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