2 # Use bash, not whatever shell somebody has installed as /bin/sh
3 # This is repeated in config.mk, since envsetup.sh runs that file
7 # this turns off the suffix rules built into make
10 # If a rule fails, delete $@.
13 # Figure out where we are.
14 #TOP := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
15 #TOP := $(patsubst %/,%,$(TOP))
17 # TOPDIR is the normal variable you should use, because
18 # if we are executing relative to the current directory
19 # it can be "", whereas TOP must be "." which causes
20 # pattern matching probles when make strips off the
21 # trailing "./" from paths in various places.
28 # check for broken versions of make
29 ifeq (0,$(shell expr $$(echo $(MAKE_VERSION) | sed "s/[^0-9\.].*//") \>= 3.81))
30 $(warning ********************************************************************************)
31 $(warning * You are using version $(MAKE_VERSION) of make.)
32 $(warning * You must upgrade to version 3.81 or greater.)
33 $(warning * see file://$(shell pwd)/docs/development-environment/machine-setup.html)
34 $(warning ********************************************************************************)
41 BUILD_SYSTEM := $(TOPDIR)build/core
43 # This is the default target. It must be the first declared target.
47 # Set up various standard variables based on configuration
48 # and host information.
49 include $(BUILD_SYSTEM)/config.mk
51 # This allows us to force a clean build - included after the config.make
52 # environment setup is done, but before we generate any dependencies. This
53 # file does the rm -rf inline so the deps which are all done below will
54 # be generated correctly
55 include $(BUILD_SYSTEM)/cleanbuild.mk
57 ifneq ($(HOST_OS),windows)
58 ifneq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
59 # check for a case sensitive file system
60 ifneq (a,$(shell mkdir -p $(OUT_DIR) ; \
61 echo a > $(OUT_DIR)/casecheck.txt; \
62 echo B > $(OUT_DIR)/CaseCheck.txt; \
63 cat $(OUT_DIR)/casecheck.txt))
64 $(warning ************************************************************)
65 $(warning You are building on a case-insensitive filesystem.)
66 $(warning Please move your source tree to a case-sensitive filesystem.)
67 $(warning ************************************************************)
68 $(error Case-insensitive filesystems not supported)
73 # Make sure that there are no spaces in the absolute path; the
74 # build system can't deal with them.
75 ifneq ($(words $(shell pwd)),1)
76 $(warning ************************************************************)
77 $(warning You are building in a directory whose absolute path contains)
78 $(warning a space character:)
80 $(warning "$(shell pwd)")
82 $(warning Please move your source tree to a path that does not contain)
83 $(warning any spaces.)
84 $(warning ************************************************************)
85 $(error Directory names containing spaces not supported)
89 # The windows build server currently uses 1.6. This will be fixed.
90 ifneq ($(HOST_OS),windows)
92 # Check for the correct version of java
93 java_version := $(shell java -version 2>&1 | head -n 1 | grep '[ "]1\.5[\. "$$]')
94 ifeq ($(strip $(java_version)),)
95 $(info ************************************************************)
96 $(info You are attempting to build with the incorrect version)
99 $(info Your version is: $(shell java -version 2>&1 | head -n 1).)
100 $(info The correct version is: 1.5.)
102 $(info Please follow the machine setup instructions at)
103 $(info $(space)$(space)$(space)$(space)http://source.android.com/download)
104 $(info ************************************************************)
108 # Check for the correct version of javac
109 javac_version := $(shell javac -version 2>&1 | head -n 1 | grep '[ "]1\.5[\. "$$]')
110 ifeq ($(strip $(javac_version)),)
111 $(info ************************************************************)
112 $(info You are attempting to build with the incorrect version)
115 $(info Your version is: $(shell javac -version 2>&1 | head -n 1).)
116 $(info The correct version is: 1.5.)
118 $(info Please follow the machine setup instructions at)
119 $(info $(space)$(space)$(space)$(space)http://source.android.com/download)
120 $(info ************************************************************)
126 # These are the modifier targets that don't do anything themselves, but
127 # change the behavior of the build.
128 # (must be defined before including definitions.make)
129 INTERNAL_MODIFIER_TARGETS := showcommands checkbuild
131 # Bring in standard build system definitions.
132 include $(BUILD_SYSTEM)/definitions.mk
134 ifneq ($(filter eng user userdebug tests,$(MAKECMDGOALS)),)
135 $(info ***************************************************************)
136 $(info ***************************************************************)
137 $(info Don't pass '$(filter eng user userdebug tests,$(MAKECMDGOALS))' on \
138 the make command line.)
139 # XXX The single quote on this line fixes gvim's syntax highlighting.
140 # Without which, the rest of this file is impossible to read.
141 $(info Set TARGET_BUILD_VARIANT in buildspec.mk, or use lunch or)
143 $(info ***************************************************************)
144 $(info ***************************************************************)
148 ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),)
149 $(info ***************************************************************)
150 $(info ***************************************************************)
151 $(info Invalid variant: $(TARGET_BUILD_VARIANT)
152 $(info Valid values are: $(INTERNAL_VALID_VARIANTS)
153 $(info ***************************************************************)
154 $(info ***************************************************************)
159 ### In this section we set up the things that are different
160 ### between the build variants
164 ifneq ($(filter sdk,$(MAKECMDGOALS)),)
167 ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),)
174 user_variant := $(filter userdebug user,$(TARGET_BUILD_VARIANT))
175 enable_target_debugging := true
176 ifneq (,$(user_variant))
177 # Target is secure in user builds.
178 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
180 tags_to_install := user
181 ifeq ($(user_variant),userdebug)
182 # Pick up some extra useful tools
183 tags_to_install += debug
185 # Disable debugging in plain user builds.
186 enable_target_debugging :=
189 # TODO: Always set WITH_DEXPREOPT (for user builds) once it works on OSX.
190 # Also, remove the corresponding block in config/product_config.make.
191 ifeq ($(HOST_OS)-$(WITH_DEXPREOPT_buildbot),linux-true)
192 WITH_DEXPREOPT := true
195 # Disallow mock locations by default for user builds
196 ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0
199 # Turn on checkjni for non-user builds.
200 ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1
201 # Set device insecure for non-user builds.
202 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
203 # Allow mock locations by default for non user builds
204 ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
205 endif # !user_variant
207 ifeq (true,$(strip $(enable_target_debugging)))
208 # Target is more debuggable and adbd is on by default
209 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1
210 # Include the debugging/testing OTA keys in this build.
211 INCLUDE_TEST_OTA_KEYS := true
212 else # !enable_target_debugging
213 # Target is less debuggable and adbd is off by default
214 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0
215 endif # !enable_target_debugging
219 ifeq ($(TARGET_BUILD_VARIANT),eng)
220 tags_to_install := user debug eng
221 # Don't require the setup wizard on eng builds
222 ADDITIONAL_BUILD_PROPERTIES := $(filter-out ro.setupwizard.mode=%,\
223 $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES)))
228 ifeq ($(TARGET_BUILD_VARIANT),tests)
229 tags_to_install := user debug eng tests
235 ifneq ($(words $(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS))),1)
236 $(error The 'sdk' target may not be specified with any other targets)
238 # TODO: this should be eng I think. Since the sdk is built from the eng
240 tags_to_install := user debug eng
241 ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true
242 ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes
244 # Enable sync for non-sdk builds only (sdk builds lack SubscribedFeedsProvider).
245 ADDITIONAL_BUILD_PROPERTIES += ro.config.sync=yes
250 ifneq ($(filter dalvik.gc.type-precise,$(PRODUCT_TAGS)),)
251 # Enabling type-precise GC results in larger optimized DEX files. The
252 # additional storage requirements for ".odex" files can cause /system
253 # to overflow on some devices, so this is configured separately for
255 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dexopt-flags=m=y
258 # Install an apns-conf.xml file if one's not already being installed.
259 ifeq (,$(filter %:system/etc/apns-conf.xml, $(PRODUCT_COPY_FILES)))
260 PRODUCT_COPY_FILES += \
261 development/data/etc/apns-conf_sdk.xml:system/etc/apns-conf.xml
262 ifeq ($(filter eng tests,$(TARGET_BUILD_VARIANT)),)
263 $(warning implicitly installing apns-conf_sdk.xml)
266 # If we're on an eng or tests build, but not on the sdk, and we have
267 # a better one, use that instead.
268 ifneq ($(filter eng tests,$(TARGET_BUILD_VARIANT)),)
270 apns_to_use := $(wildcard vendor/google/etc/apns-conf.xml)
271 ifneq ($(strip $(apns_to_use)),)
272 PRODUCT_COPY_FILES := \
273 $(filter-out %:system/etc/apns-conf.xml,$(PRODUCT_COPY_FILES)) \
274 $(strip $(apns_to_use)):system/etc/apns-conf.xml
279 ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android
281 # enable vm tracing in files for now to help track
282 # the cause of ANRs in the content process
283 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.stack-trace-file=/data/anr/traces.txt
286 # ------------------------------------------------------------
287 # Define a function that, given a list of module tags, returns
288 # non-empty if that module should be installed in /system.
290 # For most goals, anything not tagged with the "tests" tag should
291 # be installed in /system.
292 define should-install-to-system
293 $(if $(filter tests,$(1)),,true)
297 # For the sdk goal, anything with the "samples" tag should be
298 # installed in /data even if that module also has "eng"/"debug"/"user".
299 define should-install-to-system
300 $(if $(filter samples tests,$(1)),,true)
305 # If they only used the modifier goals (showcommands, checkbuild), we'll actually
306 # build the default target.
307 ifeq ($(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS)),)
308 .PHONY: $(INTERNAL_MODIFIER_TARGETS)
309 $(INTERNAL_MODIFIER_TARGETS): $(DEFAULT_GOAL)
312 # These targets are going to delete stuff, don't bother including
313 # the whole directory tree if that's all we're going to do
314 ifeq ($(MAKECMDGOALS),clean)
317 ifeq ($(MAKECMDGOALS),clobber)
320 ifeq ($(MAKECMDGOALS),dataclean)
323 ifeq ($(MAKECMDGOALS),installclean)
327 # Bring in all modules that need to be built.
328 ifneq ($(dont_bother),true)
332 ifeq ($(HOST_OS),windows)
335 ifeq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
339 ifeq ($(SDK_ONLY),true)
346 dalvik/tools/dmtracedump \
347 dalvik/tools/hprof-conv \
348 development/emulator/mksdcard \
349 development/tools/line_endings \
354 external/sqlite/dist \
356 frameworks/base/libs/utils \
357 frameworks/base/tools/aapt \
358 frameworks/base/tools/aidl \
360 system/core/fastboot \
361 system/core/libcutils \
363 system/core/libzipfile
365 # The following can only be built if "javac" is available.
366 # This check is used when building parts of the SDK under Cygwin.
367 ifneq (,$(shell which javac 2>/dev/null))
368 $(warning sdk-only: javac available.)
370 build/tools/signapk \
371 build/tools/zipalign \
375 development/tools/archquery \
376 development/tools/androidprefs \
377 development/tools/apkbuilder \
378 development/tools/jarutils \
379 development/tools/layoutlib_utils \
380 development/tools/ninepatch \
381 development/tools/sdkstats \
382 development/tools/sdkmanager \
383 development/tools/mkstubs \
385 frameworks/base/tools/layoutlib \
386 external/googleclient \
389 $(warning sdk-only: javac not available.)
392 # Exclude tools/acp when cross-compiling windows under linux
393 ifeq ($(findstring Linux,$(UNAME)),)
394 subdirs += build/tools/acp
398 ifeq ($(BUILD_TINY_ANDROID), true)
400 # TINY_ANDROID is a super-minimal build configuration, handy for board
401 # bringup and very low level debugging
409 build/tools/apriori \
416 else # !BUILD_TINY_ANDROID
419 # Typical build; include any Android.mk files we can find.
425 endif # !BUILD_TINY_ANDROID
429 # Can't use first-makefiles-under here because
430 # --mindepth=2 makes the prunes not work.
431 subdir_makefiles += \
432 $(shell build/tools/findleaves.sh --prune="./out" $(subdirs) Android.mk)
435 # Include all of the makefiles in the system
438 ifneq ($(ONE_SHOT_MAKEFILE),)
439 # We've probably been invoked by the "mm" shell function
440 # with a subdirectory's makefile.
441 include $(ONE_SHOT_MAKEFILE)
442 # Change CUSTOM_MODULES to include only modules that were
443 # defined by this makefile; this will install all of those
444 # modules as a side-effect. Do this after including ONE_SHOT_MAKEFILE
445 # so that the modules will be installed in the same place they
446 # would have been with a normal make.
447 CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS),))
449 # Stub out the notice targets, which probably aren't defined
450 # when using ONE_SHOT_MAKEFILE.
454 include $(subdir_makefiles)
456 # -------------------------------------------------------------------
457 # All module makefiles have been included at this point.
458 # -------------------------------------------------------------------
460 # -------------------------------------------------------------------
461 # Include any makefiles that must happen after the module makefiles
462 # have been included.
463 # TODO: have these files register themselves via a global var rather
464 # than hard-coding the list here.
466 # Only include this during a full build, otherwise we can't be
467 # guaranteed that any policies were included.
468 -include frameworks/policies/base/PolicyConfig.mk
471 # -------------------------------------------------------------------
472 # Fix up CUSTOM_MODULES to refer to installed files rather than
473 # just bare module names. Leave unknown modules alone in case
474 # they're actually full paths to a particular file.
475 known_custom_modules := $(filter $(ALL_MODULES),$(CUSTOM_MODULES))
476 unknown_custom_modules := $(filter-out $(ALL_MODULES),$(CUSTOM_MODULES))
478 $(call module-installed-files,$(known_custom_modules)) \
479 $(unknown_custom_modules)
481 # -------------------------------------------------------------------
482 # Define dependencies for modules that require other modules.
483 # This can only happen now, after we've read in all module makefiles.
485 # TODO: deal with the fact that a bare module name isn't
486 # unambiguous enough. Maybe declare short targets like
487 # APPS:Quake or HOST:SHARED_LIBRARIES:libutils.
488 # BUG: the system image won't know to depend on modules that are
489 # brought in as requirements of other modules.
490 define add-required-deps
493 $(foreach m,$(ALL_MODULES), \
494 $(eval r := $(ALL_MODULES.$(m).REQUIRED)) \
496 $(eval r := $(call module-installed-files,$(r))) \
497 $(eval $(call add-required-deps,$(ALL_MODULES.$(m).INSTALLED),$(r))) \
504 # -------------------------------------------------------------------
505 # Figure out our module sets.
507 # Of the modules defined by the component makefiles,
508 # determine what we actually want to build.
509 # If a module has the "restricted" tag on it, it
510 # poisons the rest of the tags and shouldn't appear
512 Default_MODULES := $(sort $(ALL_DEFAULT_INSTALLED_MODULES) \
514 # TODO: Remove the 3 places in the tree that use
515 # ALL_DEFAULT_INSTALLED_MODULES and get rid of it from this list.
518 # The base list of modules to build for this product is specified
519 # by the appropriate product definition file, which was included
520 # by product_config.make.
521 user_PACKAGES := $(call module-installed-files, \
522 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES))
524 $(info user packages for $(TARGET_DEVICE) ($(INTERNAL_PRODUCT)):)
525 $(foreach p,$(user_PACKAGES),$(info : $(p)))
529 # We're not doing a full build, and are probably only including
530 # a subset of the module makefiles. Don't try to build any modules
531 # requested by the product, because we probably won't have rules
535 # Use tags to get the non-APPS user modules. Use the product
536 # definition files to get the APPS user modules.
537 user_MODULES := $(sort $(call get-tagged-modules,user,_class@APPS restricted))
538 user_MODULES := $(user_MODULES) $(user_PACKAGES)
540 eng_MODULES := $(sort $(call get-tagged-modules,eng,restricted))
541 debug_MODULES := $(sort $(call get-tagged-modules,debug,restricted))
542 tests_MODULES := $(sort $(call get-tagged-modules,tests,restricted))
544 ifeq ($(strip $(tags_to_install)),)
545 $(error ASSERTION FAILED: tags_to_install should not be empty)
547 modules_to_install := $(sort $(Default_MODULES) \
548 $(foreach tag,$(tags_to_install),$($(tag)_MODULES)))
550 # Some packages may override others using LOCAL_OVERRIDES_PACKAGES.
551 # Filter out (do not install) any overridden packages.
552 overridden_packages := $(call get-package-overrides,$(modules_to_install))
553 ifdef overridden_packages
554 # old_modules_to_install := $(modules_to_install)
555 modules_to_install := \
556 $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
557 $(modules_to_install))
559 #$(error filtered out
560 # $(filter-out $(modules_to_install),$(old_modules_to_install)))
562 # Don't include any GNU targets in the SDK. It's ok (and necessary)
563 # to build the host tools, but nothing that's going to be installed
564 # on the target (including static libraries).
566 target_gnu_MODULES := \
568 $(TARGET_OUT_INTERMEDIATES)/% \
570 $(TARGET_OUT_DATA)/%, \
571 $(sort $(call get-tagged-modules,gnu)))
572 $(info Removing from sdk:)$(foreach d,$(target_gnu_MODULES),$(info : $(d)))
573 modules_to_install := \
574 $(filter-out $(target_gnu_MODULES),$(modules_to_install))
578 # build/core/Makefile contains extra stuff that we don't want to pollute this
579 # top-level makefile with. It expects that ALL_DEFAULT_INSTALLED_MODULES
580 # contains everything that's built during the current make, but it also further
581 # extends ALL_DEFAULT_INSTALLED_MODULES.
582 ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_install)
583 include $(BUILD_SYSTEM)/Makefile
584 modules_to_install := $(sort $(ALL_DEFAULT_INSTALLED_MODULES))
585 ALL_DEFAULT_INSTALLED_MODULES :=
589 # These are additional goals that we build, in order to make sure that there
590 # is as little code as possible in the tree that doesn't build.
591 modules_to_check := $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).CHECKED))
593 # If you would like to build all goals, and not skip any intermediate
594 # steps, you can pass the "all" modifier goal on the commandline.
595 ifneq ($(filter all,$(MAKECMDGOALS)),)
596 modules_to_check += $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).BUILT))
599 # for easier debugging
600 modules_to_check := $(sort $(modules_to_check))
601 #$(error modules_to_check $(modules_to_check))
603 # -------------------------------------------------------------------
604 # This is used to to get the ordering right, you can also use these,
605 # but they're considered undocumented, so don't complain if their
608 prebuilt: $(ALL_PREBUILT)
610 # An internal target that depends on all copied headers
611 # (see copy_headers.make). Other targets that need the
612 # headers to be copied first can depend on this target.
613 .PHONY: all_copied_headers
614 all_copied_headers: ;
616 $(ALL_C_CPP_ETC_OBJECTS): | all_copied_headers
618 # All the droid stuff, in directories
621 $(modules_to_install) \
622 $(modules_to_check) \
623 $(INSTALLED_ANDROID_INFO_TXT_TARGET)
625 # -------------------------------------------------------------------
628 checkbuild: $(modules_to_check)
631 ramdisk: $(INSTALLED_RAMDISK_TARGET)
633 .PHONY: systemtarball
634 systemtarball: $(INSTALLED_SYSTEMTARBALL_TARGET)
636 .PHONY: userdataimage
637 userdataimage: $(INSTALLED_USERDATAIMAGE_TARGET)
639 .PHONY: userdatatarball
640 userdatatarball: $(INSTALLED_USERDATATARBALL_TARGET)
643 bootimage: $(INSTALLED_BOOTIMAGE_TARGET)
645 ifeq ($(BUILD_TINY_ANDROID), true)
646 INSTALLED_RECOVERYIMAGE_TARGET :=
649 # Build files and then package it into the rom formats
653 $(INSTALLED_BOOTIMAGE_TARGET) \
654 $(INSTALLED_RECOVERYIMAGE_TARGET) \
655 $(INSTALLED_USERDATAIMAGE_TARGET) \
656 $(INSTALLED_FILES_FILE)
658 # The actual files built by the droidcore target changes depending
659 # on the build variant.
661 droid tests: droidcore
663 $(call dist-for-goals, droid, \
664 $(INTERNAL_UPDATE_PACKAGE_TARGET) \
665 $(INTERNAL_OTA_PACKAGE_TARGET) \
668 $(INTERNAL_EMULATOR_PACKAGE_TARGET) \
669 $(PACKAGE_STATS_FILE) \
670 $(INSTALLED_FILES_FILE) \
671 $(INSTALLED_BUILD_PROP_TARGET) \
672 $(BUILT_TARGET_FILES_PACKAGE) \
675 # Tests are installed in userdata.img. If we're building the tests
676 # variant, copy it for "make tests dist". Also copy a zip of the
677 # contents of userdata.img, so that people can easily extract a
679 ifeq ($(TARGET_BUILD_VARIANT),tests)
680 $(call dist-for-goals, droid, \
681 $(INSTALLED_USERDATAIMAGE_TARGET) \
682 $(BUILT_TESTS_ZIP_PACKAGE) \
690 ALL_SDK_TARGETS := $(INTERNAL_SDK_TARGET)
691 sdk: $(ALL_SDK_TARGETS)
692 $(call dist-for-goals,sdk,$(ALL_SDK_TARGETS))
695 findbugs: $(INTERNAL_FINDBUGS_HTML_TARGET) $(INTERNAL_FINDBUGS_XML_TARGET)
700 $(TARGET_COMMON_OUT_ROOT) \
702 $(HOST_COMMON_OUT_ROOT)
704 @for dir in $(dirs_to_clean) ; do \
705 echo "Cleaning $$dir..."; \
713 @echo "Entire build directory removed."
715 # The rules for dataclean and installclean are defined in cleanbuild.mk.
717 #xxx scrape this from ALL_MODULE_NAME_TAGS
720 @echo "Available sub-modules:"
721 @echo "$(call module-names-for-tag-list,$(ALL_MODULE_TAGS))" | \
722 sed -e 's/ */\n/g' | sort -u | $(COLUMN)