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