main.mk revision 0694eabe4de8231932a559498ee7784568794f81
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 probles 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 incrementaljavac 238 239.PHONY: incrementaljavac 240incrementaljavac: ; 241 242# WARNING: 243# ENABLE_INCREMENTALJAVAC should NOT be enabled by default, because change of 244# a Java source file won't trigger rebuild of its dependent Java files. 245# You can only enable it by adding "incrementaljavac" to your make command line. 246# You are responsible for the correctness of the incremental build. 247# This may decrease incremental build time dramatically for large Java libraries, 248# such as core.jar, framework.jar, etc. 249ENABLE_INCREMENTALJAVAC := 250ifneq (,$(filter incrementaljavac, $(MAKECMDGOALS))) 251ENABLE_INCREMENTALJAVAC := true 252MAKECMDGOALS := $(filter-out incrementaljavac, $(MAKECMDGOALS)) 253endif 254 255# EMMA_INSTRUMENT_STATIC merges the static emma library to each emma-enabled module. 256ifeq (true,$(EMMA_INSTRUMENT_STATIC)) 257EMMA_INSTRUMENT := true 258endif 259 260# Bring in standard build system definitions. 261include $(BUILD_SYSTEM)/definitions.mk 262 263# Bring in dex_preopt.mk 264include $(BUILD_SYSTEM)/dex_preopt.mk 265 266ifneq ($(filter user userdebug eng,$(MAKECMDGOALS)),) 267$(info ***************************************************************) 268$(info ***************************************************************) 269$(info Do not pass '$(filter user userdebug eng,$(MAKECMDGOALS))' on \ 270 the make command line.) 271$(info Set TARGET_BUILD_VARIANT in buildspec.mk, or use lunch or) 272$(info choosecombo.) 273$(info ***************************************************************) 274$(info ***************************************************************) 275$(error stopping) 276endif 277 278ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),) 279$(info ***************************************************************) 280$(info ***************************************************************) 281$(info Invalid variant: $(TARGET_BUILD_VARIANT)) 282$(info Valid values are: $(INTERNAL_VALID_VARIANTS)) 283$(info ***************************************************************) 284$(info ***************************************************************) 285$(error stopping) 286endif 287 288# ----------------------------------------------------------------- 289# Variable to check java support level inside PDK build. 290# Not necessary if the components is not in PDK. 291# not defined : not supported 292# "sdk" : sdk API only 293# "platform" : platform API supproted 294TARGET_BUILD_JAVA_SUPPORT_LEVEL := platform 295 296# ----------------------------------------------------------------- 297# The pdk (Platform Development Kit) build 298include build/core/pdk_config.mk 299 300# ----------------------------------------------------------------- 301### 302### In this section we set up the things that are different 303### between the build variants 304### 305 306is_sdk_build := 307 308ifneq ($(filter sdk win_sdk sdk_addon,$(MAKECMDGOALS)),) 309is_sdk_build := true 310endif 311 312# Add build properties for ART. These define system properties used by installd 313# to pass flags to dex2oat. 314ADDITIONAL_BUILD_PROPERTIES += persist.sys.dalvik.vm.lib.2=libart 315ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).variant=$(DEX2OAT_TARGET_CPU_VARIANT) 316ifneq ($(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),) 317 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).features=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) 318endif 319 320ifdef TARGET_2ND_ARCH 321 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).variant=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT) 322 ifneq ($($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),) 323 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).features=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) 324 endif 325endif 326 327## user/userdebug ## 328 329user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT)) 330enable_target_debugging := true 331tags_to_install := 332ifneq (,$(user_variant)) 333 # Target is secure in user builds. 334 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1 335 336 ifeq ($(user_variant),userdebug) 337 # Pick up some extra useful tools 338 tags_to_install += debug 339 else 340 # Disable debugging in plain user builds. 341 enable_target_debugging := 342 endif 343 344 # Turn on Dalvik preoptimization for user builds, but only if not 345 # explicitly disabled and the build is running on Linux (since host 346 # Dalvik isn't built for non-Linux hosts). 347 ifeq (,$(WITH_DEXPREOPT)) 348 ifeq ($(user_variant),user) 349 ifeq ($(HOST_OS),linux) 350 # TODO: turn on WITH_DEXPREOPT for libart user builds. 351 # WITH_DEXPREOPT := true 352 endif 353 endif 354 endif 355 356 # Disallow mock locations by default for user builds 357 ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0 358 359else # !user_variant 360 # Turn on checkjni for non-user builds. 361 ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1 362 # Set device insecure for non-user builds. 363 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0 364 # Allow mock locations by default for non user builds 365 ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1 366endif # !user_variant 367 368ifeq (true,$(strip $(enable_target_debugging))) 369 # Target is more debuggable and adbd is on by default 370 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 371 # Enable Dalvik lock contention logging. 372 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500 373 # Include the debugging/testing OTA keys in this build. 374 INCLUDE_TEST_OTA_KEYS := true 375else # !enable_target_debugging 376 # Target is less debuggable and adbd is off by default 377 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 378endif # !enable_target_debugging 379 380## eng ## 381 382ifeq ($(TARGET_BUILD_VARIANT),eng) 383tags_to_install := debug eng 384ifneq ($(filter ro.setupwizard.mode=ENABLED, $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))),) 385 # Don't require the setup wizard on eng builds 386 ADDITIONAL_BUILD_PROPERTIES := $(filter-out ro.setupwizard.mode=%,\ 387 $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))) \ 388 ro.setupwizard.mode=OPTIONAL 389endif 390ifndef is_sdk_build 391 # Don't even verify the image on eng builds to speed startup 392 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.image-dex2oat-filter=verify-none 393 # Don't compile apps on eng builds to speed startup 394 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dex2oat-filter=interpret-only 395endif 396 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.usejit=true 397endif 398 399## sdk ## 400 401ifdef is_sdk_build 402 403# Detect if we want to build a repository for the SDK 404sdk_repo_goal := $(strip $(filter sdk_repo,$(MAKECMDGOALS))) 405MAKECMDGOALS := $(strip $(filter-out sdk_repo,$(MAKECMDGOALS))) 406 407ifneq ($(words $(filter-out $(INTERNAL_MODIFIER_TARGETS) checkbuild emulator_tests target-files-package,$(MAKECMDGOALS))),1) 408$(error The 'sdk' target may not be specified with any other targets) 409endif 410 411# TODO: this should be eng I think. Since the sdk is built from the eng 412# variant. 413tags_to_install := debug eng 414ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true 415ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes 416else # !sdk 417endif 418 419BUILD_WITHOUT_PV := true 420 421ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android 422 423# enable vm tracing in files for now to help track 424# the cause of ANRs in the content process 425ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.stack-trace-file=/data/anr/traces.txt 426 427# ------------------------------------------------------------ 428# Define a function that, given a list of module tags, returns 429# non-empty if that module should be installed in /system. 430 431# For most goals, anything not tagged with the "tests" tag should 432# be installed in /system. 433define should-install-to-system 434$(if $(filter tests,$(1)),,true) 435endef 436 437ifdef is_sdk_build 438# For the sdk goal, anything with the "samples" tag should be 439# installed in /data even if that module also has "eng"/"debug"/"user". 440define should-install-to-system 441$(if $(filter samples tests,$(1)),,true) 442endef 443endif 444 445 446# If they only used the modifier goals (showcommands, etc), we'll actually 447# build the default target. 448ifeq ($(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS)),) 449.PHONY: $(INTERNAL_MODIFIER_TARGETS) 450$(INTERNAL_MODIFIER_TARGETS): $(DEFAULT_GOAL) 451endif 452 453# Bring in all modules that need to be built. 454ifeq ($(HOST_OS),windows) 455SDK_ONLY := true 456endif 457 458ifeq ($(SDK_ONLY),true) 459include $(TOPDIR)sdk/build/windows_sdk_whitelist.mk 460include $(TOPDIR)development/build/windows_sdk_whitelist.mk 461 462# Exclude tools/acp when cross-compiling windows under linux 463ifeq ($(findstring Linux,$(UNAME)),) 464subdirs += build/tools/acp 465endif 466 467else # !SDK_ONLY 468# 469# Typical build; include any Android.mk files we can find. 470# 471subdirs := $(TOP) 472 473FULL_BUILD := true 474 475endif # !SDK_ONLY 476 477# Before we go and include all of the module makefiles, stash away 478# the PRODUCT_* values so that later we can verify they are not modified. 479stash_product_vars:=true 480ifeq ($(stash_product_vars),true) 481 $(call stash-product-vars, __STASHED) 482endif 483 484ifneq ($(ONE_SHOT_MAKEFILE),) 485# We've probably been invoked by the "mm" shell function 486# with a subdirectory's makefile. 487include $(ONE_SHOT_MAKEFILE) 488# Change CUSTOM_MODULES to include only modules that were 489# defined by this makefile; this will install all of those 490# modules as a side-effect. Do this after including ONE_SHOT_MAKEFILE 491# so that the modules will be installed in the same place they 492# would have been with a normal make. 493CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS))) 494FULL_BUILD := 495# Stub out the notice targets, which probably aren't defined 496# when using ONE_SHOT_MAKEFILE. 497NOTICE-HOST-%: ; 498NOTICE-TARGET-%: ; 499 500# A helper goal printing out install paths 501.PHONY: GET-INSTALL-PATH 502GET-INSTALL-PATH: 503 @$(foreach m, $(ALL_MODULES), $(if $(ALL_MODULES.$(m).INSTALLED), \ 504 echo 'INSTALL-PATH: $(m) $(ALL_MODULES.$(m).INSTALLED)';)) 505 506else # ONE_SHOT_MAKEFILE 507 508ifneq ($(dont_bother),true) 509# 510# Include all of the makefiles in the system 511# 512 513# Can't use first-makefiles-under here because 514# --mindepth=2 makes the prunes not work. 515subdir_makefiles := \ 516 $(shell build/tools/findleaves.py --prune=$(OUT_DIR) --prune=.repo --prune=.git $(subdirs) Android.mk) 517 518$(foreach mk, $(subdir_makefiles), $(info including $(mk) ...)$(eval include $(mk))) 519 520endif # dont_bother 521 522endif # ONE_SHOT_MAKEFILE 523 524# Now with all Android.mks loaded we can do post cleaning steps. 525include $(BUILD_SYSTEM)/post_clean.mk 526 527ifeq ($(stash_product_vars),true) 528 $(call assert-product-vars, __STASHED) 529endif 530 531include $(BUILD_SYSTEM)/legacy_prebuilts.mk 532ifneq ($(filter-out $(GRANDFATHERED_ALL_PREBUILT),$(strip $(notdir $(ALL_PREBUILT)))),) 533 $(warning *** Some files have been added to ALL_PREBUILT.) 534 $(warning *) 535 $(warning * ALL_PREBUILT is a deprecated mechanism that) 536 $(warning * should not be used for new files.) 537 $(warning * As an alternative, use PRODUCT_COPY_FILES in) 538 $(warning * the appropriate product definition.) 539 $(warning * build/target/product/core.mk is the product) 540 $(warning * definition used in all products.) 541 $(warning *) 542 $(foreach bad_prebuilt,$(filter-out $(GRANDFATHERED_ALL_PREBUILT),$(strip $(notdir $(ALL_PREBUILT)))),$(warning * unexpected $(bad_prebuilt) in ALL_PREBUILT)) 543 $(warning *) 544 $(error ALL_PREBUILT contains unexpected files) 545endif 546 547# ------------------------------------------------------------------- 548# All module makefiles have been included at this point. 549# ------------------------------------------------------------------- 550 551 552# ------------------------------------------------------------------- 553# Fix up CUSTOM_MODULES to refer to installed files rather than 554# just bare module names. Leave unknown modules alone in case 555# they're actually full paths to a particular file. 556known_custom_modules := $(filter $(ALL_MODULES),$(CUSTOM_MODULES)) 557unknown_custom_modules := $(filter-out $(ALL_MODULES),$(CUSTOM_MODULES)) 558CUSTOM_MODULES := \ 559 $(call module-installed-files,$(known_custom_modules)) \ 560 $(unknown_custom_modules) 561 562# ------------------------------------------------------------------- 563# Define dependencies for modules that require other modules. 564# This can only happen now, after we've read in all module makefiles. 565# 566# TODO: deal with the fact that a bare module name isn't 567# unambiguous enough. Maybe declare short targets like 568# APPS:Quake or HOST:SHARED_LIBRARIES:libutils. 569# BUG: the system image won't know to depend on modules that are 570# brought in as requirements of other modules. 571# 572# Resolve the required module name to 32-bit or 64-bit variant. 573# Get a list of corresponding 32-bit module names, if one exists. 574define get-32-bit-modules 575$(strip $(foreach m,$(1),\ 576 $(if $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS),\ 577 $(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX)))) 578endef 579# Get a list of corresponding 32-bit module names, if one exists; 580# otherwise return the original module name 581define get-32-bit-modules-if-we-can 582$(strip $(foreach m,$(1),\ 583 $(if $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS),\ 584 $(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX), 585 $(m)))) 586endef 587 588# If a module is built for 32-bit, the required modules must be 32-bit too; 589# Otherwise if the module is an exectuable or shared library, 590# the required modules must be 64-bit; 591# otherwise we require both 64-bit and 32-bit variant, if one exists. 592$(foreach m,$(ALL_MODULES),\ 593 $(eval r := $(ALL_MODULES.$(m).REQUIRED))\ 594 $(if $(r),\ 595 $(if $(ALL_MODULES.$(m).FOR_2ND_ARCH),\ 596 $(eval r_r := $(call get-32-bit-modules-if-we-can,$(r))),\ 597 $(if $(filter EXECUTABLES SHARED_LIBRARIES,$(ALL_MODULES.$(m).CLASS)),\ 598 $(eval r_r := $(r)),\ 599 $(eval r_r := $(r) $(call get-32-bit-modules,$(r)))\ 600 )\ 601 )\ 602 $(eval ALL_MODULES.$(m).REQUIRED := $(strip $(r_r)))\ 603 )\ 604) 605r_r := 606 607define add-required-deps 608$(1): | $(2) 609endef 610 611$(foreach m,$(ALL_MODULES), \ 612 $(eval r := $(ALL_MODULES.$(m).REQUIRED)) \ 613 $(if $(r), \ 614 $(eval r := $(call module-installed-files,$(r))) \ 615 $(eval t_m := $(filter $(TARGET_OUT_ROOT)/%, $(ALL_MODULES.$(m).INSTALLED))) \ 616 $(eval h_m := $(filter $(HOST_OUT_ROOT)/%, $(ALL_MODULES.$(m).INSTALLED))) \ 617 $(eval t_r := $(filter $(TARGET_OUT_ROOT)/%, $(r))) \ 618 $(eval h_r := $(filter $(HOST_OUT_ROOT)/%, $(r))) \ 619 $(eval t_m := $(filter-out $(t_r), $(t_m))) \ 620 $(eval h_m := $(filter-out $(h_r), $(h_m))) \ 621 $(if $(t_m), $(eval $(call add-required-deps, $(t_m),$(t_r)))) \ 622 $(if $(h_m), $(eval $(call add-required-deps, $(h_m),$(h_r)))) \ 623 ) \ 624 ) 625 626t_m := 627h_m := 628t_r := 629h_r := 630 631# Establish the dependecies on the shared libraries. 632# It also adds the shared library module names to ALL_MODULES.$(m).REQUIRED, 633# so they can be expanded to product_MODULES later. 634# $(1): TARGET_ or HOST_. 635# $(2): non-empty for 2nd arch. 636define resolve-shared-libs-depes 637$(foreach m,$($(if $(2),$($(1)2ND_ARCH_VAR_PREFIX))$(1)DEPENDENCIES_ON_SHARED_LIBRARIES),\ 638 $(eval p := $(subst :,$(space),$(m)))\ 639 $(eval mod := $(firstword $(p)))\ 640 $(eval deps := $(subst $(comma),$(space),$(lastword $(p))))\ 641 $(if $(2),$(eval deps := $(addsuffix $($(1)2ND_ARCH_MODULE_SUFFIX),$(deps))))\ 642 $(eval r := $(filter $($(1)OUT_ROOT)/%,$(call module-installed-files,\ 643 $(deps))))\ 644 $(eval $(call add-required-deps,$(word 2,$(p)),$(r)))\ 645 $(eval ALL_MODULES.$(mod).REQUIRED += $(deps))) 646endef 647 648$(call resolve-shared-libs-depes,TARGET_) 649ifdef TARGET_2ND_ARCH 650$(call resolve-shared-libs-depes,TARGET_,true) 651endif 652$(call resolve-shared-libs-depes,HOST_) 653ifdef HOST_2ND_ARCH 654$(call resolve-shared-libs-depes,HOST_,true) 655endif 656 657m := 658r := 659p := 660deps := 661add-required-deps := 662 663# ------------------------------------------------------------------- 664# Figure out our module sets. 665# 666# Of the modules defined by the component makefiles, 667# determine what we actually want to build. 668 669########################################################### 670## Expand a module name list with REQUIRED modules 671########################################################### 672# $(1): The variable name that holds the initial module name list. 673# the variable will be modified to hold the expanded results. 674# $(2): The initial module name list. 675# Returns empty string (maybe with some whitespaces). 676define expand-required-modules 677$(eval _erm_new_modules := $(sort $(filter-out $($(1)),\ 678 $(foreach m,$(2),$(ALL_MODULES.$(m).REQUIRED)))))\ 679$(if $(_erm_new_modules),$(eval $(1) += $(_erm_new_modules))\ 680 $(call expand-required-modules,$(1),$(_erm_new_modules))) 681endef 682 683ifdef FULL_BUILD 684 # The base list of modules to build for this product is specified 685 # by the appropriate product definition file, which was included 686 # by product_config.mk. 687 product_MODULES := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES) 688 # Filter out the overridden packages before doing expansion 689 product_MODULES := $(filter-out $(foreach p, $(product_MODULES), \ 690 $(PACKAGES.$(p).OVERRIDES)), $(product_MODULES)) 691 692 # Resolve the :32 :64 module name 693 modules_32 := $(patsubst %:32,%,$(filter %:32, $(product_MODULES))) 694 modules_64 := $(patsubst %:64,%,$(filter %:64, $(product_MODULES))) 695 modules_rest := $(filter-out %:32 %:64,$(product_MODULES)) 696 # Note for 32-bit product, $(modules_32) and $(modules_64) will be 697 # added as their original module names. 698 product_MODULES := $(call get-32-bit-modules-if-we-can, $(modules_32)) 699 product_MODULES += $(modules_64) 700 # For the rest we add both 701 product_MODULES += $(call get-32-bit-modules, $(modules_rest)) 702 product_MODULES += $(modules_rest) 703 704 $(call expand-required-modules,product_MODULES,$(product_MODULES)) 705 706 product_FILES := $(call module-installed-files, $(product_MODULES)) 707 ifeq (0,1) 708 $(info product_FILES for $(TARGET_DEVICE) ($(INTERNAL_PRODUCT)):) 709 $(foreach p,$(product_FILES),$(info : $(p))) 710 $(error done) 711 endif 712else 713 # We're not doing a full build, and are probably only including 714 # a subset of the module makefiles. Don't try to build any modules 715 # requested by the product, because we probably won't have rules 716 # to build them. 717 product_FILES := 718endif 719 720eng_MODULES := $(sort \ 721 $(call get-tagged-modules,eng) \ 722 $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_ENG)) \ 723 ) 724debug_MODULES := $(sort \ 725 $(call get-tagged-modules,debug) \ 726 $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_DEBUG)) \ 727 ) 728tests_MODULES := $(sort \ 729 $(call get-tagged-modules,tests) \ 730 $(call module-installed-files, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_TESTS)) \ 731 ) 732 733# TODO: Remove the 3 places in the tree that use ALL_DEFAULT_INSTALLED_MODULES 734# and get rid of it from this list. 735modules_to_install := $(sort \ 736 $(ALL_DEFAULT_INSTALLED_MODULES) \ 737 $(product_FILES) \ 738 $(foreach tag,$(tags_to_install),$($(tag)_MODULES)) \ 739 $(CUSTOM_MODULES) \ 740 ) 741 742# Some packages may override others using LOCAL_OVERRIDES_PACKAGES. 743# Filter out (do not install) any overridden packages. 744overridden_packages := $(call get-package-overrides,$(modules_to_install)) 745ifdef overridden_packages 746# old_modules_to_install := $(modules_to_install) 747 modules_to_install := \ 748 $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \ 749 $(modules_to_install)) 750endif 751#$(error filtered out 752# $(filter-out $(modules_to_install),$(old_modules_to_install))) 753 754# Don't include any GNU targets in the SDK. It's ok (and necessary) 755# to build the host tools, but nothing that's going to be installed 756# on the target (including static libraries). 757ifdef is_sdk_build 758 target_gnu_MODULES := \ 759 $(filter \ 760 $(TARGET_OUT_INTERMEDIATES)/% \ 761 $(TARGET_OUT)/% \ 762 $(TARGET_OUT_DATA)/%, \ 763 $(sort $(call get-tagged-modules,gnu))) 764 $(info Removing from sdk:)$(foreach d,$(target_gnu_MODULES),$(info : $(d))) 765 modules_to_install := \ 766 $(filter-out $(target_gnu_MODULES),$(modules_to_install)) 767 768 # Ensure every module listed in PRODUCT_PACKAGES* gets something installed 769 # TODO: Should we do this for all builds and not just the sdk? 770 dangling_modules := 771 $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES), \ 772 $(if $(strip $(ALL_MODULES.$(m).INSTALLED) $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).INSTALLED)),,\ 773 $(eval dangling_modules += $(m)))) 774 ifneq ($(dangling_modules),) 775 $(warning: Modules '$(dangling_modules)' in PRODUCT_PACKAGES have nothing to install!) 776 endif 777 $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_DEBUG), \ 778 $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\ 779 $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_DEBUG has nothing to install!))) 780 $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_ENG), \ 781 $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\ 782 $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_ENG has nothing to install!))) 783 $(foreach m, $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES_TESTS), \ 784 $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\ 785 $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_TESTS has nothing to install!))) 786endif 787 788# build/core/Makefile contains extra stuff that we don't want to pollute this 789# top-level makefile with. It expects that ALL_DEFAULT_INSTALLED_MODULES 790# contains everything that's built during the current make, but it also further 791# extends ALL_DEFAULT_INSTALLED_MODULES. 792ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_install) 793include $(BUILD_SYSTEM)/Makefile 794modules_to_install := $(sort $(ALL_DEFAULT_INSTALLED_MODULES)) 795ALL_DEFAULT_INSTALLED_MODULES := 796 797 798# These are additional goals that we build, in order to make sure that there 799# is as little code as possible in the tree that doesn't build. 800modules_to_check := $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).CHECKED)) 801 802# If you would like to build all goals, and not skip any intermediate 803# steps, you can pass the "all" modifier goal on the commandline. 804ifneq ($(filter all,$(MAKECMDGOALS)),) 805modules_to_check += $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).BUILT)) 806endif 807 808# for easier debugging 809modules_to_check := $(sort $(modules_to_check)) 810#$(error modules_to_check $(modules_to_check)) 811 812# ------------------------------------------------------------------- 813# This is used to to get the ordering right, you can also use these, 814# but they're considered undocumented, so don't complain if their 815# behavior changes. 816.PHONY: prebuilt 817prebuilt: $(ALL_PREBUILT) 818 819# An internal target that depends on all copied headers 820# (see copy_headers.make). Other targets that need the 821# headers to be copied first can depend on this target. 822.PHONY: all_copied_headers 823all_copied_headers: ; 824 825$(ALL_C_CPP_ETC_OBJECTS): | all_copied_headers 826 827# All the droid stuff, in directories 828.PHONY: files 829files: prebuilt \ 830 $(modules_to_install) \ 831 $(INSTALLED_ANDROID_INFO_TXT_TARGET) 832 833# ------------------------------------------------------------------- 834 835.PHONY: checkbuild 836checkbuild: $(modules_to_check) 837ifeq (true,$(ANDROID_BUILD_EVERYTHING_BY_DEFAULT)$(filter $(MAKECMDGOALS),checkbuild)) 838droid: checkbuild 839else 840# ANDROID_BUILD_EVERYTHING_BY_DEFAULT not set, or checkbuild is one of the cmd goals. 841checkbuild: droid 842endif 843 844.PHONY: ramdisk 845ramdisk: $(INSTALLED_RAMDISK_TARGET) 846 847.PHONY: systemtarball 848systemtarball: $(INSTALLED_SYSTEMTARBALL_TARGET) 849 850.PHONY: boottarball 851boottarball: $(INSTALLED_BOOTTARBALL_TARGET) 852 853.PHONY: userdataimage 854userdataimage: $(INSTALLED_USERDATAIMAGE_TARGET) 855 856ifneq (,$(filter userdataimage, $(MAKECMDGOALS))) 857$(call dist-for-goals, userdataimage, $(BUILT_USERDATAIMAGE_TARGET)) 858endif 859 860.PHONY: userdatatarball 861userdatatarball: $(INSTALLED_USERDATATARBALL_TARGET) 862 863.PHONY: cacheimage 864cacheimage: $(INSTALLED_CACHEIMAGE_TARGET) 865 866.PHONY: vendorimage 867vendorimage: $(INSTALLED_VENDORIMAGE_TARGET) 868 869.PHONY: bootimage 870bootimage: $(INSTALLED_BOOTIMAGE_TARGET) 871 872# phony target that include any targets in $(ALL_MODULES) 873.PHONY: all_modules 874ifndef BUILD_MODULES_IN_PATHS 875all_modules: $(ALL_MODULES) 876else 877# BUILD_MODULES_IN_PATHS is a list of paths relative to the top of the tree 878module_path_patterns := $(foreach p, $(BUILD_MODULES_IN_PATHS),\ 879 $(if $(filter %/,$(p)),$(p)%,$(p)/%)) 880my_all_modules := $(sort $(foreach m, $(ALL_MODULES),$(if $(filter\ 881 $(module_path_patterns), $(addsuffix /,$(ALL_MODULES.$(m).PATH))),$(m)))) 882all_modules: $(my_all_modules) 883endif 884 885 886# Build files and then package it into the rom formats 887.PHONY: droidcore 888droidcore: files \ 889 systemimage \ 890 $(INSTALLED_BOOTIMAGE_TARGET) \ 891 $(INSTALLED_RECOVERYIMAGE_TARGET) \ 892 $(INSTALLED_USERDATAIMAGE_TARGET) \ 893 $(INSTALLED_CACHEIMAGE_TARGET) \ 894 $(INSTALLED_VENDORIMAGE_TARGET) \ 895 $(INSTALLED_FILES_FILE) 896 897# dist_files only for putting your library into the dist directory with a full build. 898.PHONY: dist_files 899 900ifneq ($(TARGET_BUILD_APPS),) 901 # If this build is just for apps, only build apps and not the full system by default. 902 903 unbundled_build_modules := 904 ifneq ($(filter all,$(TARGET_BUILD_APPS)),) 905 # If they used the magic goal "all" then build all apps in the source tree. 906 unbundled_build_modules := $(foreach m,$(sort $(ALL_MODULES)),$(if $(filter APPS,$(ALL_MODULES.$(m).CLASS)),$(m))) 907 else 908 unbundled_build_modules := $(TARGET_BUILD_APPS) 909 endif 910 911 # Dist the installed files if they exist. 912 apps_only_installed_files := $(foreach m,$(unbundled_build_modules),$(ALL_MODULES.$(m).INSTALLED)) 913 $(call dist-for-goals,apps_only, $(apps_only_installed_files)) 914 # For uninstallable modules such as static Java library, we have to dist the built file, 915 # as <module_name>.<suffix> 916 apps_only_dist_built_files := $(foreach m,$(unbundled_build_modules),$(if $(ALL_MODULES.$(m).INSTALLED),,\ 917 $(if $(ALL_MODULES.$(m).BUILT),$(ALL_MODULES.$(m).BUILT):$(m)$(suffix $(ALL_MODULES.$(m).BUILT)))\ 918 $(if $(ALL_MODULES.$(m).AAR),$(ALL_MODULES.$(m).AAR):$(m).aar)\ 919 )) 920 $(call dist-for-goals,apps_only, $(apps_only_dist_built_files)) 921 922 ifeq ($(EMMA_INSTRUMENT),true) 923 $(EMMA_META_ZIP) : $(apps_only_installed_files) 924 925 $(call dist-for-goals,apps_only, $(EMMA_META_ZIP)) 926 endif 927 928 $(PROGUARD_DICT_ZIP) : $(apps_only_installed_files) 929 $(call dist-for-goals,apps_only, $(PROGUARD_DICT_ZIP)) 930 931 $(SYMBOLS_ZIP) : $(apps_only_installed_files) 932 $(call dist-for-goals,apps_only, $(SYMBOLS_ZIP)) 933 934.PHONY: apps_only 935apps_only: $(unbundled_build_modules) 936 937droid: apps_only 938 939# Combine the NOTICE files for a apps_only build 940$(eval $(call combine-notice-files, \ 941 $(target_notice_file_txt), \ 942 $(target_notice_file_html), \ 943 "Notices for files for apps:", \ 944 $(TARGET_OUT_NOTICE_FILES), \ 945 $(apps_only_installed_files))) 946 947 948else # TARGET_BUILD_APPS 949 $(call dist-for-goals, droidcore, \ 950 $(INTERNAL_UPDATE_PACKAGE_TARGET) \ 951 $(INTERNAL_OTA_PACKAGE_TARGET) \ 952 $(SYMBOLS_ZIP) \ 953 $(INSTALLED_FILES_FILE) \ 954 $(INSTALLED_BUILD_PROP_TARGET) \ 955 $(BUILT_TARGET_FILES_PACKAGE) \ 956 $(INSTALLED_ANDROID_INFO_TXT_TARGET) \ 957 $(INSTALLED_RAMDISK_TARGET) \ 958 ) 959 960 # Put a copy of the radio/bootloader files in the dist dir. 961 $(foreach f,$(INSTALLED_RADIOIMAGE_TARGET), \ 962 $(call dist-for-goals, droidcore, $(f))) 963 964 ifneq ($(ANDROID_BUILD_EMBEDDED),true) 965 ifneq ($(TARGET_BUILD_PDK),true) 966 $(call dist-for-goals, droidcore, \ 967 $(APPS_ZIP) \ 968 $(INTERNAL_EMULATOR_PACKAGE_TARGET) \ 969 $(PACKAGE_STATS_FILE) \ 970 ) 971 endif 972 endif 973 974 ifeq ($(EMMA_INSTRUMENT),true) 975 $(EMMA_META_ZIP) : $(INSTALLED_SYSTEMIMAGE) 976 977 $(call dist-for-goals, dist_files, $(EMMA_META_ZIP)) 978 endif 979 980# Building a full system-- the default is to build droidcore 981droid: droidcore dist_files 982 983endif # TARGET_BUILD_APPS 984 985.PHONY: docs 986docs: $(ALL_DOCS) 987 988.PHONY: sdk 989ALL_SDK_TARGETS := $(INTERNAL_SDK_TARGET) 990sdk: $(ALL_SDK_TARGETS) 991$(call dist-for-goals,sdk win_sdk, \ 992 $(ALL_SDK_TARGETS) \ 993 $(SYMBOLS_ZIP) \ 994 $(INSTALLED_BUILD_PROP_TARGET) \ 995) 996 997# umbrella targets to assit engineers in verifying builds 998.PHONY: java native target host java-host java-target native-host native-target \ 999 java-host-tests java-target-tests native-host-tests native-target-tests \ 1000 java-tests native-tests host-tests target-tests tests 1001# some synonyms 1002.PHONY: host-java target-java host-native target-native \ 1003 target-java-tests target-native-tests 1004host-java : java-host 1005target-java : java-target 1006host-native : native-host 1007target-native : native-target 1008target-java-tests : java-target-tests 1009target-native-tests : native-target-tests 1010tests : host-tests target-tests 1011 1012# To catch more build breakage, check build tests modules in eng and userdebug builds. 1013ifneq ($(TARGET_BUILD_PDK),true) 1014ifneq ($(filter eng userdebug,$(TARGET_BUILD_VARIANT)),) 1015droidcore : target-tests host-tests 1016endif 1017endif 1018 1019.PHONY: lintall 1020 1021ifneq (,$(filter samplecode, $(MAKECMDGOALS))) 1022.PHONY: samplecode 1023sample_MODULES := $(sort $(call get-tagged-modules,samples)) 1024sample_APKS_DEST_PATH := $(TARGET_COMMON_OUT_ROOT)/samples 1025sample_APKS_COLLECTION := \ 1026 $(foreach module,$(sample_MODULES),$(sample_APKS_DEST_PATH)/$(notdir $(module))) 1027$(foreach module,$(sample_MODULES),$(eval $(call \ 1028 copy-one-file,$(module),$(sample_APKS_DEST_PATH)/$(notdir $(module))))) 1029sample_ADDITIONAL_INSTALLED := \ 1030 $(filter-out $(modules_to_install) $(modules_to_check) $(ALL_PREBUILT),$(sample_MODULES)) 1031samplecode: $(sample_APKS_COLLECTION) 1032 @echo "Collect sample code apks: $^" 1033 # remove apks that are not intended to be installed. 1034 rm -f $(sample_ADDITIONAL_INSTALLED) 1035endif # samplecode in $(MAKECMDGOALS) 1036 1037.PHONY: findbugs 1038findbugs: $(INTERNAL_FINDBUGS_HTML_TARGET) $(INTERNAL_FINDBUGS_XML_TARGET) 1039 1040.PHONY: clean 1041clean: 1042 @rm -rf $(OUT_DIR)/* 1043 @echo "Entire build directory removed." 1044 1045.PHONY: clobber 1046clobber: clean 1047 1048# The rules for dataclean and installclean are defined in cleanbuild.mk. 1049 1050#xxx scrape this from ALL_MODULE_NAME_TAGS 1051.PHONY: modules 1052modules: 1053 @echo "Available sub-modules:" 1054 @echo "$(call module-names-for-tag-list,$(ALL_MODULE_TAGS))" | \ 1055 tr -s ' ' '\n' | sort -u | $(COLUMN) 1056 1057.PHONY: showcommands 1058showcommands: 1059 @echo >/dev/null 1060 1061.PHONY: nothing 1062nothing: 1063 @echo Successfully read the makefiles. 1064