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. 41# (Allow any version under Cygwin since we don't actually build the platform there.) 42ifeq (,$(findstring CYGWIN,$(shell uname -sm))) 43ifneq (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 ********************************************************************************) 49$(error stopping) 50endif 51endif 52 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. 56PWD := $(shell pwd) 57 58TOP := . 59TOPDIR := 60 61BUILD_SYSTEM := $(TOPDIR)build/core 62 63# This is the default target. It must be the first declared target. 64.PHONY: droid 65DEFAULT_GOAL := droid 66$(DEFAULT_GOAL): 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 85ifneq ($(filter $(dont_bother_goals), $(MAKECMDGOALS)),) 86dont_bother := true 87endif 88 89# Targets that provide quick help on the build system. 90include $(BUILD_SYSTEM)/help.mk 91 92# Set up various standard variables based on configuration 93# and host information. 94include $(BUILD_SYSTEM)/config.mk 95 96# CTS-specific config. 97-include cts/build/config.mk 98 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 103include $(BUILD_SYSTEM)/cleanbuild.mk 104 105# Include the google-specific config 106-include vendor/google/build/config.mk 107 108VERSION_CHECK_SEQUENCE_NUMBER := 5 109-include $(OUT_DIR)/versions_checked.mk 110ifneq ($(VERSION_CHECK_SEQUENCE_NUMBER),$(VERSIONS_CHECKED)) 111 112$(info Checking build tools versions...) 113 114ifneq ($(HOST_OS),windows) 115# check for a case sensitive file system 116ifneq (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) 125endif 126endif 127 128# Make sure that there are no spaces in the absolute path; the 129# build system can't deal with them. 130ifneq ($(words $(shell pwd)),1) 131$(warning ************************************************************) 132$(warning You are building in a directory whose absolute path contains) 133$(warning a space character:) 134$(warning $(space)) 135$(warning "$(shell pwd)") 136$(warning $(space)) 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) 141endif 142 143java_version_str := $(shell unset _JAVA_OPTIONS && java -version 2>&1) 144javac_version_str := $(shell unset _JAVA_OPTIONS && javac -version 2>&1) 145 146# Check for the correct version of java, should be 1.7 by 147# default, and 1.8 if EXPERIMENTAL_USE_JAVA8 is set 148ifneq ($(EXPERIMENTAL_USE_JAVA8),) 149required_version := "1.8.x" 150required_javac_version := "1.8" 151java_version := $(shell echo '$(java_version_str)' | grep 'openjdk .*[ "]1\.8[\. "$$]') 152javac_version := $(shell echo '$(javac_version_str)' | grep '[ "]1\.8[\. "$$]') 153else # default 154required_version := "1.7.x" 155required_javac_version := "1.7" 156java_version := $(shell echo '$(java_version_str)' | grep '^java .*[ "]1\.7[\. "$$]') 157javac_version := $(shell echo '$(javac_version_str)' | grep '[ "]1\.7[\. "$$]') 158endif # if EXPERIMENTAL_USE_JAVA8 159 160ifeq ($(strip $(java_version)),) 161$(info ************************************************************) 162$(info You are attempting to build with the incorrect version) 163$(info of java.) 164$(info $(space)) 165$(info Your version is: $(java_version_str).) 166$(info The required version is: $(required_version)) 167$(info $(space)) 168$(info Please follow the machine setup instructions at) 169$(info $(space)$(space)$(space)$(space)https://source.android.com/source/initializing.html) 170$(info ************************************************************) 171$(error stop) 172endif 173 174# Check for the current JDK. 175# 176# For Java 1.7, we require OpenJDK on linux and Oracle JDK on Mac OS. 177requires_openjdk := false 178ifeq ($(HOST_OS), linux) 179requires_openjdk := true 180endif 181 182 183# Check for the current jdk 184ifeq ($(requires_openjdk), true) 185# The user asked for java7 openjdk, so check that the host 186# java version is really openjdk 187ifeq ($(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 ************************************************************) 192$(error stop) 193endif # java version is not OpenJdk 194else # if requires_openjdk 195ifneq ($(shell echo '$(java_version_str)' | grep -i openjdk),) 196$(info ************************************************************) 197$(info You are attempting to build with an unsupported JDK.) 198$(info $(space)) 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 ************************************************************) 203$(error stop) 204endif # java version is not Sun Oracle JDK 205endif # if requires_openjdk 206 207# Check for the correct version of javac 208ifeq ($(strip $(javac_version)),) 209$(info ************************************************************) 210$(info You are attempting to build with the incorrect version) 211$(info of javac.) 212$(info $(space)) 213$(info Your version is: $(javac_version_str).) 214$(info The required version is: $(required_javac_version)) 215$(info $(space)) 216$(info Please follow the machine setup instructions at) 217$(info $(space)$(space)$(space)$(space)https://source.android.com/source/download.html) 218$(info ************************************************************) 219$(error stop) 220endif 221 222 223ifndef BUILD_EMULATOR 224 # Emulator binaries are now provided under prebuilts/android-emulator/ 225 BUILD_EMULATOR := false 226endif 227 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) 232endif 233 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) 237INTERNAL_MODIFIER_TARGETS := showcommands all 238 239# EMMA_INSTRUMENT_STATIC merges the static emma library to each emma-enabled module. 240ifeq (true,$(EMMA_INSTRUMENT_STATIC)) 241EMMA_INSTRUMENT := true 242endif 243 244# Bring in standard build system definitions. 245include $(BUILD_SYSTEM)/definitions.mk 246 247# Bring in dex_preopt.mk 248include $(BUILD_SYSTEM)/dex_preopt.mk 249 250ifneq ($(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) 256$(info choosecombo.) 257$(info ***************************************************************) 258$(info ***************************************************************) 259$(error stopping) 260endif 261 262ifneq ($(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 ***************************************************************) 269$(error stopping) 270endif 271 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 278TARGET_BUILD_JAVA_SUPPORT_LEVEL := platform 279 280# ----------------------------------------------------------------- 281# The pdk (Platform Development Kit) build 282include build/core/pdk_config.mk 283 284# ----------------------------------------------------------------- 285### 286### In this section we set up the things that are different 287### between the build variants 288### 289 290is_sdk_build := 291 292ifneq ($(filter sdk win_sdk sdk_addon,$(MAKECMDGOALS)),) 293is_sdk_build := true 294endif 295 296# Add build properties for ART. These define system properties used by installd 297# to pass flags to dex2oat. 298ADDITIONAL_BUILD_PROPERTIES += persist.sys.dalvik.vm.lib.2=libart 299ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).variant=$(DEX2OAT_TARGET_CPU_VARIANT) 300ifneq ($(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),) 301 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).features=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) 302endif 303 304ifdef 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) 308 endif 309endif 310 311## user/userdebug ## 312 313user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT)) 314enable_target_debugging := true 315tags_to_install := 316ifneq (,$(user_variant)) 317 # Target is secure in user builds. 318 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1 319 ADDITIONAL_DEFAULT_PROPERTIES += security.perf_harden=1 320 321 ifeq ($(user_variant),userdebug) 322 # Pick up some extra useful tools 323 tags_to_install += debug 324 else 325 # Disable debugging in plain user builds. 326 enable_target_debugging := 327 endif 328 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 337 endif 338 endif 339 endif 340 341 # Disallow mock locations by default for user builds 342 ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0 343 344else # !user_variant 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 351endif # !user_variant 352 353ifeq (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 360else # !enable_target_debugging 361 # Target is less debuggable and adbd is off by default 362 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 363endif # !enable_target_debugging 364 365## eng ## 366 367ifeq ($(TARGET_BUILD_VARIANT),eng) 368tags_to_install := debug eng 369ifneq ($(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 374endif 375ifndef is_sdk_build 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 380endif 381 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.usejit=true 382endif 383 384## sdk ## 385 386ifdef is_sdk_build 387 388# Detect if we want to build a repository for the SDK 389sdk_repo_goal := $(strip $(filter sdk_repo,$(MAKECMDGOALS))) 390MAKECMDGOALS := $(strip $(filter-out sdk_repo,$(MAKECMDGOALS))) 391 392ifneq ($(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) 394endif 395 396# TODO: this should be eng I think. Since the sdk is built from the eng 397# variant. 398tags_to_install := debug eng 399ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true 400ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes 401else # !sdk 402endif 403 404BUILD_WITHOUT_PV := true 405 406ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android 407 408# enable vm tracing in files for now to help track 409# the cause of ANRs in the content process 410ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.stack-trace-file=/data/anr/traces.txt 411 412# ------------------------------------------------------------ 413# Define a function that, given a list of module tags, returns 414# non-empty if that module should be installed in /system. 415 416# For most goals, anything not tagged with the "tests" tag should 417# be installed in /system. 418define should-install-to-system 419$(if $(filter tests,$(1)),,true) 420endef 421 422ifdef is_sdk_build 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". 425define should-install-to-system 426$(if $(filter samples tests,$(1)),,true) 427endef 428endif 429 430 431# If they only used the modifier goals (showcommands, etc), we'll actually 432# build the default target. 433ifeq ($(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS)),) 434.PHONY: $(INTERNAL_MODIFIER_TARGETS) 435$(INTERNAL_MODIFIER_TARGETS): $(DEFAULT_GOAL) 436endif 437 438# Bring in all modules that need to be built. 439ifeq ($(HOST_OS),windows) 440SDK_ONLY := true 441endif 442 443ifeq ($(SDK_ONLY),true) 444include $(TOPDIR)sdk/build/windows_sdk_whitelist.mk 445include $(TOPDIR)development/build/windows_sdk_whitelist.mk 446 447# Exclude tools/acp when cross-compiling windows under linux 448ifeq ($(findstring Linux,$(UNAME)),) 449subdirs += build/tools/acp 450endif 451 452else # !SDK_ONLY 453# 454# Typical build; include any Android.mk files we can find. 455# 456subdirs := $(TOP) 457 458FULL_BUILD := true 459 460endif # !SDK_ONLY 461 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. 464stash_product_vars:=true 465ifeq ($(stash_product_vars),true) 466 $(call stash-product-vars, __STASHED) 467endif 468 469ifneq ($(ONE_SHOT_MAKEFILE),) 470# We've probably been invoked by the "mm" shell function 471# with a subdirectory's makefile. 472include $(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. 478CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS))) 479FULL_BUILD := 480# Stub out the notice targets, which probably aren't defined 481# when using ONE_SHOT_MAKEFILE. 482NOTICE-HOST-%: ; 483NOTICE-TARGET-%: ; 484 485# A helper goal printing out install paths 486.PHONY: GET-INSTALL-PATH 487GET-INSTALL-PATH: 488 @$(foreach m, $(ALL_MODULES), $(if $(ALL_MODULES.$(m).INSTALLED), \ 489 echo 'INSTALL-PATH: $(m) $(ALL_MODULES.$(m).INSTALLED)';)) 490 491else # ONE_SHOT_MAKEFILE 492 493ifneq ($(dont_bother),true) 494# 495# Include all of the makefiles in the system 496# 497 498# Can't use first-makefiles-under here because 499# --mindepth=2 makes the prunes not work. 500subdir_makefiles := \ 501 $(shell build/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) $(subdirs) Android.mk) 502 503$(foreach mk, $(subdir_makefiles), $(info including $(mk) ...)$(eval include $(mk))) 504 505endif # dont_bother 506 507endif # ONE_SHOT_MAKEFILE 508 509# Now with all Android.mks loaded we can do post cleaning steps. 510include $(BUILD_SYSTEM)/post_clean.mk 511 512ifeq ($(stash_product_vars),true) 513 $(call assert-product-vars, __STASHED) 514endif 515 516include $(BUILD_SYSTEM)/legacy_prebuilts.mk 517ifneq ($(filter-out $(GRANDFATHERED_ALL_PREBUILT),$(strip $(notdir $(ALL_PREBUILT)))),) 518 $(warning *** Some files have been added to ALL_PREBUILT.) 519 $(warning *) 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.) 526 $(warning *) 527 $(foreach bad_prebuilt,$(filter-out $(GRANDFATHERED_ALL_PREBUILT),$(strip $(notdir $(ALL_PREBUILT)))),$(warning * unexpected $(bad_prebuilt) in ALL_PREBUILT)) 528 $(warning *) 529 $(error ALL_PREBUILT contains unexpected files) 530endif 531 532# ------------------------------------------------------------------- 533# All module makefiles have been included at this point. 534# ------------------------------------------------------------------- 535 536 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. 541known_custom_modules := $(filter $(ALL_MODULES),$(CUSTOM_MODULES)) 542unknown_custom_modules := $(filter-out $(ALL_MODULES),$(CUSTOM_MODULES)) 543CUSTOM_MODULES := \ 544 $(call module-installed-files,$(known_custom_modules)) \ 545 $(unknown_custom_modules) 546 547# ------------------------------------------------------------------- 548# Define dependencies for modules that require other modules. 549# This can only happen now, after we've read in all module makefiles. 550# 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. 556# 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. 559define 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)))) 563endef 564# Get a list of corresponding 32-bit module names, if one exists; 565# otherwise return the original module name 566define 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), 570 $(m)))) 571endef 572 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))\ 579 $(if $(r),\ 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)))\ 585 )\ 586 )\ 587 $(eval ALL_MODULES.$(m).REQUIRED := $(strip $(r_r)))\ 588 )\ 589) 590r_r := 591 592define add-required-deps 593$(1): | $(2) 594endef 595 596$(foreach m,$(ALL_MODULES), \ 597 $(eval r := $(ALL_MODULES.$(m).REQUIRED)) \ 598 $(if $(r), \ 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)))) \ 608 ) \ 609 ) 610 611t_m := 612h_m := 613t_r := 614h_r := 615 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. 621define 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,\ 628 $(deps))))\ 629 $(eval $(call add-required-deps,$(word 2,$(p)),$(r)))\ 630 $(eval ALL_MODULES.$(mod).REQUIRED += $(deps))) 631endef 632 633$(call resolve-shared-libs-depes,TARGET_) 634ifdef TARGET_2ND_ARCH 635$(call resolve-shared-libs-depes,TARGET_,true) 636endif 637$(call resolve-shared-libs-depes,HOST_) 638ifdef HOST_2ND_ARCH 639$(call resolve-shared-libs-depes,HOST_,true) 640endif 641 642m := 643r := 644p := 645deps := 646add-required-deps := 647 648# ------------------------------------------------------------------- 649# Figure out our module sets. 650# 651# Of the modules defined by the component makefiles, 652# determine what we actually want to build. 653 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). 661define 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))) 666endef 667 668ifdef FULL_BUILD 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)) 676 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) 688 689 $(call expand-required-modules,product_MODULES,$(product_MODULES)) 690 691 product_FILES := $(call module-installed-files, $(product_MODULES)) 692 ifeq (0,1) 693 $(info product_FILES for $(TARGET_DEVICE) ($(INTERNAL_PRODUCT)):) 694 $(foreach p,$(product_FILES),$(info : $(p))) 695 $(error done) 696 endif 697else 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 701 # to build them. 702 product_FILES := 703endif 704 705eng_MODULES := $(sort \ 706 $(call get-tagged-modules,eng) \ 707 $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_ENG)) \ 708 ) 709debug_MODULES := $(sort \ 710 $(call get-tagged-modules,debug) \ 711 $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_DEBUG)) \ 712 ) 713tests_MODULES := $(sort \ 714 $(call get-tagged-modules,tests) \ 715 $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_TESTS)) \ 716 ) 717 718# TODO: Remove the 3 places in the tree that use ALL_DEFAULT_INSTALLED_MODULES 719# and get rid of it from this list. 720modules_to_install := $(sort \ 721 $(ALL_DEFAULT_INSTALLED_MODULES) \ 722 $(product_FILES) \ 723 $(foreach tag,$(tags_to_install),$($(tag)_MODULES)) \ 724 $(CUSTOM_MODULES) \ 725 ) 726 727# Some packages may override others using LOCAL_OVERRIDES_PACKAGES. 728# Filter out (do not install) any overridden packages. 729overridden_packages := $(call get-package-overrides,$(modules_to_install)) 730ifdef 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)) 735endif 736#$(error filtered out 737# $(filter-out $(modules_to_install),$(old_modules_to_install))) 738 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 742# or indirectly) 743 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). 746 747ifdef is_sdk_build 748 target_gnu_MODULES := \ 749 $(filter \ 750 $(TARGET_OUT_INTERMEDIATES)/% \ 751 $(TARGET_OUT)/% \ 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)) 758 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? 761 dangling_modules := 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!) 767 endif 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!))) 777endif 778 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. 783ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_install) 784include $(BUILD_SYSTEM)/Makefile 785modules_to_install := $(sort $(ALL_DEFAULT_INSTALLED_MODULES)) 786ALL_DEFAULT_INSTALLED_MODULES := 787 788 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. 791modules_to_check := $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).CHECKED)) 792 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. 795ifneq ($(filter all,$(MAKECMDGOALS)),) 796modules_to_check += $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).BUILT)) 797endif 798 799# for easier debugging 800modules_to_check := $(sort $(modules_to_check)) 801#$(error modules_to_check $(modules_to_check)) 802 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 806# behavior changes. 807.PHONY: prebuilt 808prebuilt: $(ALL_PREBUILT) 809 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 814all_copied_headers: ; 815 816$(ALL_C_CPP_ETC_OBJECTS): | all_copied_headers 817 818# All the droid stuff, in directories 819.PHONY: files 820files: prebuilt \ 821 $(modules_to_install) \ 822 $(INSTALLED_ANDROID_INFO_TXT_TARGET) 823 824# ------------------------------------------------------------------- 825 826.PHONY: checkbuild 827checkbuild: $(modules_to_check) 828ifeq (true,$(ANDROID_BUILD_EVERYTHING_BY_DEFAULT)$(filter $(MAKECMDGOALS),checkbuild)) 829droid: checkbuild 830else 831# ANDROID_BUILD_EVERYTHING_BY_DEFAULT not set, or checkbuild is one of the cmd goals. 832checkbuild: droid 833endif 834 835.PHONY: ramdisk 836ramdisk: $(INSTALLED_RAMDISK_TARGET) 837 838.PHONY: systemtarball 839systemtarball: $(INSTALLED_SYSTEMTARBALL_TARGET) 840 841.PHONY: boottarball 842boottarball: $(INSTALLED_BOOTTARBALL_TARGET) 843 844.PHONY: userdataimage 845userdataimage: $(INSTALLED_USERDATAIMAGE_TARGET) 846 847ifneq (,$(filter userdataimage, $(MAKECMDGOALS))) 848$(call dist-for-goals, userdataimage, $(BUILT_USERDATAIMAGE_TARGET)) 849endif 850 851.PHONY: userdatatarball 852userdatatarball: $(INSTALLED_USERDATATARBALL_TARGET) 853 854.PHONY: cacheimage 855cacheimage: $(INSTALLED_CACHEIMAGE_TARGET) 856 857.PHONY: vendorimage 858vendorimage: $(INSTALLED_VENDORIMAGE_TARGET) 859 860.PHONY: bootimage 861bootimage: $(INSTALLED_BOOTIMAGE_TARGET) 862 863# phony target that include any targets in $(ALL_MODULES) 864.PHONY: all_modules 865ifndef BUILD_MODULES_IN_PATHS 866all_modules: $(ALL_MODULES) 867else 868# BUILD_MODULES_IN_PATHS is a list of paths relative to the top of the tree 869module_path_patterns := $(foreach p, $(BUILD_MODULES_IN_PATHS),\ 870 $(if $(filter %/,$(p)),$(p)%,$(p)/%)) 871my_all_modules := $(sort $(foreach m, $(ALL_MODULES),$(if $(filter\ 872 $(module_path_patterns), $(addsuffix /,$(ALL_MODULES.$(m).PATH))),$(m)))) 873all_modules: $(my_all_modules) 874endif 875 876 877# Build files and then package it into the rom formats 878.PHONY: droidcore 879droidcore: files \ 880 systemimage \ 881 $(INSTALLED_BOOTIMAGE_TARGET) \ 882 $(INSTALLED_RECOVERYIMAGE_TARGET) \ 883 $(INSTALLED_USERDATAIMAGE_TARGET) \ 884 $(INSTALLED_CACHEIMAGE_TARGET) \ 885 $(INSTALLED_VENDORIMAGE_TARGET) \ 886 $(INSTALLED_FILES_FILE) 887 888# dist_files only for putting your library into the dist directory with a full build. 889.PHONY: dist_files 890 891ifneq ($(TARGET_BUILD_APPS),) 892 # If this build is just for apps, only build apps and not the full system by default. 893 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))) 898 else 899 unbundled_build_modules := $(TARGET_BUILD_APPS) 900 endif 901 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)\ 910 )) 911 $(call dist-for-goals,apps_only, $(apps_only_dist_built_files)) 912 913 ifeq ($(EMMA_INSTRUMENT),true) 914 $(EMMA_META_ZIP) : $(apps_only_installed_files) 915 916 $(call dist-for-goals,apps_only, $(EMMA_META_ZIP)) 917 endif 918 919 $(PROGUARD_DICT_ZIP) : $(apps_only_installed_files) 920 $(call dist-for-goals,apps_only, $(PROGUARD_DICT_ZIP)) 921 922 $(SYMBOLS_ZIP) : $(apps_only_installed_files) 923 $(call dist-for-goals,apps_only, $(SYMBOLS_ZIP)) 924 925.PHONY: apps_only 926apps_only: $(unbundled_build_modules) 927 928droid: apps_only 929 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))) 937 938 939else # TARGET_BUILD_APPS 940 $(call dist-for-goals, droidcore, \ 941 $(INTERNAL_UPDATE_PACKAGE_TARGET) \ 942 $(INTERNAL_OTA_PACKAGE_TARGET) \ 943 $(BUILT_OTATOOLS_PACKAGE) \ 944 $(SYMBOLS_ZIP) \ 945 $(INSTALLED_FILES_FILE) \ 946 $(INSTALLED_BUILD_PROP_TARGET) \ 947 $(BUILT_TARGET_FILES_PACKAGE) \ 948 $(INSTALLED_ANDROID_INFO_TXT_TARGET) \ 949 $(INSTALLED_RAMDISK_TARGET) \ 950 ) 951 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))) 955 956 ifneq ($(ANDROID_BUILD_EMBEDDED),true) 957 ifneq ($(TARGET_BUILD_PDK),true) 958 $(call dist-for-goals, droidcore, \ 959 $(APPS_ZIP) \ 960 $(INTERNAL_EMULATOR_PACKAGE_TARGET) \ 961 $(PACKAGE_STATS_FILE) \ 962 ) 963 endif 964 endif 965 966 ifeq ($(EMMA_INSTRUMENT),true) 967 $(EMMA_META_ZIP) : $(INSTALLED_SYSTEMIMAGE) 968 969 $(call dist-for-goals, dist_files, $(EMMA_META_ZIP)) 970 endif 971 972# Building a full system-- the default is to build droidcore 973droid: droidcore dist_files 974 975endif # TARGET_BUILD_APPS 976 977.PHONY: docs 978docs: $(ALL_DOCS) 979 980.PHONY: sdk 981ALL_SDK_TARGETS := $(INTERNAL_SDK_TARGET) 982sdk: $(ALL_SDK_TARGETS) 983$(call dist-for-goals,sdk win_sdk, \ 984 $(ALL_SDK_TARGETS) \ 985 $(SYMBOLS_ZIP) \ 986 $(INSTALLED_BUILD_PROP_TARGET) \ 987) 988 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 993# some synonyms 994.PHONY: host-java target-java host-native target-native \ 995 target-java-tests target-native-tests 996host-java : java-host 997target-java : java-target 998host-native : native-host 999target-native : native-target 1000target-java-tests : java-target-tests 1001target-native-tests : native-target-tests 1002tests : host-tests target-tests 1003 1004# To catch more build breakage, check build tests modules in eng and userdebug builds. 1005ifneq ($(TARGET_BUILD_PDK),true) 1006ifneq ($(filter eng userdebug,$(TARGET_BUILD_VARIANT)),) 1007droidcore : target-tests host-tests 1008endif 1009endif 1010 1011.PHONY: lintall 1012 1013ifneq (,$(filter samplecode, $(MAKECMDGOALS))) 1014.PHONY: samplecode 1015sample_MODULES := $(sort $(call get-tagged-modules,samples)) 1016sample_APKS_DEST_PATH := $(TARGET_COMMON_OUT_ROOT)/samples 1017sample_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))))) 1021sample_ADDITIONAL_INSTALLED := \ 1022 $(filter-out $(modules_to_install) $(modules_to_check) $(ALL_PREBUILT),$(sample_MODULES)) 1023samplecode: $(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) 1027endif # samplecode in $(MAKECMDGOALS) 1028 1029.PHONY: findbugs 1030findbugs: $(INTERNAL_FINDBUGS_HTML_TARGET) $(INTERNAL_FINDBUGS_XML_TARGET) 1031 1032.PHONY: clean 1033clean: 1034 @rm -rf $(OUT_DIR)/* 1035 @echo "Entire build directory removed." 1036 1037.PHONY: clobber 1038clobber: clean 1039 1040# The rules for dataclean and installclean are defined in cleanbuild.mk. 1041 1042#xxx scrape this from ALL_MODULE_NAME_TAGS 1043.PHONY: modules 1044modules: 1045 @echo "Available sub-modules:" 1046 @echo "$(call module-names-for-tag-list,$(ALL_MODULE_TAGS))" | \ 1047 tr -s ' ' '\n' | sort -u | $(COLUMN) 1048 1049.PHONY: showcommands 1050showcommands: 1051 @echo >/dev/null 1052 1053.PHONY: nothing 1054nothing: 1055 @echo Successfully read the makefiles. 1056