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