1 # Only use ANDROID_BUILD_SHELL to wrap around bash.
2 # DO NOT use other shells such as zsh.
3 ifdef ANDROID_BUILD_SHELL
4 SHELL := $(ANDROID_BUILD_SHELL)
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
12 # this turns off the suffix rules built into make
15 # this turns off the RCS / SCCS implicit rules of GNU Make
22 # If a rule fails, delete $@.
25 # Figure out where we are.
26 #TOP := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
27 #TOP := $(patsubst %/,%,$(TOP))
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.
40 # Check for broken versions of make.
41 # (Allow any version under Cygwin since we don't actually build the platform there.)
42 ifeq (,$(findstring CYGWIN,$(shell uname -sm)))
43 ifneq (1,$(strip $(shell expr $(MAKE_VERSION) \>= 3.81)))
44 $(warning ********************************************************************************)
45 $(warning * You are using version $(MAKE_VERSION) of make.)
46 $(warning * Android can only be built by versions 3.81 and higher.)
47 $(warning * see https://source.android.com/source/download.html)
48 $(warning ********************************************************************************)
53 # Absolute path of the present working direcotry.
54 # This overrides the shell variable $PWD, which does not necessarily points to
55 # the top of the source tree, for example when "make -C" is used in m/mm/mmm.
61 BUILD_SYSTEM := $(TOPDIR)build/core
63 # This is the default target. It must be the first declared target.
68 # Used to force goals to build. Only use for conditionally defined goals.
72 # These goals don't need to collect and include Android.mks/CleanSpec.mks
74 dont_bother_goals := clean clobber dataclean installclean \
76 snod systemimage-nodeps \
77 stnod systemtarball-nodeps \
78 userdataimage-nodeps userdatatarball-nodeps \
85 ifneq ($(filter $(dont_bother_goals), $(MAKECMDGOALS)),)
89 # Targets that provide quick help on the build system.
90 include $(BUILD_SYSTEM)/help.mk
92 # Set up various standard variables based on configuration
93 # and host information.
94 include $(BUILD_SYSTEM)/config.mk
96 # CTS-specific config.
97 -include cts/build/config.mk
99 # This allows us to force a clean build - included after the config.mk
100 # environment setup is done, but before we generate any dependencies. This
101 # file does the rm -rf inline so the deps which are all done below will
102 # be generated correctly
103 include $(BUILD_SYSTEM)/cleanbuild.mk
105 # Include the google-specific config
106 -include vendor/google/build/config.mk
108 VERSION_CHECK_SEQUENCE_NUMBER := 5
109 -include $(OUT_DIR)/versions_checked.mk
110 ifneq ($(VERSION_CHECK_SEQUENCE_NUMBER),$(VERSIONS_CHECKED))
112 $(info Checking build tools versions...)
114 ifneq ($(HOST_OS),windows)
115 # check for a case sensitive file system
116 ifneq (a,$(shell mkdir -p $(OUT_DIR) ; \
117 echo a > $(OUT_DIR)/casecheck.txt; \
118 echo B > $(OUT_DIR)/CaseCheck.txt; \
119 cat $(OUT_DIR)/casecheck.txt))
120 $(warning ************************************************************)
121 $(warning You are building on a case-insensitive filesystem.)
122 $(warning Please move your source tree to a case-sensitive filesystem.)
123 $(warning ************************************************************)
124 $(error Case-insensitive filesystems not supported)
128 # Make sure that there are no spaces in the absolute path; the
129 # build system can't deal with them.
130 ifneq ($(words $(shell pwd)),1)
131 $(warning ************************************************************)
132 $(warning You are building in a directory whose absolute path contains)
133 $(warning a space character:)
135 $(warning "$(shell pwd)")
137 $(warning Please move your source tree to a path that does not contain)
138 $(warning any spaces.)
139 $(warning ************************************************************)
140 $(error Directory names containing spaces not supported)
143 java_version_str := $(shell unset _JAVA_OPTIONS && java -version 2>&1)
144 javac_version_str := $(shell unset _JAVA_OPTIONS && javac -version 2>&1)
146 # Check for the correct version of java, should be 1.7 by
147 # default, and 1.8 if EXPERIMENTAL_USE_JAVA8 is set
148 ifneq ($(EXPERIMENTAL_USE_JAVA8),)
149 required_version := "1.8.x"
150 required_javac_version := "1.8"
151 java_version := $(shell echo '$(java_version_str)' | grep 'openjdk .*[ "]1\.8[\. "$$]')
152 javac_version := $(shell echo '$(javac_version_str)' | grep '[ "]1\.8[\. "$$]')
154 required_version := "1.7.x"
155 required_javac_version := "1.7"
156 java_version := $(shell echo '$(java_version_str)' | grep '^java .*[ "]1\.7[\. "$$]')
157 javac_version := $(shell echo '$(javac_version_str)' | grep '[ "]1\.7[\. "$$]')
158 endif # if EXPERIMENTAL_USE_JAVA8
160 ifeq ($(strip $(java_version)),)
161 $(info ************************************************************)
162 $(info You are attempting to build with the incorrect version)
165 $(info Your version is: $(java_version_str).)
166 $(info The required version is: $(required_version))
168 $(info Please follow the machine setup instructions at)
169 $(info $(space)$(space)$(space)$(space)https://source.android.com/source/initializing.html)
170 $(info ************************************************************)
174 # Check for the current JDK.
176 # For Java 1.7, we require OpenJDK on linux and Oracle JDK on Mac OS.
177 requires_openjdk := false
178 ifeq ($(HOST_OS), linux)
179 requires_openjdk := true
183 # Check for the current jdk
184 ifeq ($(requires_openjdk), true)
185 # The user asked for java7 openjdk, so check that the host
186 # java version is really openjdk
187 ifeq ($(shell echo '$(java_version_str)' | grep -i openjdk),)
188 $(info ************************************************************)
189 $(info You asked for an OpenJDK 7 build but your version is)
190 $(info $(java_version_str).)
191 $(info ************************************************************)
193 endif # java version is not OpenJdk
194 else # if requires_openjdk
195 ifneq ($(shell echo '$(java_version_str)' | grep -i openjdk),)
196 $(info ************************************************************)
197 $(info You are attempting to build with an unsupported JDK.)
199 $(info You use OpenJDK but only Sun/Oracle JDK is supported.)
200 $(info Please follow the machine setup instructions at)
201 $(info $(space)$(space)$(space)$(space)https://source.android.com/source/download.html)
202 $(info ************************************************************)
204 endif # java version is not Sun Oracle JDK
205 endif # if requires_openjdk
207 # Check for the correct version of javac
208 ifeq ($(strip $(javac_version)),)
209 $(info ************************************************************)
210 $(info You are attempting to build with the incorrect version)
213 $(info Your version is: $(javac_version_str).)
214 $(info The required version is: $(required_javac_version))
216 $(info Please follow the machine setup instructions at)
217 $(info $(space)$(space)$(space)$(space)https://source.android.com/source/download.html)
218 $(info ************************************************************)
223 ifndef BUILD_EMULATOR
224 # Emulator binaries are now provided under prebuilts/android-emulator/
225 BUILD_EMULATOR := false
228 $(shell echo 'VERSIONS_CHECKED := $(VERSION_CHECK_SEQUENCE_NUMBER)' \
229 > $(OUT_DIR)/versions_checked.mk)
230 $(shell echo 'BUILD_EMULATOR ?= $(BUILD_EMULATOR)' \
231 >> $(OUT_DIR)/versions_checked.mk)
234 # These are the modifier targets that don't do anything themselves, but
235 # change the behavior of the build.
236 # (must be defined before including definitions.make)
237 INTERNAL_MODIFIER_TARGETS := showcommands all
239 # EMMA_INSTRUMENT_STATIC merges the static emma library to each emma-enabled module.
240 ifeq (true,$(EMMA_INSTRUMENT_STATIC))
241 EMMA_INSTRUMENT := true
244 # Bring in standard build system definitions.
245 include $(BUILD_SYSTEM)/definitions.mk
247 # Bring in dex_preopt.mk
248 include $(BUILD_SYSTEM)/dex_preopt.mk
250 ifneq ($(filter user userdebug eng,$(MAKECMDGOALS)),)
251 $(info ***************************************************************)
252 $(info ***************************************************************)
253 $(info Do not pass '$(filter user userdebug eng,$(MAKECMDGOALS))' on \
254 the make command line.)
255 $(info Set TARGET_BUILD_VARIANT in buildspec.mk, or use lunch or)
257 $(info ***************************************************************)
258 $(info ***************************************************************)
262 ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),)
263 $(info ***************************************************************)
264 $(info ***************************************************************)
265 $(info Invalid variant: $(TARGET_BUILD_VARIANT))
266 $(info Valid values are: $(INTERNAL_VALID_VARIANTS))
267 $(info ***************************************************************)
268 $(info ***************************************************************)
272 # -----------------------------------------------------------------
273 # Variable to check java support level inside PDK build.
274 # Not necessary if the components is not in PDK.
275 # not defined : not supported
276 # "sdk" : sdk API only
277 # "platform" : platform API supproted
278 TARGET_BUILD_JAVA_SUPPORT_LEVEL := platform
280 # -----------------------------------------------------------------
281 # The pdk (Platform Development Kit) build
282 include build/core/pdk_config.mk
284 # -----------------------------------------------------------------
286 ### In this section we set up the things that are different
287 ### between the build variants
292 ifneq ($(filter sdk win_sdk sdk_addon,$(MAKECMDGOALS)),)
296 # Add build properties for ART. These define system properties used by installd
297 # to pass flags to dex2oat.
298 ADDITIONAL_BUILD_PROPERTIES += persist.sys.dalvik.vm.lib.2=libart
299 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).variant=$(DEX2OAT_TARGET_CPU_VARIANT)
300 ifneq ($(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
301 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).features=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
304 ifdef TARGET_2ND_ARCH
305 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).variant=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT)
306 ifneq ($($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
307 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).features=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
313 user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))
314 enable_target_debugging := true
316 ifneq (,$(user_variant))
317 # Target is secure in user builds.
318 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
319 ADDITIONAL_DEFAULT_PROPERTIES += security.perf_harden=1
321 ifeq ($(user_variant),userdebug)
322 # Pick up some extra useful tools
323 tags_to_install += debug
325 # Disable debugging in plain user builds.
326 enable_target_debugging :=
329 # Turn on Dalvik preoptimization for user builds, but only if not
330 # explicitly disabled and the build is running on Linux (since host
331 # Dalvik isn't built for non-Linux hosts).
332 ifeq (,$(WITH_DEXPREOPT))
333 ifeq ($(user_variant),user)
334 ifeq ($(HOST_OS),linux)
335 # TODO: turn on WITH_DEXPREOPT for libart user builds.
336 # WITH_DEXPREOPT := true
341 # Disallow mock locations by default for user builds
342 ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0
345 # Turn on checkjni for non-user builds.
346 ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1
347 # Set device insecure for non-user builds.
348 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
349 # Allow mock locations by default for non user builds
350 ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
351 endif # !user_variant
353 ifeq (true,$(strip $(enable_target_debugging)))
354 # Target is more debuggable and adbd is on by default
355 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1
356 # Enable Dalvik lock contention logging.
357 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500
358 # Include the debugging/testing OTA keys in this build.
359 INCLUDE_TEST_OTA_KEYS := true
360 else # !enable_target_debugging
361 # Target is less debuggable and adbd is off by default
362 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0
363 endif # !enable_target_debugging
367 ifeq ($(TARGET_BUILD_VARIANT),eng)
368 tags_to_install := debug eng
369 ifneq ($(filter ro.setupwizard.mode=ENABLED, $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))),)
370 # Don't require the setup wizard on eng builds
371 ADDITIONAL_BUILD_PROPERTIES := $(filter-out ro.setupwizard.mode=%,\
372 $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))) \
373 ro.setupwizard.mode=OPTIONAL
376 # Don't verify or compile the image on eng builds to speed startup.
377 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.image-dex2oat-filter=verify-at-runtime
378 # Don't verify or compile apps on eng builds to speed startup.
379 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dex2oat-filter=verify-at-runtime
381 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.usejit=true
388 # Detect if we want to build a repository for the SDK
389 sdk_repo_goal := $(strip $(filter sdk_repo,$(MAKECMDGOALS)))
390 MAKECMDGOALS := $(strip $(filter-out sdk_repo,$(MAKECMDGOALS)))
392 ifneq ($(words $(filter-out $(INTERNAL_MODIFIER_TARGETS) checkbuild emulator_tests target-files-package,$(MAKECMDGOALS))),1)
393 $(error The 'sdk' target may not be specified with any other targets)
396 # TODO: this should be eng I think. Since the sdk is built from the eng
398 tags_to_install := debug eng
399 ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true
400 ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes
404 BUILD_WITHOUT_PV := true
406 ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android
408 # enable vm tracing in files for now to help track
409 # the cause of ANRs in the content process
410 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.stack-trace-file=/data/anr/traces.txt
412 # ------------------------------------------------------------
413 # Define a function that, given a list of module tags, returns
414 # non-empty if that module should be installed in /system.
416 # For most goals, anything not tagged with the "tests" tag should
417 # be installed in /system.
418 define should-install-to-system
419 $(if $(filter tests,$(1)),,true)
423 # For the sdk goal, anything with the "samples" tag should be
424 # installed in /data even if that module also has "eng"/"debug"/"user".
425 define should-install-to-system
426 $(if $(filter samples tests,$(1)),,true)
431 # If they only used the modifier goals (showcommands, etc), we'll actually
432 # build the default target.
433 ifeq ($(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS)),)
434 .PHONY: $(INTERNAL_MODIFIER_TARGETS)
435 $(INTERNAL_MODIFIER_TARGETS): $(DEFAULT_GOAL)
438 # Bring in all modules that need to be built.
439 ifeq ($(HOST_OS),windows)
443 ifeq ($(SDK_ONLY),true)
444 include $(TOPDIR)sdk/build/windows_sdk_whitelist.mk
445 include $(TOPDIR)development/build/windows_sdk_whitelist.mk
447 # Exclude tools/acp when cross-compiling windows under linux
448 ifeq ($(findstring Linux,$(UNAME)),)
449 subdirs += build/tools/acp
454 # Typical build; include any Android.mk files we can find.
462 # Before we go and include all of the module makefiles, stash away
463 # the PRODUCT_* values so that later we can verify they are not modified.
464 stash_product_vars:=true
465 ifeq ($(stash_product_vars),true)
466 $(call stash-product-vars, __STASHED)
469 ifneq ($(ONE_SHOT_MAKEFILE),)
470 # We've probably been invoked by the "mm" shell function
471 # with a subdirectory's makefile.
472 include $(ONE_SHOT_MAKEFILE)
473 # Change CUSTOM_MODULES to include only modules that were
474 # defined by this makefile; this will install all of those
475 # modules as a side-effect. Do this after including ONE_SHOT_MAKEFILE
476 # so that the modules will be installed in the same place they
477 # would have been with a normal make.
478 CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS)))
480 # Stub out the notice targets, which probably aren't defined
481 # when using ONE_SHOT_MAKEFILE.
485 # A helper goal printing out install paths
486 .PHONY: GET-INSTALL-PATH
488 @$(foreach m, $(ALL_MODULES), $(if $(ALL_MODULES.$(m).INSTALLED), \
489 echo 'INSTALL-PATH: $(m) $(ALL_MODULES.$(m).INSTALLED)';))
491 else # ONE_SHOT_MAKEFILE
493 ifneq ($(dont_bother),true)
495 # Include all of the makefiles in the system
498 # Can't use first-makefiles-under here because
499 # --mindepth=2 makes the prunes not work.
500 subdir_makefiles := \
501 $(shell build/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) $(subdirs) Android.mk)
503 $(foreach mk, $(subdir_makefiles), $(info including $(mk) ...)$(eval include $(mk)))
507 endif # ONE_SHOT_MAKEFILE
509 # Now with all Android.mks loaded we can do post cleaning steps.
510 include $(BUILD_SYSTEM)/post_clean.mk
512 ifeq ($(stash_product_vars),true)
513 $(call assert-product-vars, __STASHED)
516 include $(BUILD_SYSTEM)/legacy_prebuilts.mk
517 ifneq ($(filter-out $(GRANDFATHERED_ALL_PREBUILT),$(strip $(notdir $(ALL_PREBUILT)))),)
518 $(warning *** Some files have been added to ALL_PREBUILT.)
520 $(warning * ALL_PREBUILT is a deprecated mechanism that)
521 $(warning * should not be used for new files.)
522 $(warning * As an alternative, use PRODUCT_COPY_FILES in)
523 $(warning * the appropriate product definition.)
524 $(warning * build/target/product/core.mk is the product)
525 $(warning * definition used in all products.)
527 $(foreach bad_prebuilt,$(filter-out $(GRANDFATHERED_ALL_PREBUILT),$(strip $(notdir $(ALL_PREBUILT)))),$(warning * unexpected $(bad_prebuilt) in ALL_PREBUILT))
529 $(error ALL_PREBUILT contains unexpected files)
532 # -------------------------------------------------------------------
533 # All module makefiles have been included at this point.
534 # -------------------------------------------------------------------
537 # -------------------------------------------------------------------
538 # Fix up CUSTOM_MODULES to refer to installed files rather than
539 # just bare module names. Leave unknown modules alone in case
540 # they're actually full paths to a particular file.
541 known_custom_modules := $(filter $(ALL_MODULES),$(CUSTOM_MODULES))
542 unknown_custom_modules := $(filter-out $(ALL_MODULES),$(CUSTOM_MODULES))
544 $(call module-installed-files,$(known_custom_modules)) \
545 $(unknown_custom_modules)
547 # -------------------------------------------------------------------
548 # Define dependencies for modules that require other modules.
549 # This can only happen now, after we've read in all module makefiles.
551 # TODO: deal with the fact that a bare module name isn't
552 # unambiguous enough. Maybe declare short targets like
553 # APPS:Quake or HOST:SHARED_LIBRARIES:libutils.
554 # BUG: the system image won't know to depend on modules that are
555 # brought in as requirements of other modules.
557 # Resolve the required module name to 32-bit or 64-bit variant.
558 # Get a list of corresponding 32-bit module names, if one exists.
559 define get-32-bit-modules
560 $(strip $(foreach m,$(1),\
561 $(if $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS),\
562 $(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX))))
564 # Get a list of corresponding 32-bit module names, if one exists;
565 # otherwise return the original module name
566 define get-32-bit-modules-if-we-can
567 $(strip $(foreach m,$(1),\
568 $(if $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS),\
569 $(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX),
573 # If a module is built for 32-bit, the required modules must be 32-bit too;
574 # Otherwise if the module is an exectuable or shared library,
575 # the required modules must be 64-bit;
576 # otherwise we require both 64-bit and 32-bit variant, if one exists.
577 $(foreach m,$(ALL_MODULES),\
578 $(eval r := $(ALL_MODULES.$(m).REQUIRED))\
580 $(if $(ALL_MODULES.$(m).FOR_2ND_ARCH),\
581 $(eval r_r := $(call get-32-bit-modules-if-we-can,$(r))),\
582 $(if $(filter EXECUTABLES SHARED_LIBRARIES,$(ALL_MODULES.$(m).CLASS)),\
583 $(eval r_r := $(r)),\
584 $(eval r_r := $(r) $(call get-32-bit-modules,$(r)))\
587 $(eval ALL_MODULES.$(m).REQUIRED := $(strip $(r_r)))\
592 define add-required-deps
596 $(foreach m,$(ALL_MODULES), \
597 $(eval r := $(ALL_MODULES.$(m).REQUIRED)) \
599 $(eval r := $(call module-installed-files,$(r))) \
600 $(eval t_m := $(filter $(TARGET_OUT_ROOT)/%, $(ALL_MODULES.$(m).INSTALLED))) \
601 $(eval h_m := $(filter $(HOST_OUT_ROOT)/%, $(ALL_MODULES.$(m).INSTALLED))) \
602 $(eval t_r := $(filter $(TARGET_OUT_ROOT)/%, $(r))) \
603 $(eval h_r := $(filter $(HOST_OUT_ROOT)/%, $(r))) \
604 $(eval t_m := $(filter-out $(t_r), $(t_m))) \
605 $(eval h_m := $(filter-out $(h_r), $(h_m))) \
606 $(if $(t_m), $(eval $(call add-required-deps, $(t_m),$(t_r)))) \
607 $(if $(h_m), $(eval $(call add-required-deps, $(h_m),$(h_r)))) \
616 # Establish the dependecies on the shared libraries.
617 # It also adds the shared library module names to ALL_MODULES.$(m).REQUIRED,
618 # so they can be expanded to product_MODULES later.
619 # $(1): TARGET_ or HOST_.
620 # $(2): non-empty for 2nd arch.
621 define resolve-shared-libs-depes
622 $(foreach m,$($(if $(2),$($(1)2ND_ARCH_VAR_PREFIX))$(1)DEPENDENCIES_ON_SHARED_LIBRARIES),\
623 $(eval p := $(subst :,$(space),$(m)))\
624 $(eval mod := $(firstword $(p)))\
625 $(eval deps := $(subst $(comma),$(space),$(lastword $(p))))\
626 $(if $(2),$(eval deps := $(addsuffix $($(1)2ND_ARCH_MODULE_SUFFIX),$(deps))))\
627 $(eval r := $(filter $($(1)OUT_ROOT)/%,$(call module-installed-files,\
629 $(eval $(call add-required-deps,$(word 2,$(p)),$(r)))\
630 $(eval ALL_MODULES.$(mod).REQUIRED += $(deps)))
633 $(call resolve-shared-libs-depes,TARGET_)
634 ifdef TARGET_2ND_ARCH
635 $(call resolve-shared-libs-depes,TARGET_,true)
637 $(call resolve-shared-libs-depes,HOST_)
639 $(call resolve-shared-libs-depes,HOST_,true)
648 # -------------------------------------------------------------------
649 # Figure out our module sets.
651 # Of the modules defined by the component makefiles,
652 # determine what we actually want to build.
654 ###########################################################
655 ## Expand a module name list with REQUIRED modules
656 ###########################################################
657 # $(1): The variable name that holds the initial module name list.
658 # the variable will be modified to hold the expanded results.
659 # $(2): The initial module name list.
660 # Returns empty string (maybe with some whitespaces).
661 define expand-required-modules
662 $(eval _erm_new_modules := $(sort $(filter-out $($(1)),\
663 $(foreach m,$(2),$(ALL_MODULES.$(m).REQUIRED)))))\
664 $(if $(_erm_new_modules),$(eval $(1) += $(_erm_new_modules))\
665 $(call expand-required-modules,$(1),$(_erm_new_modules)))
669 # The base list of modules to build for this product is specified
670 # by the appropriate product definition file, which was included
671 # by product_config.mk.
672 product_MODULES := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES)
673 # Filter out the overridden packages before doing expansion
674 product_MODULES := $(filter-out $(foreach p, $(product_MODULES), \
675 $(PACKAGES.$(p).OVERRIDES)), $(product_MODULES))
677 # Resolve the :32 :64 module name
678 modules_32 := $(patsubst %:32,%,$(filter %:32, $(product_MODULES)))
679 modules_64 := $(patsubst %:64,%,$(filter %:64, $(product_MODULES)))
680 modules_rest := $(filter-out %:32 %:64,$(product_MODULES))
681 # Note for 32-bit product, $(modules_32) and $(modules_64) will be
682 # added as their original module names.
683 product_MODULES := $(call get-32-bit-modules-if-we-can, $(modules_32))
684 product_MODULES += $(modules_64)
685 # For the rest we add both
686 product_MODULES += $(call get-32-bit-modules, $(modules_rest))
687 product_MODULES += $(modules_rest)
689 $(call expand-required-modules,product_MODULES,$(product_MODULES))
691 product_FILES := $(call module-installed-files, $(product_MODULES))
693 $(info product_FILES for $(TARGET_DEVICE) ($(INTERNAL_PRODUCT)):)
694 $(foreach p,$(product_FILES),$(info : $(p)))
698 # We're not doing a full build, and are probably only including
699 # a subset of the module makefiles. Don't try to build any modules
700 # requested by the product, because we probably won't have rules
705 eng_MODULES := $(sort \
706 $(call get-tagged-modules,eng) \
707 $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_ENG)) \
709 debug_MODULES := $(sort \
710 $(call get-tagged-modules,debug) \
711 $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_DEBUG)) \
713 tests_MODULES := $(sort \
714 $(call get-tagged-modules,tests) \
715 $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_TESTS)) \
718 # TODO: Remove the 3 places in the tree that use ALL_DEFAULT_INSTALLED_MODULES
719 # and get rid of it from this list.
720 modules_to_install := $(sort \
721 $(ALL_DEFAULT_INSTALLED_MODULES) \
723 $(foreach tag,$(tags_to_install),$($(tag)_MODULES)) \
727 # Some packages may override others using LOCAL_OVERRIDES_PACKAGES.
728 # Filter out (do not install) any overridden packages.
729 overridden_packages := $(call get-package-overrides,$(modules_to_install))
730 ifdef overridden_packages
731 # old_modules_to_install := $(modules_to_install)
732 modules_to_install := \
733 $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
734 $(modules_to_install))
736 #$(error filtered out
737 # $(filter-out $(modules_to_install),$(old_modules_to_install)))
739 # Don't include any GNU General Public License shared objects or static
740 # libraries in SDK images. GPL executables (not static/dynamic libraries)
741 # are okay if they don't link against any closed source libraries (directly
744 # It's ok (and necessary) to build the host tools, but nothing that's
745 # going to be installed on the target (including static libraries).
748 target_gnu_MODULES := \
750 $(TARGET_OUT_INTERMEDIATES)/% \
752 $(TARGET_OUT_DATA)/%, \
753 $(sort $(call get-tagged-modules,gnu)))
754 target_gnu_MODULES := $(filter-out $(TARGET_OUT_EXECUTABLES)/%,$(target_gnu_MODULES))
755 $(info Removing from sdk:)$(foreach d,$(target_gnu_MODULES),$(info : $(d)))
756 modules_to_install := \
757 $(filter-out $(target_gnu_MODULES),$(modules_to_install))
759 # Ensure every module listed in PRODUCT_PACKAGES* gets something installed
760 # TODO: Should we do this for all builds and not just the sdk?
762 $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES), \
763 $(if $(strip $(ALL_MODULES.$(m).INSTALLED) $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).INSTALLED)),,\
764 $(eval dangling_modules += $(m))))
765 ifneq ($(dangling_modules),)
766 $(warning: Modules '$(dangling_modules)' in PRODUCT_PACKAGES have nothing to install!)
768 $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_DEBUG), \
769 $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\
770 $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_DEBUG has nothing to install!)))
771 $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_ENG), \
772 $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\
773 $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_ENG has nothing to install!)))
774 $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_TESTS), \
775 $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\
776 $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_TESTS has nothing to install!)))
779 # build/core/Makefile contains extra stuff that we don't want to pollute this
780 # top-level makefile with. It expects that ALL_DEFAULT_INSTALLED_MODULES
781 # contains everything that's built during the current make, but it also further
782 # extends ALL_DEFAULT_INSTALLED_MODULES.
783 ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_install)
784 include $(BUILD_SYSTEM)/Makefile
785 modules_to_install := $(sort $(ALL_DEFAULT_INSTALLED_MODULES))
786 ALL_DEFAULT_INSTALLED_MODULES :=
789 # These are additional goals that we build, in order to make sure that there
790 # is as little code as possible in the tree that doesn't build.
791 modules_to_check := $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).CHECKED))
793 # If you would like to build all goals, and not skip any intermediate
794 # steps, you can pass the "all" modifier goal on the commandline.
795 ifneq ($(filter all,$(MAKECMDGOALS)),)
796 modules_to_check += $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).BUILT))
799 # for easier debugging
800 modules_to_check := $(sort $(modules_to_check))
801 #$(error modules_to_check $(modules_to_check))
803 # -------------------------------------------------------------------
804 # This is used to to get the ordering right, you can also use these,
805 # but they're considered undocumented, so don't complain if their
808 prebuilt: $(ALL_PREBUILT)
810 # An internal target that depends on all copied headers
811 # (see copy_headers.make). Other targets that need the
812 # headers to be copied first can depend on this target.
813 .PHONY: all_copied_headers
814 all_copied_headers: ;
816 $(ALL_C_CPP_ETC_OBJECTS): | all_copied_headers
818 # All the droid stuff, in directories
821 $(modules_to_install) \
822 $(INSTALLED_ANDROID_INFO_TXT_TARGET)
824 # -------------------------------------------------------------------
827 checkbuild: $(modules_to_check)
828 ifeq (true,$(ANDROID_BUILD_EVERYTHING_BY_DEFAULT)$(filter $(MAKECMDGOALS),checkbuild))
831 # ANDROID_BUILD_EVERYTHING_BY_DEFAULT not set, or checkbuild is one of the cmd goals.
836 ramdisk: $(INSTALLED_RAMDISK_TARGET)
838 .PHONY: systemtarball
839 systemtarball: $(INSTALLED_SYSTEMTARBALL_TARGET)
842 boottarball: $(INSTALLED_BOOTTARBALL_TARGET)
844 .PHONY: userdataimage
845 userdataimage: $(INSTALLED_USERDATAIMAGE_TARGET)
847 ifneq (,$(filter userdataimage, $(MAKECMDGOALS)))
848 $(call dist-for-goals, userdataimage, $(BUILT_USERDATAIMAGE_TARGET))
851 .PHONY: userdatatarball
852 userdatatarball: $(INSTALLED_USERDATATARBALL_TARGET)
855 cacheimage: $(INSTALLED_CACHEIMAGE_TARGET)
858 vendorimage: $(INSTALLED_VENDORIMAGE_TARGET)
861 bootimage: $(INSTALLED_BOOTIMAGE_TARGET)
863 # phony target that include any targets in $(ALL_MODULES)
865 ifndef BUILD_MODULES_IN_PATHS
866 all_modules: $(ALL_MODULES)
868 # BUILD_MODULES_IN_PATHS is a list of paths relative to the top of the tree
869 module_path_patterns := $(foreach p, $(BUILD_MODULES_IN_PATHS),\
870 $(if $(filter %/,$(p)),$(p)%,$(p)/%))
871 my_all_modules := $(sort $(foreach m, $(ALL_MODULES),$(if $(filter\
872 $(module_path_patterns), $(addsuffix /,$(ALL_MODULES.$(m).PATH))),$(m))))
873 all_modules: $(my_all_modules)
877 # Build files and then package it into the rom formats
881 $(INSTALLED_BOOTIMAGE_TARGET) \
882 $(INSTALLED_RECOVERYIMAGE_TARGET) \
883 $(INSTALLED_USERDATAIMAGE_TARGET) \
884 $(INSTALLED_CACHEIMAGE_TARGET) \
885 $(INSTALLED_VENDORIMAGE_TARGET) \
886 $(INSTALLED_FILES_FILE)
888 # dist_files only for putting your library into the dist directory with a full build.
891 ifneq ($(TARGET_BUILD_APPS),)
892 # If this build is just for apps, only build apps and not the full system by default.
894 unbundled_build_modules :=
895 ifneq ($(filter all,$(TARGET_BUILD_APPS)),)
896 # If they used the magic goal "all" then build all apps in the source tree.
897 unbundled_build_modules := $(foreach m,$(sort $(ALL_MODULES)),$(if $(filter APPS,$(ALL_MODULES.$(m).CLASS)),$(m)))
899 unbundled_build_modules := $(TARGET_BUILD_APPS)
902 # Dist the installed files if they exist.
903 apps_only_installed_files := $(foreach m,$(unbundled_build_modules),$(ALL_MODULES.$(m).INSTALLED))
904 $(call dist-for-goals,apps_only, $(apps_only_installed_files))
905 # For uninstallable modules such as static Java library, we have to dist the built file,
906 # as <module_name>.<suffix>
907 apps_only_dist_built_files := $(foreach m,$(unbundled_build_modules),$(if $(ALL_MODULES.$(m).INSTALLED),,\
908 $(if $(ALL_MODULES.$(m).BUILT),$(ALL_MODULES.$(m).BUILT):$(m)$(suffix $(ALL_MODULES.$(m).BUILT)))\
909 $(if $(ALL_MODULES.$(m).AAR),$(ALL_MODULES.$(m).AAR):$(m).aar)\
911 $(call dist-for-goals,apps_only, $(apps_only_dist_built_files))
913 ifeq ($(EMMA_INSTRUMENT),true)
914 $(EMMA_META_ZIP) : $(apps_only_installed_files)
916 $(call dist-for-goals,apps_only, $(EMMA_META_ZIP))
919 $(PROGUARD_DICT_ZIP) : $(apps_only_installed_files)
920 $(call dist-for-goals,apps_only, $(PROGUARD_DICT_ZIP))
922 $(SYMBOLS_ZIP) : $(apps_only_installed_files)
923 $(call dist-for-goals,apps_only, $(SYMBOLS_ZIP))
926 apps_only: $(unbundled_build_modules)
930 # Combine the NOTICE files for a apps_only build
931 $(eval $(call combine-notice-files, \
932 $(target_notice_file_txt), \
933 $(target_notice_file_html), \
934 "Notices for files for apps:", \
935 $(TARGET_OUT_NOTICE_FILES), \
936 $(apps_only_installed_files)))
939 else # TARGET_BUILD_APPS
940 $(call dist-for-goals, droidcore, \
941 $(INTERNAL_UPDATE_PACKAGE_TARGET) \
942 $(INTERNAL_OTA_PACKAGE_TARGET) \
943 $(BUILT_OTATOOLS_PACKAGE) \
945 $(INSTALLED_FILES_FILE) \
946 $(INSTALLED_BUILD_PROP_TARGET) \
947 $(BUILT_TARGET_FILES_PACKAGE) \
948 $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
949 $(INSTALLED_RAMDISK_TARGET) \
952 # Put a copy of the radio/bootloader files in the dist dir.
953 $(foreach f,$(INSTALLED_RADIOIMAGE_TARGET), \
954 $(call dist-for-goals, droidcore, $(f)))
956 ifneq ($(ANDROID_BUILD_EMBEDDED),true)
957 ifneq ($(TARGET_BUILD_PDK),true)
958 $(call dist-for-goals, droidcore, \
960 $(INTERNAL_EMULATOR_PACKAGE_TARGET) \
961 $(PACKAGE_STATS_FILE) \
966 ifeq ($(EMMA_INSTRUMENT),true)
967 $(EMMA_META_ZIP) : $(INSTALLED_SYSTEMIMAGE)
969 $(call dist-for-goals, dist_files, $(EMMA_META_ZIP))
972 # Building a full system-- the default is to build droidcore
973 droid: droidcore dist_files
975 endif # TARGET_BUILD_APPS
981 ALL_SDK_TARGETS := $(INTERNAL_SDK_TARGET)
982 sdk: $(ALL_SDK_TARGETS)
983 $(call dist-for-goals,sdk win_sdk, \
986 $(INSTALLED_BUILD_PROP_TARGET) \
989 # umbrella targets to assit engineers in verifying builds
990 .PHONY: java native target host java-host java-target native-host native-target \
991 java-host-tests java-target-tests native-host-tests native-target-tests \
992 java-tests native-tests host-tests target-tests tests
994 .PHONY: host-java target-java host-native target-native \
995 target-java-tests target-native-tests
996 host-java : java-host
997 target-java : java-target
998 host-native : native-host
999 target-native : native-target
1000 target-java-tests : java-target-tests
1001 target-native-tests : native-target-tests
1002 tests : host-tests target-tests
1004 # To catch more build breakage, check build tests modules in eng and userdebug builds.
1005 ifneq ($(TARGET_BUILD_PDK),true)
1006 ifneq ($(filter eng userdebug,$(TARGET_BUILD_VARIANT)),)
1007 droidcore : target-tests host-tests
1013 ifneq (,$(filter samplecode, $(MAKECMDGOALS)))
1015 sample_MODULES := $(sort $(call get-tagged-modules,samples))
1016 sample_APKS_DEST_PATH := $(TARGET_COMMON_OUT_ROOT)/samples
1017 sample_APKS_COLLECTION := \
1018 $(foreach module,$(sample_MODULES),$(sample_APKS_DEST_PATH)/$(notdir $(module)))
1019 $(foreach module,$(sample_MODULES),$(eval $(call \
1020 copy-one-file,$(module),$(sample_APKS_DEST_PATH)/$(notdir $(module)))))
1021 sample_ADDITIONAL_INSTALLED := \
1022 $(filter-out $(modules_to_install) $(modules_to_check) $(ALL_PREBUILT),$(sample_MODULES))
1023 samplecode: $(sample_APKS_COLLECTION)
1024 @echo "Collect sample code apks: $^"
1025 # remove apks that are not intended to be installed.
1026 rm -f $(sample_ADDITIONAL_INSTALLED)
1027 endif # samplecode in $(MAKECMDGOALS)
1030 findbugs: $(INTERNAL_FINDBUGS_HTML_TARGET) $(INTERNAL_FINDBUGS_XML_TARGET)
1034 @rm -rf $(OUT_DIR)/*
1035 @echo "Entire build directory removed."
1040 # The rules for dataclean and installclean are defined in cleanbuild.mk.
1042 #xxx scrape this from ALL_MODULE_NAME_TAGS
1045 @echo "Available sub-modules:"
1046 @echo "$(call module-names-for-tag-list,$(ALL_MODULE_TAGS))" | \
1047 tr -s ' ' '\n' | sort -u | $(COLUMN)
1049 .PHONY: showcommands
1055 @echo Successfully read the makefiles.