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