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 VERSION_CHECK_SEQUENCE_NUMBER := 1
58 -include $(OUT_DIR)/versions_checked.mk
59 ifneq ($(VERSION_CHECK_SEQUENCE_NUMBER),$(VERSIONS_CHECKED))
61 $(info Checking build tools versions...)
63 ifneq ($(HOST_OS),windows)
64 ifneq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
65 # check for a case sensitive file system
66 ifneq (a,$(shell mkdir -p $(OUT_DIR) ; \
67 echo a > $(OUT_DIR)/casecheck.txt; \
68 echo B > $(OUT_DIR)/CaseCheck.txt; \
69 cat $(OUT_DIR)/casecheck.txt))
70 $(warning ************************************************************)
71 $(warning You are building on a case-insensitive filesystem.)
72 $(warning Please move your source tree to a case-sensitive filesystem.)
73 $(warning ************************************************************)
74 $(error Case-insensitive filesystems not supported)
79 # Make sure that there are no spaces in the absolute path; the
80 # build system can't deal with them.
81 ifneq ($(words $(shell pwd)),1)
82 $(warning ************************************************************)
83 $(warning You are building in a directory whose absolute path contains)
84 $(warning a space character:)
86 $(warning "$(shell pwd)")
88 $(warning Please move your source tree to a path that does not contain)
89 $(warning any spaces.)
90 $(warning ************************************************************)
91 $(error Directory names containing spaces not supported)
95 # The windows build server currently uses 1.6. This will be fixed.
96 ifneq ($(HOST_OS),windows)
98 # Check for the correct version of java
99 java_version := $(shell java -version 2>&1 | head -n 1 | grep '[ "]1\.5[\. "$$]')
100 ifeq ($(strip $(java_version)),)
101 $(info ************************************************************)
102 $(info You are attempting to build with the incorrect version)
105 $(info Your version is: $(shell java -version 2>&1 | head -n 1).)
106 $(info The correct version is: 1.5.)
108 $(info Please follow the machine setup instructions at)
109 $(info $(space)$(space)$(space)$(space)http://source.android.com/download)
110 $(info ************************************************************)
114 # Check for the correct version of javac
115 javac_version := $(shell javac -version 2>&1 | head -n 1 | grep '[ "]1\.5[\. "$$]')
116 ifeq ($(strip $(javac_version)),)
117 $(info ************************************************************)
118 $(info You are attempting to build with the incorrect version)
121 $(info Your version is: $(shell javac -version 2>&1 | head -n 1).)
122 $(info The correct version is: 1.5.)
124 $(info Please follow the machine setup instructions at)
125 $(info $(space)$(space)$(space)$(space)http://source.android.com/download)
126 $(info ************************************************************)
132 $(shell echo 'VERSIONS_CHECKED := $(VERSION_CHECK_SEQUENCE_NUMBER)' \
133 > $(OUT_DIR)/versions_checked.mk)
136 # These are the modifier targets that don't do anything themselves, but
137 # change the behavior of the build.
138 # (must be defined before including definitions.make)
139 INTERNAL_MODIFIER_TARGETS := showcommands checkbuild
141 # Bring in standard build system definitions.
142 include $(BUILD_SYSTEM)/definitions.mk
144 ifneq ($(filter eng user userdebug tests,$(MAKECMDGOALS)),)
145 $(info ***************************************************************)
146 $(info ***************************************************************)
147 $(info Don't pass '$(filter eng user userdebug tests,$(MAKECMDGOALS))' on \
148 the make command line.)
149 # XXX The single quote on this line fixes gvim's syntax highlighting.
150 # Without which, the rest of this file is impossible to read.
151 $(info Set TARGET_BUILD_VARIANT in buildspec.mk, or use lunch or)
153 $(info ***************************************************************)
154 $(info ***************************************************************)
158 ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),)
159 $(info ***************************************************************)
160 $(info ***************************************************************)
161 $(info Invalid variant: $(TARGET_BUILD_VARIANT)
162 $(info Valid values are: $(INTERNAL_VALID_VARIANTS)
163 $(info ***************************************************************)
164 $(info ***************************************************************)
169 ### In this section we set up the things that are different
170 ### between the build variants
174 ifneq ($(filter sdk,$(MAKECMDGOALS)),)
177 ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),)
184 user_variant := $(filter userdebug user,$(TARGET_BUILD_VARIANT))
185 enable_target_debugging := true
186 ifneq (,$(user_variant))
187 # Target is secure in user builds.
188 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
190 tags_to_install := user
191 ifeq ($(user_variant),userdebug)
192 # Pick up some extra useful tools
193 tags_to_install += debug
195 # Disable debugging in plain user builds.
196 enable_target_debugging :=
199 # TODO: Always set WITH_DEXPREOPT (for user builds) once it works on OSX.
200 # Also, remove the corresponding block in config/product_config.make.
201 ifeq ($(HOST_OS)-$(WITH_DEXPREOPT_buildbot),linux-true)
202 WITH_DEXPREOPT := true
205 # Disallow mock locations by default for user builds
206 ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0
209 # Turn on checkjni for non-user builds.
210 ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1
211 # Set device insecure for non-user builds.
212 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
213 # Allow mock locations by default for non user builds
214 ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
215 endif # !user_variant
217 ifeq (true,$(strip $(enable_target_debugging)))
218 # Target is more debuggable and adbd is on by default
219 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1
220 # Include the debugging/testing OTA keys in this build.
221 INCLUDE_TEST_OTA_KEYS := true
222 else # !enable_target_debugging
223 # Target is less debuggable and adbd is off by default
224 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0
225 endif # !enable_target_debugging
229 ifeq ($(TARGET_BUILD_VARIANT),eng)
230 tags_to_install := user debug eng
231 # Don't require the setup wizard on eng builds
232 ADDITIONAL_BUILD_PROPERTIES := $(filter-out ro.setupwizard.mode=%,\
233 $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))) \
234 ro.setupwizard.mode=OPTIONAL
239 ifeq ($(TARGET_BUILD_VARIANT),tests)
240 tags_to_install := user debug eng tests
246 ifneq ($(words $(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS))),1)
247 $(error The 'sdk' target may not be specified with any other targets)
249 # TODO: this should be eng I think. Since the sdk is built from the eng
251 tags_to_install := user debug eng
252 ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true
253 ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes
259 ifneq ($(filter dalvik.gc.type-precise,$(PRODUCT_TAGS)),)
260 # Enabling type-precise GC results in larger optimized DEX files. The
261 # additional storage requirements for ".odex" files can cause /system
262 # to overflow on some devices, so this is configured separately for
264 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dexopt-flags=m=y
267 # Install an apns-conf.xml file if one's not already being installed.
268 ifeq (,$(filter %:system/etc/apns-conf.xml, $(PRODUCT_COPY_FILES)))
269 PRODUCT_COPY_FILES += \
270 development/data/etc/apns-conf_sdk.xml:system/etc/apns-conf.xml
271 ifeq ($(filter eng tests,$(TARGET_BUILD_VARIANT)),)
272 $(warning implicitly installing apns-conf_sdk.xml)
275 # If we're on an eng or tests build, but not on the sdk, and we have
276 # a better one, use that instead.
277 ifneq ($(filter eng tests,$(TARGET_BUILD_VARIANT)),)
279 apns_to_use := $(wildcard vendor/google/etc/apns-conf.xml)
280 ifneq ($(strip $(apns_to_use)),)
281 PRODUCT_COPY_FILES := \
282 $(filter-out %:system/etc/apns-conf.xml,$(PRODUCT_COPY_FILES)) \
283 $(strip $(apns_to_use)):system/etc/apns-conf.xml
288 ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android
289 ADDITIONAL_BUILD_PROPERTIES += ro.config.sync=yes
291 # enable vm tracing in files for now to help track
292 # the cause of ANRs in the content process
293 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.stack-trace-file=/data/anr/traces.txt
296 # ------------------------------------------------------------
297 # Define a function that, given a list of module tags, returns
298 # non-empty if that module should be installed in /system.
300 # For most goals, anything not tagged with the "tests" tag should
301 # be installed in /system.
302 define should-install-to-system
303 $(if $(filter tests,$(1)),,true)
307 # For the sdk goal, anything with the "samples" tag should be
308 # installed in /data even if that module also has "eng"/"debug"/"user".
309 define should-install-to-system
310 $(if $(filter samples tests,$(1)),,true)
315 # If they only used the modifier goals (showcommands, checkbuild), we'll actually
316 # build the default target.
317 ifeq ($(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS)),)
318 .PHONY: $(INTERNAL_MODIFIER_TARGETS)
319 $(INTERNAL_MODIFIER_TARGETS): $(DEFAULT_GOAL)
322 # These targets are going to delete stuff, don't bother including
323 # the whole directory tree if that's all we're going to do
324 ifeq ($(MAKECMDGOALS),clean)
327 ifeq ($(MAKECMDGOALS),clobber)
330 ifeq ($(MAKECMDGOALS),dataclean)
333 ifeq ($(MAKECMDGOALS),installclean)
337 # Bring in all modules that need to be built.
338 ifneq ($(dont_bother),true)
340 ifeq ($(HOST_OS),windows)
343 ifeq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
347 ifeq ($(SDK_ONLY),true)
352 build/tools/zipalign \
355 dalvik/tools/dmtracedump \
356 dalvik/tools/hprof-conv \
357 development/emulator/mksdcard \
358 development/tools/line_endings \
359 development/tools/sdklauncher \
364 external/sqlite/dist \
366 frameworks/base/libs/utils \
367 frameworks/base/tools/aapt \
368 frameworks/base/tools/aidl \
370 system/core/fastboot \
371 system/core/libcutils \
373 system/core/libzipfile
375 # The following can only be built if "javac" is available.
376 # This check is used when building parts of the SDK under Cygwin.
377 ifneq (,$(shell which javac 2>/dev/null))
378 $(warning sdk-only: javac available.)
380 build/tools/signapk \
384 development/tools/archquery \
385 development/tools/androidprefs \
386 development/tools/apkbuilder \
387 development/tools/jarutils \
388 development/tools/layoutlib_utils \
389 development/tools/ninepatch \
390 development/tools/sdkstats \
391 development/tools/sdkmanager \
392 development/tools/mkstubs \
393 development/tools/layoutopt \
395 frameworks/base/tools/layoutlib \
396 external/googleclient \
399 $(warning sdk-only: javac not available.)
402 # Exclude tools/acp when cross-compiling windows under linux
403 ifeq ($(findstring Linux,$(UNAME)),)
404 subdirs += build/tools/acp
408 ifeq ($(BUILD_TINY_ANDROID), true)
410 # TINY_ANDROID is a super-minimal build configuration, handy for board
411 # bringup and very low level debugging
419 build/tools/apriori \
426 else # !BUILD_TINY_ANDROID
429 # Typical build; include any Android.mk files we can find.
435 endif # !BUILD_TINY_ANDROID
439 ifneq ($(ONE_SHOT_MAKEFILE),)
440 # We've probably been invoked by the "mm" shell function
441 # with a subdirectory's makefile.
442 include $(ONE_SHOT_MAKEFILE)
443 # Change CUSTOM_MODULES to include only modules that were
444 # defined by this makefile; this will install all of those
445 # modules as a side-effect. Do this after including ONE_SHOT_MAKEFILE
446 # so that the modules will be installed in the same place they
447 # would have been with a normal make.
448 CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS),))
450 # Stub out the notice targets, which probably aren't defined
451 # when using ONE_SHOT_MAKEFILE.
455 else # ONE_SHOT_MAKEFILE
458 # Include all of the makefiles in the system
461 # Can't use first-makefiles-under here because
462 # --mindepth=2 makes the prunes not work.
463 subdir_makefiles := \
464 $(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git $(subdirs) Android.mk)
466 include $(subdir_makefiles)
467 endif # ONE_SHOT_MAKEFILE
469 # -------------------------------------------------------------------
470 # All module makefiles have been included at this point.
471 # -------------------------------------------------------------------
473 # -------------------------------------------------------------------
474 # Include any makefiles that must happen after the module makefiles
475 # have been included.
476 # TODO: have these files register themselves via a global var rather
477 # than hard-coding the list here.
479 # Only include this during a full build, otherwise we can't be
480 # guaranteed that any policies were included.
481 -include frameworks/policies/base/PolicyConfig.mk
484 # -------------------------------------------------------------------
485 # Fix up CUSTOM_MODULES to refer to installed files rather than
486 # just bare module names. Leave unknown modules alone in case
487 # they're actually full paths to a particular file.
488 known_custom_modules := $(filter $(ALL_MODULES),$(CUSTOM_MODULES))
489 unknown_custom_modules := $(filter-out $(ALL_MODULES),$(CUSTOM_MODULES))
491 $(call module-installed-files,$(known_custom_modules)) \
492 $(unknown_custom_modules)
494 # -------------------------------------------------------------------
495 # Define dependencies for modules that require other modules.
496 # This can only happen now, after we've read in all module makefiles.
498 # TODO: deal with the fact that a bare module name isn't
499 # unambiguous enough. Maybe declare short targets like
500 # APPS:Quake or HOST:SHARED_LIBRARIES:libutils.
501 # BUG: the system image won't know to depend on modules that are
502 # brought in as requirements of other modules.
503 define add-required-deps
506 $(foreach m,$(ALL_MODULES), \
507 $(eval r := $(ALL_MODULES.$(m).REQUIRED)) \
509 $(eval r := $(call module-installed-files,$(r))) \
510 $(eval $(call add-required-deps,$(ALL_MODULES.$(m).INSTALLED),$(r))) \
517 # -------------------------------------------------------------------
518 # Figure out our module sets.
520 # Of the modules defined by the component makefiles,
521 # determine what we actually want to build.
522 # If a module has the "restricted" tag on it, it
523 # poisons the rest of the tags and shouldn't appear
525 Default_MODULES := $(sort $(ALL_DEFAULT_INSTALLED_MODULES) \
527 # TODO: Remove the 3 places in the tree that use
528 # ALL_DEFAULT_INSTALLED_MODULES and get rid of it from this list.
531 # The base list of modules to build for this product is specified
532 # by the appropriate product definition file, which was included
533 # by product_config.make.
534 user_PACKAGES := $(call module-installed-files, \
535 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES))
537 $(info user packages for $(TARGET_DEVICE) ($(INTERNAL_PRODUCT)):)
538 $(foreach p,$(user_PACKAGES),$(info : $(p)))
542 # We're not doing a full build, and are probably only including
543 # a subset of the module makefiles. Don't try to build any modules
544 # requested by the product, because we probably won't have rules
548 # Use tags to get the non-APPS user modules. Use the product
549 # definition files to get the APPS user modules.
550 user_MODULES := $(sort $(call get-tagged-modules,user,_class@APPS restricted))
551 user_MODULES := $(user_MODULES) $(user_PACKAGES)
553 eng_MODULES := $(sort $(call get-tagged-modules,eng,restricted))
554 debug_MODULES := $(sort $(call get-tagged-modules,debug,restricted))
555 tests_MODULES := $(sort $(call get-tagged-modules,tests,restricted))
557 ifeq ($(strip $(tags_to_install)),)
558 $(error ASSERTION FAILED: tags_to_install should not be empty)
560 modules_to_install := $(sort $(Default_MODULES) \
561 $(foreach tag,$(tags_to_install),$($(tag)_MODULES)))
563 # Some packages may override others using LOCAL_OVERRIDES_PACKAGES.
564 # Filter out (do not install) any overridden packages.
565 overridden_packages := $(call get-package-overrides,$(modules_to_install))
566 ifdef overridden_packages
567 # old_modules_to_install := $(modules_to_install)
568 modules_to_install := \
569 $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
570 $(modules_to_install))
572 #$(error filtered out
573 # $(filter-out $(modules_to_install),$(old_modules_to_install)))
575 # Don't include any GNU targets in the SDK. It's ok (and necessary)
576 # to build the host tools, but nothing that's going to be installed
577 # on the target (including static libraries).
579 target_gnu_MODULES := \
581 $(TARGET_OUT_INTERMEDIATES)/% \
583 $(TARGET_OUT_DATA)/%, \
584 $(sort $(call get-tagged-modules,gnu)))
585 $(info Removing from sdk:)$(foreach d,$(target_gnu_MODULES),$(info : $(d)))
586 modules_to_install := \
587 $(filter-out $(target_gnu_MODULES),$(modules_to_install))
591 # build/core/Makefile contains extra stuff that we don't want to pollute this
592 # top-level makefile with. It expects that ALL_DEFAULT_INSTALLED_MODULES
593 # contains everything that's built during the current make, but it also further
594 # extends ALL_DEFAULT_INSTALLED_MODULES.
595 ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_install)
596 include $(BUILD_SYSTEM)/Makefile
597 modules_to_install := $(sort $(ALL_DEFAULT_INSTALLED_MODULES))
598 ALL_DEFAULT_INSTALLED_MODULES :=
602 # These are additional goals that we build, in order to make sure that there
603 # is as little code as possible in the tree that doesn't build.
604 modules_to_check := $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).CHECKED))
606 # If you would like to build all goals, and not skip any intermediate
607 # steps, you can pass the "all" modifier goal on the commandline.
608 ifneq ($(filter all,$(MAKECMDGOALS)),)
609 modules_to_check += $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).BUILT))
612 # for easier debugging
613 modules_to_check := $(sort $(modules_to_check))
614 #$(error modules_to_check $(modules_to_check))
616 # -------------------------------------------------------------------
617 # This is used to to get the ordering right, you can also use these,
618 # but they're considered undocumented, so don't complain if their
621 prebuilt: $(ALL_PREBUILT)
623 # An internal target that depends on all copied headers
624 # (see copy_headers.make). Other targets that need the
625 # headers to be copied first can depend on this target.
626 .PHONY: all_copied_headers
627 all_copied_headers: ;
629 $(ALL_C_CPP_ETC_OBJECTS): | all_copied_headers
631 # All the droid stuff, in directories
634 $(modules_to_install) \
635 $(modules_to_check) \
636 $(INSTALLED_ANDROID_INFO_TXT_TARGET)
638 # -------------------------------------------------------------------
641 checkbuild: $(modules_to_check)
644 ramdisk: $(INSTALLED_RAMDISK_TARGET)
646 .PHONY: systemtarball
647 systemtarball: $(INSTALLED_SYSTEMTARBALL_TARGET)
649 .PHONY: userdataimage
650 userdataimage: $(INSTALLED_USERDATAIMAGE_TARGET)
652 .PHONY: userdatatarball
653 userdatatarball: $(INSTALLED_USERDATATARBALL_TARGET)
656 bootimage: $(INSTALLED_BOOTIMAGE_TARGET)
658 ifeq ($(BUILD_TINY_ANDROID), true)
659 INSTALLED_RECOVERYIMAGE_TARGET :=
662 # Build files and then package it into the rom formats
666 $(INSTALLED_BOOTIMAGE_TARGET) \
667 $(INSTALLED_RECOVERYIMAGE_TARGET) \
668 $(INSTALLED_USERDATAIMAGE_TARGET) \
669 $(INSTALLED_FILES_FILE)
671 # The actual files built by the droidcore target changes depending
672 # on the build variant.
674 droid tests: droidcore
676 $(call dist-for-goals, droid, \
677 $(INTERNAL_UPDATE_PACKAGE_TARGET) \
678 $(INTERNAL_OTA_PACKAGE_TARGET) \
681 $(INTERNAL_EMULATOR_PACKAGE_TARGET) \
682 $(PACKAGE_STATS_FILE) \
683 $(INSTALLED_FILES_FILE) \
684 $(INSTALLED_BUILD_PROP_TARGET) \
685 $(BUILT_TARGET_FILES_PACKAGE) \
688 # Tests are installed in userdata.img. If we're building the tests
689 # variant, copy it for "make tests dist". Also copy a zip of the
690 # contents of userdata.img, so that people can easily extract a
692 ifeq ($(TARGET_BUILD_VARIANT),tests)
693 $(call dist-for-goals, droid, \
694 $(INSTALLED_USERDATAIMAGE_TARGET) \
695 $(BUILT_TESTS_ZIP_PACKAGE) \
703 ALL_SDK_TARGETS := $(INTERNAL_SDK_TARGET)
704 sdk: $(ALL_SDK_TARGETS)
705 $(call dist-for-goals,sdk,$(ALL_SDK_TARGETS))
708 findbugs: $(INTERNAL_FINDBUGS_HTML_TARGET) $(INTERNAL_FINDBUGS_XML_TARGET)
713 $(TARGET_COMMON_OUT_ROOT) \
715 $(HOST_COMMON_OUT_ROOT)
717 @for dir in $(dirs_to_clean) ; do \
718 echo "Cleaning $$dir..."; \
726 @echo "Entire build directory removed."
728 # The rules for dataclean and installclean are defined in cleanbuild.mk.
730 #xxx scrape this from ALL_MODULE_NAME_TAGS
733 @echo "Available sub-modules:"
734 @echo "$(call module-names-for-tag-list,$(ALL_MODULE_TAGS))" | \
735 sed -e 's/ */\n/g' | sort -u | $(COLUMN)