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)
88 # Set up version information.
89 include $(BUILD_SYSTEM)/version_defaults.mk
91 # These are the modifier targets that don't do anything themselves, but
92 # change the behavior of the build.
93 # (must be defined before including definitions.make)
94 INTERNAL_MODIFIER_TARGETS := showcommands
96 # Bring in standard build system definitions.
97 include $(BUILD_SYSTEM)/definitions.mk
99 ifneq ($(filter eng user userdebug tests,$(MAKECMDGOALS)),)
100 $(info ***************************************************************)
101 $(info ***************************************************************)
102 $(info Don't pass '$(filter eng user userdebug tests,$(MAKECMDGOALS))' on \
103 the make command line.)
104 $(info Set TARGET_BUILD_VARIANT in buildspec.mk, or use lunch or)
106 $(info ***************************************************************)
107 $(info ***************************************************************)
113 ### In this section we set up the things that are different
114 ### between the build variants
119 user_variant := $(filter userdebug user,$(TARGET_BUILD_VARIANT))
120 enable_target_debugging := true
121 ifneq (,$(user_variant))
122 # Target is secure in user builds.
123 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
125 override_build_tags := user
126 ifeq ($(user_variant),userdebug)
127 # Pick up some extra useful tools
128 override_build_tags += debug
130 # Disable debugging in plain user builds.
131 enable_target_debugging :=
134 # TODO: Always set WITH_DEXPREOPT (for user builds) once it works on OSX.
135 # Also, remove the corresponding block in config/product_config.make.
136 ifeq ($(HOST_OS)-$(WITH_DEXPREOPT_buildbot),linux-true)
137 WITH_DEXPREOPT := true
140 # Turn on checkjni for non-user builds.
141 ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1
142 # Set device insecure for non-user builds.
143 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
144 endif # !user_variant
146 ifeq (true,$(strip $(enable_target_debugging)))
147 # Target is more debuggable and adbd is on by default
148 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1
149 # Include the debugging/testing OTA keys in this build.
150 INCLUDE_TEST_OTA_KEYS := true
151 else # !enable_target_debugging
152 # Target is less debuggable and adbd is off by default
153 ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0
154 endif # !enable_target_debugging
158 ifeq ($(TARGET_BUILD_VARIANT),tests)
159 override_build_tags := eng debug user development tests
164 ifneq ($(filter sdk,$(MAKECMDGOALS)),)
165 ifneq ($(words $(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS))),1)
166 $(error The 'sdk' target may not be specified with any other targets)
168 override_build_tags := user
169 ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true
170 ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes
172 # Enable sync for non-sdk builds only (sdk builds lack SubscribedFeedsProvider).
173 ADDITIONAL_BUILD_PROPERTIES += ro.config.sync=yes
176 ifeq "" "$(filter %:system/etc/apns-conf.xml, $(PRODUCT_COPY_FILES))"
177 # Install an apns-conf.xml file if one's not already being installed.
178 PRODUCT_COPY_FILES += development/data/etc/apns-conf_sdk.xml:system/etc/apns-conf.xml
179 ifeq ($(filter sdk,$(MAKECMDGOALS)),)
180 $(warning implicitly installing apns-conf_sdk.xml)
184 ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android
186 # enable vm tracing in files for now to help track
187 # the cause of ANRs in the content process
188 ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.stack-trace-file=/data/anr/traces.txt
191 # ------------------------------------------------------------
192 # Define a function that, given a list of module tags, returns
193 # non-empty if that module should be installed in /system.
195 # For most goals, anything tagged with "eng"/"debug"/"user" should
196 # be installed in /system.
197 define should-install-to-system
198 $(filter eng debug user,$(1))
201 ifneq (,$(filter sdk,$(MAKECMDGOALS)))
202 # For the sdk goal, anything with the "samples" tag should be
203 # installed in /data even if that module also has "eng"/"debug"/"user".
204 define should-install-to-system
205 $(if $(filter samples,$(1)),,$(filter eng debug user development,$(1)))
209 ifeq ($(TARGET_BUILD_VARIANT),)
210 # For the default goal, everything should be installed in /system.
211 define should-install-to-system
217 # If all they typed was make showcommands, we'll actually build
218 # the default target.
219 ifeq ($(MAKECMDGOALS),showcommands)
221 showcommands: $(DEFAULT_GOAL)
224 # These targets are going to delete stuff, don't bother including
225 # the whole directory tree if that's all we're going to do
226 ifeq ($(MAKECMDGOALS),clean)
229 ifeq ($(MAKECMDGOALS),clobber)
232 ifeq ($(MAKECMDGOALS),dataclean)
235 ifeq ($(MAKECMDGOALS),installclean)
239 # Bring in all modules that need to be built.
240 ifneq ($(dont_bother),true)
244 ifeq ($(HOST_OS),windows)
247 ifeq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
251 ifeq ($(SDK_ONLY),true)
258 dalvik/tools/dmtracedump \
259 development/emulator/mksdcard \
260 development/tools/activitycreator \
261 development/tools/line_endings \
266 external/sqlite/dist \
268 frameworks/base/libs/utils \
269 frameworks/base/tools/aapt \
270 frameworks/base/tools/aidl \
272 system/core/fastboot \
273 system/core/libcutils \
275 system/core/libzipfile
277 # The following can only be built if "javac" is available.
278 # This check is used when building parts of the SDK under Cygwin.
279 ifneq (,$(shell which javac 2>/dev/null))
280 $(warning sdk-only: javac available.)
282 build/tools/signapk \
283 build/tools/zipalign \
287 development/tools/androidprefs \
288 development/tools/apkbuilder \
289 development/tools/jarutils \
290 development/tools/layoutlib_utils \
291 development/tools/ninepatch \
292 development/tools/sdkstats \
293 development/tools/sdkmanager \
295 frameworks/base/tools/layoutlib \
296 external/googleclient \
299 $(warning sdk-only: javac not available.)
302 # Exclude tools/acp when cross-compiling windows under linux
303 ifeq ($(findstring Linux,$(UNAME)),)
304 subdirs += build/tools/acp
308 ifeq ($(BUILD_TINY_ANDROID), true)
310 # TINY_ANDROID is a super-minimal build configuration, handy for board
311 # bringup and very low level debugging
313 INTERNAL_DEFAULT_DOCS_TARGETS :=
321 else # !BUILD_TINY_ANDROID
324 # Typical build; include any Android.mk files we can find.
326 INTERNAL_DEFAULT_DOCS_TARGETS := offline-sdk-docs
328 # Only include Android.mk files directly under vendor/*, not
329 # *all* Android.mk files under vendor (which is what would happen
330 # if we didn't prune vendor in the findleaves call).
331 subdir_makefiles += $(wildcard vendor/*/Android.mk)
335 endif # !BUILD_TINY_ANDROID
339 # Can't use first-makefiles-under here because
340 # --mindepth=2 makes the prunes not work.
341 subdir_makefiles += \
342 $(shell build/tools/findleaves.sh \
343 --prune="./vendor" --prune="./out" $(subdirs) Android.mk)
345 # Boards may be defined under $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)
346 # or under vendor/*/$(TARGET_DEVICE). Search in both places, but
347 # make sure only one exists.
348 # Real boards should always be associated with an OEM vendor.
351 $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk \
352 vendor/*/$(TARGET_DEVICE)/BoardConfig.mk \
354 ifeq ($(board_config_mk),)
355 $(error No config file found for TARGET_DEVICE $(TARGET_DEVICE))
357 ifneq ($(words $(board_config_mk)),1)
358 $(error Multiple board config files for TARGET_DEVICE $(TARGET_DEVICE): $(board_config_mk))
360 include $(board_config_mk)
361 TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(board_config_mk)))
365 $(info ***************************************************************)
366 $(info ***************************************************************)
367 $(info CUSTOM_PKG is obsolete; use CUSTOM_MODULES)
368 $(info ***************************************************************)
369 $(info ***************************************************************)
373 $(info ***************************************************************)
374 $(info ***************************************************************)
375 $(info CUSTOM_TARGETS is obsolete; use CUSTOM_MODULES)
376 $(info ***************************************************************)
377 $(info ***************************************************************)
382 # Include all of the makefiles in the system
385 ifneq ($(ONE_SHOT_MAKEFILE),)
386 # We've probably been invoked by the "mm" shell function
387 # with a subdirectory's makefile.
388 include $(ONE_SHOT_MAKEFILE)
389 # Change CUSTOM_MODULES to include only modules that were
390 # defined by this makefile; this will install all of those
391 # modules as a side-effect. Do this after including ONE_SHOT_MAKEFILE
392 # so that the modules will be installed in the same place they
393 # would have been with a normal make.
394 CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS),))
396 INTERNAL_DEFAULT_DOCS_TARGETS :=
397 # Stub out the notice targets, which probably aren't defined
398 # when using ONE_SHOT_MAKEFILE.
402 include $(subdir_makefiles)
404 # -------------------------------------------------------------------
405 # All module makefiles have been included at this point.
406 # -------------------------------------------------------------------
408 # -------------------------------------------------------------------
409 # Include any makefiles that must happen after the module makefiles
410 # have been included.
411 # TODO: have these files register themselves via a global var rather
412 # than hard-coding the list here.
414 # Only include this during a full build, otherwise we can't be
415 # guaranteed that any policies were included.
416 -include frameworks/policies/base/PolicyConfig.mk
419 # -------------------------------------------------------------------
420 # Fix up CUSTOM_MODULES to refer to installed files rather than
421 # just bare module names. Leave unknown modules alone in case
422 # they're actually full paths to a particular file.
423 known_custom_modules := $(filter $(ALL_MODULES),$(CUSTOM_MODULES))
424 unknown_custom_modules := $(filter-out $(ALL_MODULES),$(CUSTOM_MODULES))
426 $(call module-installed-files,$(known_custom_modules)) \
427 $(unknown_custom_modules)
429 # -------------------------------------------------------------------
430 # Define dependencies for modules that require other modules.
431 # This can only happen now, after we've read in all module makefiles.
433 # TODO: deal with the fact that a bare module name isn't
434 # unambiguous enough. Maybe declare short targets like
435 # APPS:Quake or HOST:SHARED_LIBRARIES:libutils.
436 # BUG: the system image won't know to depend on modules that are
437 # brought in as requirements of other modules.
438 define add-required-deps
441 $(foreach m,$(ALL_MODULES), \
442 $(eval r := $(ALL_MODULES.$(m).REQUIRED)) \
444 $(eval r := $(call module-installed-files,$(r))) \
445 $(eval $(call add-required-deps,$(ALL_MODULES.$(m).INSTALLED),$(r))) \
452 # -------------------------------------------------------------------
453 # Figure out our module sets.
455 # Of the modules defined by the component makefiles,
456 # determine what we actually want to build.
457 # If a module has the "restricted" tag on it, it
458 # poisons the rest of the tags and shouldn't appear
460 Default_MODULES := $(sort $(ALL_DEFAULT_INSTALLED_MODULES) \
461 $(ALL_BUILT_MODULES) \
465 # The base list of modules to build for this product is specified
466 # by the appropriate product definition file, which was included
467 # by product_config.make.
468 user_PACKAGES := $(call module-installed-files, \
469 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES))
471 $(info user packages for $(TARGET_DEVICE) ($(INTERNAL_PRODUCT)):)
472 $(foreach p,$(user_PACKAGES),$(info : $(p)))
476 # We're not doing a full build, and are probably only including
477 # a subset of the module makefiles. Don't try to build any modules
478 # requested by the product, because we probably won't have rules
482 # Use tags to get the non-APPS user modules. Use the product
483 # definition files to get the APPS user modules.
484 user_MODULES := $(sort $(call get-tagged-modules,user,_class@APPS restricted))
485 user_MODULES := $(user_MODULES) $(user_PACKAGES)
487 eng_MODULES := $(sort $(call get-tagged-modules,eng,restricted))
488 debug_MODULES := $(sort $(call get-tagged-modules,debug,restricted))
489 tests_MODULES := $(sort $(call get-tagged-modules,tests,restricted))
491 droid_MODULES := $(sort $(Default_MODULES) \
495 $(all_development_MODULES))
497 # THIS IS A TOTAL HACK AND SHOULD NOT BE USED AS AN EXAMPLE
498 modules_to_build := $(droid_MODULES)
499 ifneq ($(override_build_tags),)
500 modules_to_build := $(sort $(Default_MODULES) \
501 $(foreach tag,$(override_build_tags),$($(tag)_MODULES)))
502 #$(error skipping modules $(filter-out $(modules_to_build),$(Default_MODULES) $(droid_MODULES)))
505 # Some packages may override others using LOCAL_OVERRIDES_PACKAGES.
506 # Filter out (do not install) any overridden packages.
507 overridden_packages := $(call get-package-overrides,$(modules_to_build))
508 ifdef overridden_packages
509 # old_modules_to_build := $(modules_to_build)
510 modules_to_build := \
511 $(filter-out $(foreach p,$(overridden_packages),%/$(p) %/$(p).apk), \
514 #$(error filtered out $(filter-out $(modules_to_build),$(old_modules_to_build)))
516 # Don't include any GNU targets in the SDK. It's ok (and necessary)
517 # to build the host tools, but nothing that's going to be installed
518 # on the target (including static libraries).
519 ifneq ($(filter sdk,$(MAKECMDGOALS)),)
520 target_gnu_MODULES := \
522 $(TARGET_OUT_INTERMEDIATES)/% \
524 $(TARGET_OUT_DATA)/%, \
525 $(sort $(call get-tagged-modules,gnu)))
526 $(info Removing from sdk:)$(foreach d,$(target_gnu_MODULES),$(info : $(d)))
527 modules_to_build := \
528 $(filter-out $(target_gnu_MODULES),$(modules_to_build))
532 # config/Makefile contains extra stuff that we don't want to pollute this
533 # top-level makefile with. It expects that ALL_DEFAULT_INSTALLED_MODULES
534 # contains everything that's built during the current make, but it also further
535 # extends ALL_DEFAULT_INSTALLED_MODULES.
536 ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_build)
537 include $(BUILD_SYSTEM)/Makefile
538 modules_to_build := $(sort $(ALL_DEFAULT_INSTALLED_MODULES))
539 ALL_DEFAULT_INSTALLED_MODULES :=
543 # -------------------------------------------------------------------
544 # This is used to to get the ordering right, you can also use these,
545 # but they're considered undocumented, so don't complain if their
548 prebuilt: $(ALL_PREBUILT)
550 # An internal target that depends on all copied headers
551 # (see copy_headers.make). Other targets that need the
552 # headers to be copied first can depend on this target.
553 .PHONY: all_copied_headers
554 all_copied_headers: ;
556 $(ALL_C_CPP_ETC_OBJECTS): | all_copied_headers
558 # All the droid stuff, in directories
560 files: prebuilt $(modules_to_build) $(INSTALLED_ANDROID_INFO_TXT_TARGET)
562 # -------------------------------------------------------------------
565 ramdisk: $(INSTALLED_RAMDISK_TARGET)
567 .PHONY: systemtarball
568 systemtarball: $(INSTALLED_SYSTEMTARBALL_TARGET)
570 .PHONY: userdataimage
571 userdataimage: $(INSTALLED_USERDATAIMAGE_TARGET)
573 .PHONY: userdatatarball
574 userdatatarball: $(INSTALLED_USERDATATARBALL_TARGET)
577 bootimage: $(INSTALLED_BOOTIMAGE_TARGET)
579 ifeq ($(BUILD_TINY_ANDROID), true)
580 INSTALLED_RECOVERYIMAGE_TARGET :=
583 # Build files and then package it into the rom formats
587 $(INSTALLED_BOOTIMAGE_TARGET) \
588 $(INSTALLED_RECOVERYIMAGE_TARGET) \
589 $(INSTALLED_USERDATAIMAGE_TARGET) \
590 $(INTERNAL_DEFAULT_DOCS_TARGETS)
592 # The actual files built by the droidcore target changes depending
593 # on the build variant.
595 droid tests: droidcore
597 $(call dist-for-goals, droid, \
598 $(INTERNAL_UPDATE_PACKAGE_TARGET) \
599 $(INTERNAL_OTA_PACKAGE_TARGET) \
602 $(INTERNAL_EMULATOR_PACKAGE_TARGET) \
603 $(PACKAGE_STATS_FILE) \
604 $(INSTALLED_FILES_FILE) \
605 $(INSTALLED_BUILD_PROP_TARGET) \
606 $(BUILT_TARGET_FILES_PACKAGE) \
609 # Tests are installed in userdata.img. If we're building the tests
610 # variant, copy it for "make tests dist". Also copy a zip of the
611 # contents of userdata.img, so that people can easily extract a
613 ifeq ($(TARGET_BUILD_VARIANT),tests)
614 $(call dist-for-goals, droid, \
615 $(INSTALLED_USERDATAIMAGE_TARGET) \
616 $(BUILT_TESTS_ZIP_PACKAGE) \
624 ALL_SDK_TARGETS := $(INTERNAL_SDK_TARGET)
625 sdk: $(ALL_SDK_TARGETS)
626 $(call dist-for-goals,sdk,$(ALL_SDK_TARGETS))
629 findbugs: $(INTERNAL_FINDBUGS_HTML_TARGET) $(INTERNAL_FINDBUGS_XML_TARGET)
634 $(TARGET_COMMON_OUT_ROOT) \
636 $(HOST_COMMON_OUT_ROOT)
638 @for dir in $(dirs_to_clean) ; do \
639 echo "Cleaning $$dir..."; \
647 @echo "Entire build directory removed."
651 @rm -rf $(PRODUCT_OUT)/data/*
652 @rm -rf $(PRODUCT_OUT)/data-qemu/*
653 @rm -rf $(PRODUCT_OUT)/userdata-qemu.img
654 @echo "Deleted emulator userdata images."
657 # Deletes all of the files that change between different build types,
658 # like "make user" vs. "make sdk". This lets you work with different
659 # build types without having to do a full clean each time. E.g.:
662 # $ make installclean
664 # $ make installclean
667 installclean: dataclean
668 $(hide) rm -rf ./$(PRODUCT_OUT)/system
669 $(hide) rm -rf ./$(PRODUCT_OUT)/recovery
670 $(hide) rm -rf ./$(PRODUCT_OUT)/data
671 $(hide) rm -rf ./$(PRODUCT_OUT)/root
672 $(hide) rm -rf ./$(PRODUCT_OUT)/obj/NOTICE_FILES
673 @# Remove APPS because they may contain the wrong resources.
674 $(hide) rm -rf ./$(PRODUCT_OUT)/obj/APPS
675 $(hide) rm -rf ./$(HOST_OUT)/obj/NOTICE_FILES
676 $(hide) rm -rf ./$(HOST_OUT)/sdk
677 $(hide) rm -rf ./$(PRODUCT_OUT)/obj/PACKAGING
678 $(hide) rm -f ./$(PRODUCT_OUT)/*.img
679 $(hide) rm -f ./$(PRODUCT_OUT)/*.zip
680 $(hide) rm -f ./$(PRODUCT_OUT)/*.txt
681 $(hide) rm -f ./$(PRODUCT_OUT)/*.xlb
682 @echo "Deleted images and staging directories."
684 #xxx scrape this from ALL_MODULE_NAME_TAGS
687 @echo "Available sub-modules:"
688 @echo "$(call module-names-for-tag-list,$(ALL_MODULE_TAGS))" | \
689 sed -e 's/ */\n/g' | sort -u | $(COLUMN)