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