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