main.mk revision 4a4a0bc38f01f67445354543cfae4dafb3e84028
1# Only use ANDROID_BUILD_SHELL to wrap around bash.
2# DO NOT use other shells such as zsh.
3ifdef ANDROID_BUILD_SHELL
4SHELL := $(ANDROID_BUILD_SHELL)
5else
6# Use bash, not whatever shell somebody has installed as /bin/sh
7# This is repeated in config.mk, since envsetup.sh runs that file
8# directly.
9SHELL := /bin/bash
10endif
11
12# this turns off the suffix rules built into make
13.SUFFIXES:
14
15# this turns off the RCS / SCCS implicit rules of GNU Make
16% : RCS/%,v
17% : RCS/%
18% : %,v
19% : s.%
20% : SCCS/s.%
21
22# If a rule fails, delete $@.
23.DELETE_ON_ERROR:
24
25# Figure out where we are.
26#TOP := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
27#TOP := $(patsubst %/,%,$(TOP))
28
29# TOPDIR is the normal variable you should use, because
30# if we are executing relative to the current directory
31# it can be "", whereas TOP must be "." which causes
32# pattern matching problems when make strips off the
33# trailing "./" from paths in various places.
34#ifeq ($(TOP),.)
35#TOPDIR :=
36#else
37#TOPDIR := $(TOP)/
38#endif
39
40# Check for broken versions of make.
41ifneq (1,$(strip $(shell expr $(MAKE_VERSION) \>= 3.81)))
42$(warning ********************************************************************************)
43$(warning *  You are using version $(MAKE_VERSION) of make.)
44$(warning *  Android can only be built by versions 3.81 and higher.)
45$(warning *  see https://source.android.com/source/download.html)
46$(warning ********************************************************************************)
47$(error stopping)
48endif
49
50# Absolute path of the present working direcotry.
51# This overrides the shell variable $PWD, which does not necessarily points to
52# the top of the source tree, for example when "make -C" is used in m/mm/mmm.
53PWD := $(shell pwd)
54
55TOP := .
56TOPDIR :=
57
58BUILD_SYSTEM := $(TOPDIR)build/core
59
60# This is the default target.  It must be the first declared target.
61.PHONY: droid
62DEFAULT_GOAL := droid
63$(DEFAULT_GOAL): droid_targets
64
65.PHONY: droid_targets
66droid_targets:
67
68# Used to force goals to build.  Only use for conditionally defined goals.
69.PHONY: FORCE
70FORCE:
71
72# These goals don't need to collect and include Android.mks/CleanSpec.mks
73# in the source tree.
74dont_bother_goals := clean clobber dataclean installclean \
75    help out \
76    snod systemimage-nodeps \
77    stnod systemtarball-nodeps \
78    userdataimage-nodeps userdatatarball-nodeps \
79    cacheimage-nodeps \
80    vendorimage-nodeps \
81    ramdisk-nodeps \
82    bootimage-nodeps \
83    recoveryimage-nodeps \
84    product-graph dump-products
85
86ifneq ($(filter $(dont_bother_goals), $(MAKECMDGOALS)),)
87dont_bother := true
88endif
89
90ORIGINAL_MAKECMDGOALS := $(MAKECMDGOALS)
91
92# Targets that provide quick help on the build system.
93include $(BUILD_SYSTEM)/help.mk
94
95# Set up various standard variables based on configuration
96# and host information.
97include $(BUILD_SYSTEM)/config.mk
98
99relaunch_with_ninja :=
100ifneq ($(USE_NINJA),false)
101ifndef BUILDING_WITH_NINJA
102relaunch_with_ninja := true
103endif
104endif
105
106ifeq ($(relaunch_with_ninja),true)
107# Mark this is a ninja build.
108$(shell mkdir -p $(OUT_DIR) && touch $(OUT_DIR)/ninja_build)
109include build/core/ninja.mk
110else # !relaunch_with_ninja
111ifndef BUILDING_WITH_NINJA
112# Remove ninja build mark if it exists.
113$(shell rm -f $(OUT_DIR)/ninja_build)
114endif
115
116# Write the build number to a file so it can be read back in
117# without changing the command line every time.  Avoids rebuilds
118# when using ninja.
119$(shell mkdir -p $(OUT_DIR) && \
120    echo -n $(BUILD_NUMBER) > $(OUT_DIR)/build_number.txt && \
121    echo -n $(BUILD_DATETIME) > $(OUT_DIR)/build_date.txt)
122BUILD_NUMBER_FROM_FILE := $$(cat $(OUT_DIR)/build_number.txt)
123BUILD_DATETIME_FROM_FILE := $$(cat $(OUT_DIR)/build_date.txt)
124ifeq ($(HOST_OS),darwin)
125DATE_FROM_FILE := date -r $(BUILD_DATETIME_FROM_FILE)
126else
127DATE_FROM_FILE := date -d @$(BUILD_DATETIME_FROM_FILE)
128endif
129
130# CTS-specific config.
131-include cts/build/config.mk
132
133# This allows us to force a clean build - included after the config.mk
134# environment setup is done, but before we generate any dependencies.  This
135# file does the rm -rf inline so the deps which are all done below will
136# be generated correctly
137include $(BUILD_SYSTEM)/cleanbuild.mk
138
139# Include the google-specific config
140-include vendor/google/build/config.mk
141
142VERSION_CHECK_SEQUENCE_NUMBER := 5
143-include $(OUT_DIR)/versions_checked.mk
144ifneq ($(VERSION_CHECK_SEQUENCE_NUMBER),$(VERSIONS_CHECKED))
145
146$(info Checking build tools versions...)
147
148# check for a case sensitive file system
149ifneq (a,$(shell mkdir -p $(OUT_DIR) ; \
150                echo a > $(OUT_DIR)/casecheck.txt; \
151                    echo B > $(OUT_DIR)/CaseCheck.txt; \
152                cat $(OUT_DIR)/casecheck.txt))
153$(warning ************************************************************)
154$(warning You are building on a case-insensitive filesystem.)
155$(warning Please move your source tree to a case-sensitive filesystem.)
156$(warning ************************************************************)
157$(error Case-insensitive filesystems not supported)
158endif
159
160# Make sure that there are no spaces in the absolute path; the
161# build system can't deal with them.
162ifneq ($(words $(shell pwd)),1)
163$(warning ************************************************************)
164$(warning You are building in a directory whose absolute path contains)
165$(warning a space character:)
166$(warning $(space))
167$(warning "$(shell pwd)")
168$(warning $(space))
169$(warning Please move your source tree to a path that does not contain)
170$(warning any spaces.)
171$(warning ************************************************************)
172$(error Directory names containing spaces not supported)
173endif
174
175java_version_str := $(shell unset _JAVA_OPTIONS && java -version 2>&1)
176javac_version_str := $(shell unset _JAVA_OPTIONS && javac -version 2>&1)
177
178# Check for the correct version of java, should be 1.7 by
179# default, and 1.8 if EXPERIMENTAL_USE_JAVA8 is set
180ifneq ($(EXPERIMENTAL_USE_JAVA8),)
181required_version := "1.8.x"
182required_javac_version := "1.8"
183java_version := $(shell echo '$(java_version_str)' | grep '[ "]1\.8[\. "$$]')
184javac_version := $(shell echo '$(javac_version_str)' | grep '[ "]1\.8[\. "$$]')
185else # default
186required_version := "1.7.x"
187required_javac_version := "1.7"
188java_version := $(shell echo '$(java_version_str)' | grep '^java .*[ "]1\.7[\. "$$]')
189javac_version := $(shell echo '$(javac_version_str)' | grep '[ "]1\.7[\. "$$]')
190endif # if EXPERIMENTAL_USE_JAVA8
191
192ifeq ($(strip $(java_version)),)
193$(info ************************************************************)
194$(info You are attempting to build with the incorrect version)
195$(info of java.)
196$(info $(space))
197$(info Your version is: $(java_version_str).)
198$(info The required version is: $(required_version))
199$(info $(space))
200$(info Please follow the machine setup instructions at)
201$(info $(space)$(space)$(space)$(space)https://source.android.com/source/initializing.html)
202$(info ************************************************************)
203$(error stop)
204endif
205
206# Check for the current JDK.
207#
208# For Java 1.7, we require OpenJDK on linux and Oracle JDK on Mac OS.
209requires_openjdk := false
210ifeq ($(BUILD_OS),linux)
211requires_openjdk := true
212endif
213
214
215# Check for the current jdk
216ifeq ($(requires_openjdk), true)
217# The user asked for java7 openjdk, so check that the host
218# java version is really openjdk
219ifeq ($(shell echo '$(java_version_str)' | grep -i openjdk),)
220$(info ************************************************************)
221$(info You asked for an OpenJDK 7 build but your version is)
222$(info $(java_version_str).)
223$(info ************************************************************)
224$(error stop)
225endif # java version is not OpenJdk
226else # if requires_openjdk
227ifneq ($(shell echo '$(java_version_str)' | grep -i openjdk),)
228$(info ************************************************************)
229$(info You are attempting to build with an unsupported JDK.)
230$(info $(space))
231$(info You use OpenJDK but only Sun/Oracle JDK is supported.)
232$(info Please follow the machine setup instructions at)
233$(info $(space)$(space)$(space)$(space)https://source.android.com/source/download.html)
234$(info ************************************************************)
235$(error stop)
236endif # java version is not Sun Oracle JDK
237endif # if requires_openjdk
238
239# Check for the correct version of javac
240ifeq ($(strip $(javac_version)),)
241$(info ************************************************************)
242$(info You are attempting to build with the incorrect version)
243$(info of javac.)
244$(info $(space))
245$(info Your version is: $(javac_version_str).)
246$(info The required version is: $(required_javac_version))
247$(info $(space))
248$(info Please follow the machine setup instructions at)
249$(info $(space)$(space)$(space)$(space)https://source.android.com/source/download.html)
250$(info ************************************************************)
251$(error stop)
252endif
253
254
255ifndef BUILD_EMULATOR
256  # Emulator binaries are now provided under prebuilts/android-emulator/
257  BUILD_EMULATOR := false
258endif
259
260$(shell echo 'VERSIONS_CHECKED := $(VERSION_CHECK_SEQUENCE_NUMBER)' \
261        > $(OUT_DIR)/versions_checked.mk)
262$(shell echo 'BUILD_EMULATOR ?= $(BUILD_EMULATOR)' \
263        >> $(OUT_DIR)/versions_checked.mk)
264endif
265
266# These are the modifier targets that don't do anything themselves, but
267# change the behavior of the build.
268# (must be defined before including definitions.make)
269INTERNAL_MODIFIER_TARGETS := showcommands all
270
271# EMMA_INSTRUMENT_STATIC merges the static emma library to each emma-enabled module.
272ifeq (true,$(EMMA_INSTRUMENT_STATIC))
273EMMA_INSTRUMENT := true
274endif
275
276# Bring in standard build system definitions.
277include $(BUILD_SYSTEM)/definitions.mk
278
279# Bring in dex_preopt.mk
280include $(BUILD_SYSTEM)/dex_preopt.mk
281
282ifneq ($(filter user userdebug eng,$(MAKECMDGOALS)),)
283$(info ***************************************************************)
284$(info ***************************************************************)
285$(info Do not pass '$(filter user userdebug eng,$(MAKECMDGOALS))' on \
286       the make command line.)
287$(info Set TARGET_BUILD_VARIANT in buildspec.mk, or use lunch or)
288$(info choosecombo.)
289$(info ***************************************************************)
290$(info ***************************************************************)
291$(error stopping)
292endif
293
294ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),)
295$(info ***************************************************************)
296$(info ***************************************************************)
297$(info Invalid variant: $(TARGET_BUILD_VARIANT))
298$(info Valid values are: $(INTERNAL_VALID_VARIANTS))
299$(info ***************************************************************)
300$(info ***************************************************************)
301$(error stopping)
302endif
303
304# -----------------------------------------------------------------
305# Variable to check java support level inside PDK build.
306# Not necessary if the components is not in PDK.
307# not defined : not supported
308# "sdk" : sdk API only
309# "platform" : platform API supproted
310TARGET_BUILD_JAVA_SUPPORT_LEVEL := platform
311
312# -----------------------------------------------------------------
313# The pdk (Platform Development Kit) build
314include build/core/pdk_config.mk
315
316#
317# -----------------------------------------------------------------
318# Jack version configuration
319include $(TOPDIR)prebuilts/sdk/tools/jack_versions.mk
320include $(TOPDIR)prebuilts/sdk/tools/jack_for_module.mk
321
322# -----------------------------------------------------------------
323###
324### In this section we set up the things that are different
325### between the build variants
326###
327
328is_sdk_build :=
329
330ifneq ($(filter sdk win_sdk sdk_addon,$(MAKECMDGOALS)),)
331is_sdk_build := true
332endif
333
334# Add build properties for ART. These define system properties used by installd
335# to pass flags to dex2oat.
336ADDITIONAL_BUILD_PROPERTIES += persist.sys.dalvik.vm.lib.2=libart
337ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).variant=$(DEX2OAT_TARGET_CPU_VARIANT)
338ifneq ($(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
339  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).features=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
340endif
341
342ifdef TARGET_2ND_ARCH
343  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).variant=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT)
344  ifneq ($($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
345    ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).features=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
346  endif
347endif
348
349## user/userdebug ##
350
351user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))
352enable_target_debugging := true
353tags_to_install :=
354ifneq (,$(user_variant))
355  # Target is secure in user builds.
356  ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
357
358  ifeq ($(user_variant),userdebug)
359    # Pick up some extra useful tools
360    tags_to_install += debug
361  else
362    # Disable debugging in plain user builds.
363    enable_target_debugging :=
364  endif
365
366  # Turn on Dalvik preoptimization for user builds, but only if not
367  # explicitly disabled and the build is running on Linux (since host
368  # Dalvik isn't built for non-Linux hosts).
369  ifeq (,$(WITH_DEXPREOPT))
370    ifeq ($(user_variant),user)
371      ifeq ($(HOST_OS),linux)
372        # TODO: turn on WITH_DEXPREOPT for libart user builds.
373        # WITH_DEXPREOPT := true
374      endif
375    endif
376  endif
377
378  # Disallow mock locations by default for user builds
379  ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0
380
381else # !user_variant
382  # Turn on checkjni for non-user builds.
383  ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1
384  # Set device insecure for non-user builds.
385  ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
386  # Allow mock locations by default for non user builds
387  ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
388endif # !user_variant
389
390ifeq (true,$(strip $(enable_target_debugging)))
391  # Target is more debuggable and adbd is on by default
392  ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1
393  # Enable Dalvik lock contention logging.
394  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500
395  # Include the debugging/testing OTA keys in this build.
396  INCLUDE_TEST_OTA_KEYS := true
397else # !enable_target_debugging
398  # Target is less debuggable and adbd is off by default
399  ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0
400endif # !enable_target_debugging
401
402## eng ##
403
404ifeq ($(TARGET_BUILD_VARIANT),eng)
405tags_to_install := debug eng
406ifneq ($(filter ro.setupwizard.mode=ENABLED, $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))),)
407  # Don't require the setup wizard on eng builds
408  ADDITIONAL_BUILD_PROPERTIES := $(filter-out ro.setupwizard.mode=%,\
409          $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))) \
410          ro.setupwizard.mode=OPTIONAL
411endif
412ifndef is_sdk_build
413  # Don't verify or compile the image on eng builds to speed startup.
414  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.image-dex2oat-filter=verify-at-runtime
415  # Don't verify or compile apps on eng builds to speed startup.
416  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dex2oat-filter=verify-at-runtime
417endif
418  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.usejit=true
419endif
420
421## sdk ##
422
423ifdef is_sdk_build
424
425# Detect if we want to build a repository for the SDK
426sdk_repo_goal := $(strip $(filter sdk_repo,$(MAKECMDGOALS)))
427MAKECMDGOALS := $(strip $(filter-out sdk_repo,$(MAKECMDGOALS)))
428
429ifneq ($(words $(sort $(filter-out $(INTERNAL_MODIFIER_TARGETS) checkbuild emulator_tests target-files-package,$(MAKECMDGOALS)))),1)
430$(error The 'sdk' target may not be specified with any other targets)
431endif
432
433# TODO: this should be eng I think.  Since the sdk is built from the eng
434# variant.
435tags_to_install := debug eng
436ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true
437ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes
438else # !sdk
439endif
440
441BUILD_WITHOUT_PV := true
442
443ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android
444
445# enable vm tracing in files for now to help track
446# the cause of ANRs in the content process
447ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.stack-trace-file=/data/anr/traces.txt
448
449# ------------------------------------------------------------
450# Define a function that, given a list of module tags, returns
451# non-empty if that module should be installed in /system.
452
453# For most goals, anything not tagged with the "tests" tag should
454# be installed in /system.
455define should-install-to-system
456$(if $(filter tests,$(1)),,true)
457endef
458
459ifdef is_sdk_build
460# For the sdk goal, anything with the "samples" tag should be
461# installed in /data even if that module also has "eng"/"debug"/"user".
462define should-install-to-system
463$(if $(filter samples tests,$(1)),,true)
464endef
465endif
466
467
468# If they only used the modifier goals (showcommands, etc), we'll actually
469# build the default target.
470ifeq ($(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS)),)
471.PHONY: $(INTERNAL_MODIFIER_TARGETS)
472$(INTERNAL_MODIFIER_TARGETS): $(DEFAULT_GOAL)
473endif
474
475#
476# Typical build; include any Android.mk files we can find.
477#
478subdirs := $(TOP)
479
480FULL_BUILD := true
481
482# Before we go and include all of the module makefiles, stash away
483# the PRODUCT_* values so that later we can verify they are not modified.
484stash_product_vars:=true
485ifeq ($(stash_product_vars),true)
486  $(call stash-product-vars, __STASHED)
487endif
488
489ifneq ($(ONE_SHOT_MAKEFILE),)
490# We've probably been invoked by the "mm" shell function
491# with a subdirectory's makefile.
492include $(ONE_SHOT_MAKEFILE)
493# Change CUSTOM_MODULES to include only modules that were
494# defined by this makefile; this will install all of those
495# modules as a side-effect.  Do this after including ONE_SHOT_MAKEFILE
496# so that the modules will be installed in the same place they
497# would have been with a normal make.
498CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS)))
499FULL_BUILD :=
500# Stub out the notice targets, which probably aren't defined
501# when using ONE_SHOT_MAKEFILE.
502NOTICE-HOST-%: ;
503NOTICE-TARGET-%: ;
504
505# A helper goal printing out install paths
506.PHONY: GET-INSTALL-PATH
507GET-INSTALL-PATH:
508	@echo "Install paths for modules in $(ONE_SHOT_MAKEFILE):"
509	@$(foreach m, $(ALL_MODULES), $(if $(ALL_MODULES.$(m).INSTALLED), \
510		echo 'INSTALL-PATH: $(m) $(ALL_MODULES.$(m).INSTALLED)';))
511
512else # ONE_SHOT_MAKEFILE
513
514ifneq ($(dont_bother),true)
515#
516# Include all of the makefiles in the system
517#
518
519# Can't use first-makefiles-under here because
520# --mindepth=2 makes the prunes not work.
521subdir_makefiles := \
522	$(shell build/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) $(subdirs) Android.mk)
523
524$(foreach mk, $(subdir_makefiles), $(info including $(mk) ...)$(eval include $(mk)))
525
526endif # dont_bother
527
528endif # ONE_SHOT_MAKEFILE
529
530# Now with all Android.mks loaded we can do post cleaning steps.
531include $(BUILD_SYSTEM)/post_clean.mk
532
533ifeq ($(stash_product_vars),true)
534  $(call assert-product-vars, __STASHED)
535endif
536
537include $(BUILD_SYSTEM)/legacy_prebuilts.mk
538ifneq ($(filter-out $(GRANDFATHERED_ALL_PREBUILT),$(strip $(notdir $(ALL_PREBUILT)))),)
539  $(warning *** Some files have been added to ALL_PREBUILT.)
540  $(warning *)
541  $(warning * ALL_PREBUILT is a deprecated mechanism that)
542  $(warning * should not be used for new files.)
543  $(warning * As an alternative, use PRODUCT_COPY_FILES in)
544  $(warning * the appropriate product definition.)
545  $(warning * build/target/product/core.mk is the product)
546  $(warning * definition used in all products.)
547  $(warning *)
548  $(foreach bad_prebuilt,$(filter-out $(GRANDFATHERED_ALL_PREBUILT),$(strip $(notdir $(ALL_PREBUILT)))),$(warning * unexpected $(bad_prebuilt) in ALL_PREBUILT))
549  $(warning *)
550  $(error ALL_PREBUILT contains unexpected files)
551endif
552
553# -------------------------------------------------------------------
554# All module makefiles have been included at this point.
555# -------------------------------------------------------------------
556
557
558# -------------------------------------------------------------------
559# Fix up CUSTOM_MODULES to refer to installed files rather than
560# just bare module names.  Leave unknown modules alone in case
561# they're actually full paths to a particular file.
562known_custom_modules := $(filter $(ALL_MODULES),$(CUSTOM_MODULES))
563unknown_custom_modules := $(filter-out $(ALL_MODULES),$(CUSTOM_MODULES))
564CUSTOM_MODULES := \
565	$(call module-installed-files,$(known_custom_modules)) \
566	$(unknown_custom_modules)
567
568# -------------------------------------------------------------------
569# Define dependencies for modules that require other modules.
570# This can only happen now, after we've read in all module makefiles.
571#
572# TODO: deal with the fact that a bare module name isn't
573# unambiguous enough.  Maybe declare short targets like
574# APPS:Quake or HOST:SHARED_LIBRARIES:libutils.
575# BUG: the system image won't know to depend on modules that are
576# brought in as requirements of other modules.
577#
578# Resolve the required module name to 32-bit or 64-bit variant.
579# Get a list of corresponding 32-bit module names, if one exists.
580define get-32-bit-modules
581$(strip $(foreach m,$(1),\
582  $(if $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS),\
583    $(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX))))
584endef
585# Get a list of corresponding 32-bit module names, if one exists;
586# otherwise return the original module name
587define get-32-bit-modules-if-we-can
588$(strip $(foreach m,$(1),\
589  $(if $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS),\
590    $(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX),
591    $(m))))
592endef
593
594# If a module is for a cross host os, the required modules must be for
595# that OS too.
596# If a module is built for 32-bit, the required modules must be 32-bit too;
597# Otherwise if the module is an exectuable or shared library,
598#   the required modules must be 64-bit;
599#   otherwise we require both 64-bit and 32-bit variant, if one exists.
600$(foreach m,$(ALL_MODULES),\
601  $(eval r := $(ALL_MODULES.$(m).REQUIRED))\
602  $(if $(r),\
603    $(if $(ALL_MODULES.$(m).FOR_HOST_CROSS),\
604      $(eval r := $(addprefix host_cross_,$(r))))\
605    $(if $(ALL_MODULES.$(m).FOR_2ND_ARCH),\
606      $(eval r_r := $(call get-32-bit-modules-if-we-can,$(r))),\
607      $(if $(filter EXECUTABLES SHARED_LIBRARIES,$(ALL_MODULES.$(m).CLASS)),\
608        $(eval r_r := $(r)),\
609        $(eval r_r := $(r) $(call get-32-bit-modules,$(r)))\
610       )\
611     )\
612     $(eval ALL_MODULES.$(m).REQUIRED := $(strip $(r_r)))\
613  )\
614)
615r_r :=
616
617define add-required-deps
618$(1): | $(2)
619endef
620
621$(foreach m,$(ALL_MODULES), \
622  $(eval r := $(ALL_MODULES.$(m).REQUIRED)) \
623  $(if $(r), \
624    $(eval r := $(call module-installed-files,$(r))) \
625    $(eval t_m := $(filter $(TARGET_OUT_ROOT)/%, $(ALL_MODULES.$(m).INSTALLED))) \
626    $(eval h_m := $(filter $(HOST_OUT_ROOT)/%, $(ALL_MODULES.$(m).INSTALLED))) \
627    $(eval hc_m := $(filter $(HOST_CROSS_OUT_ROOT)/%, $(ALL_MODULES.$(m).INSTALLED))) \
628    $(eval t_r := $(filter $(TARGET_OUT_ROOT)/%, $(r))) \
629    $(eval h_r := $(filter $(HOST_OUT_ROOT)/%, $(r))) \
630    $(eval hc_r := $(filter $(HOST_CROSS_OUT_ROOT)/%, $(r))) \
631    $(eval t_m := $(filter-out $(t_r), $(t_m))) \
632    $(eval h_m := $(filter-out $(h_r), $(h_m))) \
633    $(eval hc_m := $(filter-out $(hc_r), $(hc_m))) \
634    $(if $(t_m), $(eval $(call add-required-deps, $(t_m),$(t_r)))) \
635    $(if $(h_m), $(eval $(call add-required-deps, $(h_m),$(h_r)))) \
636    $(if $(hc_m), $(eval $(call add-required-deps, $(hc_m),$(hc_r)))) \
637   ) \
638 )
639
640t_m :=
641h_m :=
642hc_m :=
643t_r :=
644h_r :=
645hc_r :=
646
647# Establish the dependecies on the shared libraries.
648# It also adds the shared library module names to ALL_MODULES.$(m).REQUIRED,
649# so they can be expanded to product_MODULES later.
650# $(1): TARGET_ or HOST_ or HOST_CROSS_.
651# $(2): non-empty for 2nd arch.
652# $(3): non-empty for host cross compile.
653define resolve-shared-libs-depes
654$(foreach m,$($(if $(2),$($(1)2ND_ARCH_VAR_PREFIX))$(1)DEPENDENCIES_ON_SHARED_LIBRARIES),\
655  $(eval p := $(subst :,$(space),$(m)))\
656  $(eval mod := $(firstword $(p)))\
657  $(eval deps := $(subst $(comma),$(space),$(lastword $(p))))\
658  $(if $(2),$(eval deps := $(addsuffix $($(1)2ND_ARCH_MODULE_SUFFIX),$(deps))))\
659  $(if $(3),$(eval deps := $(addprefix host_cross_,$(deps))))\
660  $(eval r := $(filter $($(1)OUT)/%,$(call module-installed-files,\
661    $(deps))))\
662  $(eval $(call add-required-deps,$(word 2,$(p)),$(r)))\
663  $(eval ALL_MODULES.$(mod).REQUIRED += $(deps)))
664endef
665
666$(call resolve-shared-libs-depes,TARGET_)
667ifdef TARGET_2ND_ARCH
668$(call resolve-shared-libs-depes,TARGET_,true)
669endif
670$(call resolve-shared-libs-depes,HOST_)
671ifdef HOST_2ND_ARCH
672$(call resolve-shared-libs-depes,HOST_,true)
673endif
674ifdef HOST_CROSS_OS
675$(call resolve-shared-libs-depes,HOST_CROSS_,,true)
676endif
677
678m :=
679r :=
680p :=
681deps :=
682add-required-deps :=
683
684# -------------------------------------------------------------------
685# Figure out our module sets.
686#
687# Of the modules defined by the component makefiles,
688# determine what we actually want to build.
689
690###########################################################
691## Expand a module name list with REQUIRED modules
692###########################################################
693# $(1): The variable name that holds the initial module name list.
694#       the variable will be modified to hold the expanded results.
695# $(2): The initial module name list.
696# Returns empty string (maybe with some whitespaces).
697define expand-required-modules
698$(eval _erm_new_modules := $(sort $(filter-out $($(1)),\
699  $(foreach m,$(2),$(ALL_MODULES.$(m).REQUIRED)))))\
700$(if $(_erm_new_modules),$(eval $(1) += $(_erm_new_modules))\
701  $(call expand-required-modules,$(1),$(_erm_new_modules)))
702endef
703
704ifdef FULL_BUILD
705  # The base list of modules to build for this product is specified
706  # by the appropriate product definition file, which was included
707  # by product_config.mk.
708  product_MODULES := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES)
709  # Filter out the overridden packages before doing expansion
710  product_MODULES := $(filter-out $(foreach p, $(product_MODULES), \
711      $(PACKAGES.$(p).OVERRIDES)), $(product_MODULES))
712
713  # Resolve the :32 :64 module name
714  modules_32 := $(patsubst %:32,%,$(filter %:32, $(product_MODULES)))
715  modules_64 := $(patsubst %:64,%,$(filter %:64, $(product_MODULES)))
716  modules_rest := $(filter-out %:32 %:64,$(product_MODULES))
717  # Note for 32-bit product, $(modules_32) and $(modules_64) will be
718  # added as their original module names.
719  product_MODULES := $(call get-32-bit-modules-if-we-can, $(modules_32))
720  product_MODULES += $(modules_64)
721  # For the rest we add both
722  product_MODULES += $(call get-32-bit-modules, $(modules_rest))
723  product_MODULES += $(modules_rest)
724
725  $(call expand-required-modules,product_MODULES,$(product_MODULES))
726
727  product_FILES := $(call module-installed-files, $(product_MODULES))
728  ifeq (0,1)
729    $(info product_FILES for $(TARGET_DEVICE) ($(INTERNAL_PRODUCT)):)
730    $(foreach p,$(product_FILES),$(info :   $(p)))
731    $(error done)
732  endif
733else
734  # We're not doing a full build, and are probably only including
735  # a subset of the module makefiles.  Don't try to build any modules
736  # requested by the product, because we probably won't have rules
737  # to build them.
738  product_FILES :=
739endif
740
741eng_MODULES := $(sort \
742        $(call get-tagged-modules,eng) \
743        $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_ENG)) \
744    )
745debug_MODULES := $(sort \
746        $(call get-tagged-modules,debug) \
747        $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_DEBUG)) \
748    )
749tests_MODULES := $(sort \
750        $(call get-tagged-modules,tests) \
751        $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_TESTS)) \
752    )
753
754# TODO: Remove the 3 places in the tree that use ALL_DEFAULT_INSTALLED_MODULES
755# and get rid of it from this list.
756modules_to_install := $(sort \
757    $(ALL_DEFAULT_INSTALLED_MODULES) \
758    $(product_FILES) \
759    $(foreach tag,$(tags_to_install),$($(tag)_MODULES)) \
760    $(CUSTOM_MODULES) \
761  )
762
763# Some packages may override others using LOCAL_OVERRIDES_PACKAGES.
764# Filter out (do not install) any overridden packages.
765overridden_packages := $(call get-package-overrides,$(modules_to_install))
766ifdef overridden_packages
767#  old_modules_to_install := $(modules_to_install)
768  modules_to_install := \
769      $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
770          $(modules_to_install))
771endif
772#$(error filtered out
773#           $(filter-out $(modules_to_install),$(old_modules_to_install)))
774
775# Don't include any GNU General Public License shared objects or static
776# libraries in SDK images.  GPL executables (not static/dynamic libraries)
777# are okay if they don't link against any closed source libraries (directly
778# or indirectly)
779
780# It's ok (and necessary) to build the host tools, but nothing that's
781# going to be installed on the target (including static libraries).
782
783ifdef is_sdk_build
784  target_gnu_MODULES := \
785              $(filter \
786                      $(TARGET_OUT_INTERMEDIATES)/% \
787                      $(TARGET_OUT)/% \
788                      $(TARGET_OUT_DATA)/%, \
789                              $(sort $(call get-tagged-modules,gnu)))
790  target_gnu_MODULES := $(filter-out $(TARGET_OUT_EXECUTABLES)/%,$(target_gnu_MODULES))
791  $(info Removing from sdk:)$(foreach d,$(target_gnu_MODULES),$(info : $(d)))
792  modules_to_install := \
793              $(filter-out $(target_gnu_MODULES),$(modules_to_install))
794
795  # Ensure every module listed in PRODUCT_PACKAGES* gets something installed
796  # TODO: Should we do this for all builds and not just the sdk?
797  dangling_modules :=
798  $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES), \
799    $(if $(strip $(ALL_MODULES.$(m).INSTALLED) $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).INSTALLED)),,\
800      $(eval dangling_modules += $(m))))
801  ifneq ($(dangling_modules),)
802    $(warning: Modules '$(dangling_modules)' in PRODUCT_PACKAGES have nothing to install!)
803  endif
804  $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_DEBUG), \
805    $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\
806      $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_DEBUG has nothing to install!)))
807  $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_ENG), \
808    $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\
809      $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_ENG has nothing to install!)))
810  $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_TESTS), \
811    $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\
812      $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_TESTS has nothing to install!)))
813endif
814
815# build/core/Makefile contains extra stuff that we don't want to pollute this
816# top-level makefile with.  It expects that ALL_DEFAULT_INSTALLED_MODULES
817# contains everything that's built during the current make, but it also further
818# extends ALL_DEFAULT_INSTALLED_MODULES.
819ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_install)
820include $(BUILD_SYSTEM)/Makefile
821modules_to_install := $(sort $(ALL_DEFAULT_INSTALLED_MODULES))
822ALL_DEFAULT_INSTALLED_MODULES :=
823
824
825# These are additional goals that we build, in order to make sure that there
826# is as little code as possible in the tree that doesn't build.
827modules_to_check := $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).CHECKED))
828
829# If you would like to build all goals, and not skip any intermediate
830# steps, you can pass the "all" modifier goal on the commandline.
831ifneq ($(filter all,$(MAKECMDGOALS)),)
832modules_to_check += $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).BUILT))
833endif
834
835# for easier debugging
836modules_to_check := $(sort $(modules_to_check))
837#$(error modules_to_check $(modules_to_check))
838
839# -------------------------------------------------------------------
840# This is used to to get the ordering right, you can also use these,
841# but they're considered undocumented, so don't complain if their
842# behavior changes.
843.PHONY: prebuilt
844prebuilt: $(ALL_PREBUILT)
845
846# An internal target that depends on all copied headers
847# (see copy_headers.make).  Other targets that need the
848# headers to be copied first can depend on this target.
849.PHONY: all_copied_headers
850all_copied_headers: ;
851
852$(ALL_C_CPP_ETC_OBJECTS): | all_copied_headers
853
854# All the droid stuff, in directories
855.PHONY: files
856files: prebuilt \
857        $(modules_to_install) \
858        $(INSTALLED_ANDROID_INFO_TXT_TARGET)
859
860# -------------------------------------------------------------------
861
862.PHONY: checkbuild
863checkbuild: $(modules_to_check) droid_targets
864ifeq (true,$(ANDROID_BUILD_EVERYTHING_BY_DEFAULT))
865droid: checkbuild
866endif
867
868.PHONY: ramdisk
869ramdisk: $(INSTALLED_RAMDISK_TARGET)
870
871.PHONY: systemtarball
872systemtarball: $(INSTALLED_SYSTEMTARBALL_TARGET)
873
874.PHONY: boottarball
875boottarball: $(INSTALLED_BOOTTARBALL_TARGET)
876
877.PHONY: userdataimage
878userdataimage: $(INSTALLED_USERDATAIMAGE_TARGET)
879
880ifneq (,$(filter userdataimage, $(MAKECMDGOALS)))
881$(call dist-for-goals, userdataimage, $(BUILT_USERDATAIMAGE_TARGET))
882endif
883
884.PHONY: userdatatarball
885userdatatarball: $(INSTALLED_USERDATATARBALL_TARGET)
886
887.PHONY: cacheimage
888cacheimage: $(INSTALLED_CACHEIMAGE_TARGET)
889
890.PHONY: vendorimage
891vendorimage: $(INSTALLED_VENDORIMAGE_TARGET)
892
893.PHONY: bootimage
894bootimage: $(INSTALLED_BOOTIMAGE_TARGET)
895
896# phony target that include any targets in $(ALL_MODULES)
897.PHONY: all_modules
898ifndef BUILD_MODULES_IN_PATHS
899all_modules: $(ALL_MODULES)
900else
901# BUILD_MODULES_IN_PATHS is a list of paths relative to the top of the tree
902build_modules_in_paths := $(patsubst ./%,%,$(BUILD_MODULES_IN_PATHS))
903module_path_patterns := $(foreach p, $(build_modules_in_paths),\
904    $(if $(filter %/,$(p)),$(p)%,$(p)/%))
905my_all_modules := $(sort $(foreach m, $(ALL_MODULES),$(if $(filter\
906    $(module_path_patterns), $(addsuffix /,$(ALL_MODULES.$(m).PATH))),$(m))))
907all_modules: $(my_all_modules)
908endif
909
910
911# Build files and then package it into the rom formats
912.PHONY: droidcore
913droidcore: files \
914	systemimage \
915	$(INSTALLED_BOOTIMAGE_TARGET) \
916	$(INSTALLED_RECOVERYIMAGE_TARGET) \
917	$(INSTALLED_USERDATAIMAGE_TARGET) \
918	$(INSTALLED_CACHEIMAGE_TARGET) \
919	$(INSTALLED_VENDORIMAGE_TARGET) \
920	$(INSTALLED_FILES_FILE) \
921	$(INSTALLED_FILES_FILE_VENDOR)
922
923# dist_files only for putting your library into the dist directory with a full build.
924.PHONY: dist_files
925
926ifneq ($(TARGET_BUILD_APPS),)
927  # If this build is just for apps, only build apps and not the full system by default.
928
929  unbundled_build_modules :=
930  ifneq ($(filter all,$(TARGET_BUILD_APPS)),)
931    # If they used the magic goal "all" then build all apps in the source tree.
932    unbundled_build_modules := $(foreach m,$(sort $(ALL_MODULES)),$(if $(filter APPS,$(ALL_MODULES.$(m).CLASS)),$(m)))
933  else
934    unbundled_build_modules := $(TARGET_BUILD_APPS)
935  endif
936
937  # Dist the installed files if they exist.
938  apps_only_installed_files := $(foreach m,$(unbundled_build_modules),$(ALL_MODULES.$(m).INSTALLED))
939  $(call dist-for-goals,apps_only, $(apps_only_installed_files))
940  # For uninstallable modules such as static Java library, we have to dist the built file,
941  # as <module_name>.<suffix>
942  apps_only_dist_built_files := $(foreach m,$(unbundled_build_modules),$(if $(ALL_MODULES.$(m).INSTALLED),,\
943      $(if $(ALL_MODULES.$(m).BUILT),$(ALL_MODULES.$(m).BUILT):$(m)$(suffix $(ALL_MODULES.$(m).BUILT)))\
944      $(if $(ALL_MODULES.$(m).AAR),$(ALL_MODULES.$(m).AAR):$(m).aar)\
945      ))
946  $(call dist-for-goals,apps_only, $(apps_only_dist_built_files))
947
948  ifeq ($(EMMA_INSTRUMENT),true)
949    $(EMMA_META_ZIP) : $(apps_only_installed_files)
950
951    $(call dist-for-goals,apps_only, $(EMMA_META_ZIP))
952  endif
953
954  $(PROGUARD_DICT_ZIP) : $(apps_only_installed_files)
955  $(call dist-for-goals,apps_only, $(PROGUARD_DICT_ZIP))
956
957  $(SYMBOLS_ZIP) : $(apps_only_installed_files)
958  $(call dist-for-goals,apps_only, $(SYMBOLS_ZIP))
959
960.PHONY: apps_only
961apps_only: $(unbundled_build_modules)
962
963droid_targets: apps_only
964
965# Combine the NOTICE files for a apps_only build
966$(eval $(call combine-notice-files, \
967    $(target_notice_file_txt), \
968    $(target_notice_file_html), \
969    "Notices for files for apps:", \
970    $(TARGET_OUT_NOTICE_FILES), \
971    $(apps_only_installed_files)))
972
973
974else # TARGET_BUILD_APPS
975  $(call dist-for-goals, droidcore, \
976    $(INTERNAL_UPDATE_PACKAGE_TARGET) \
977    $(INTERNAL_OTA_PACKAGE_TARGET) \
978    $(BUILT_OTATOOLS_PACKAGE) \
979    $(SYMBOLS_ZIP) \
980    $(INSTALLED_FILES_FILE) \
981    $(INSTALLED_FILES_FILE_VENDOR) \
982    $(INSTALLED_BUILD_PROP_TARGET) \
983    $(BUILT_TARGET_FILES_PACKAGE) \
984    $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
985    $(INSTALLED_RAMDISK_TARGET) \
986   )
987
988  # Put a copy of the radio/bootloader files in the dist dir.
989  $(foreach f,$(INSTALLED_RADIOIMAGE_TARGET), \
990    $(call dist-for-goals, droidcore, $(f)))
991
992  ifneq ($(ANDROID_BUILD_EMBEDDED),true)
993  ifneq ($(TARGET_BUILD_PDK),true)
994    $(call dist-for-goals, droidcore, \
995      $(APPS_ZIP) \
996      $(INTERNAL_EMULATOR_PACKAGE_TARGET) \
997      $(PACKAGE_STATS_FILE) \
998    )
999  endif
1000  endif
1001
1002  ifeq ($(EMMA_INSTRUMENT),true)
1003    $(EMMA_META_ZIP) : $(INSTALLED_SYSTEMIMAGE)
1004
1005    $(call dist-for-goals, dist_files, $(EMMA_META_ZIP))
1006  endif
1007
1008# Building a full system-- the default is to build droidcore
1009droid_targets: droidcore dist_files
1010
1011endif # TARGET_BUILD_APPS
1012
1013.PHONY: docs
1014docs: $(ALL_DOCS)
1015
1016.PHONY: sdk
1017ALL_SDK_TARGETS := $(INTERNAL_SDK_TARGET)
1018sdk: $(ALL_SDK_TARGETS)
1019$(call dist-for-goals,sdk win_sdk, \
1020    $(ALL_SDK_TARGETS) \
1021    $(SYMBOLS_ZIP) \
1022    $(INSTALLED_BUILD_PROP_TARGET) \
1023)
1024
1025# umbrella targets to assit engineers in verifying builds
1026.PHONY: java native target host java-host java-target native-host native-target \
1027        java-host-tests java-target-tests native-host-tests native-target-tests \
1028        java-tests native-tests host-tests target-tests tests
1029# some synonyms
1030.PHONY: host-java target-java host-native target-native \
1031        target-java-tests target-native-tests
1032host-java : java-host
1033target-java : java-target
1034host-native : native-host
1035target-native : native-target
1036target-java-tests : java-target-tests
1037target-native-tests : native-target-tests
1038tests : host-tests target-tests
1039
1040# To catch more build breakage, check build tests modules in eng and userdebug builds.
1041ifneq ($(ANDROID_NO_TEST_CHECK),true)
1042ifneq ($(TARGET_BUILD_PDK),true)
1043ifneq ($(filter eng userdebug,$(TARGET_BUILD_VARIANT)),)
1044droidcore : target-tests host-tests
1045endif
1046endif
1047endif
1048
1049ifneq (,$(filter samplecode, $(MAKECMDGOALS)))
1050.PHONY: samplecode
1051sample_MODULES := $(sort $(call get-tagged-modules,samples))
1052sample_APKS_DEST_PATH := $(TARGET_COMMON_OUT_ROOT)/samples
1053sample_APKS_COLLECTION := \
1054        $(foreach module,$(sample_MODULES),$(sample_APKS_DEST_PATH)/$(notdir $(module)))
1055$(foreach module,$(sample_MODULES),$(eval $(call \
1056        copy-one-file,$(module),$(sample_APKS_DEST_PATH)/$(notdir $(module)))))
1057sample_ADDITIONAL_INSTALLED := \
1058        $(filter-out $(modules_to_install) $(modules_to_check) $(ALL_PREBUILT),$(sample_MODULES))
1059samplecode: $(sample_APKS_COLLECTION)
1060	@echo "Collect sample code apks: $^"
1061	# remove apks that are not intended to be installed.
1062	rm -f $(sample_ADDITIONAL_INSTALLED)
1063endif  # samplecode in $(MAKECMDGOALS)
1064
1065.PHONY: findbugs
1066findbugs: $(INTERNAL_FINDBUGS_HTML_TARGET) $(INTERNAL_FINDBUGS_XML_TARGET)
1067
1068.PHONY: clean
1069clean:
1070	@rm -rf $(OUT_DIR)/*
1071	@echo "Entire build directory removed."
1072
1073.PHONY: clobber
1074clobber: clean
1075
1076# The rules for dataclean and installclean are defined in cleanbuild.mk.
1077
1078#xxx scrape this from ALL_MODULE_NAME_TAGS
1079.PHONY: modules
1080modules:
1081	@echo "Available sub-modules:"
1082	@echo "$(call module-names-for-tag-list,$(ALL_MODULE_TAGS))" | \
1083	      tr -s ' ' '\n' | sort -u | $(COLUMN)
1084
1085.PHONY: showcommands
1086showcommands:
1087	@echo >/dev/null
1088
1089.PHONY: nothing
1090nothing:
1091	@echo Successfully read the makefiles.
1092endif # !relaunch_with_ninja
1093