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