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