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