Home | History | Annotate | Download | only in core
      1 # Put some miscellaneous rules here
      2 
      3 # HACK: clear LOCAL_PATH from including last build target before calling
      4 # intermedites-dir-for
      5 LOCAL_PATH := $(BUILD_SYSTEM)
      6 
      7 # Pick a reasonable string to use to identify files.
      8 ifneq "" "$(filter eng.%,$(BUILD_NUMBER))"
      9   # BUILD_NUMBER has a timestamp in it, which means that
     10   # it will change every time.  Pick a stable value.
     11   FILE_NAME_TAG := eng.$(USER)
     12 else
     13   FILE_NAME_TAG := $(BUILD_NUMBER)
     14 endif
     15 
     16 # -----------------------------------------------------------------
     17 # Define rules to copy PRODUCT_COPY_FILES defined by the product.
     18 # PRODUCT_COPY_FILES contains words like <source file>:<dest file>[:<owner>].
     19 # <dest file> is relative to $(PRODUCT_OUT), so it should look like,
     20 # e.g., "system/etc/file.xml".
     21 # The filter part means "only eval the copy-one-file rule if this
     22 # src:dest pair is the first one to match the same dest"
     23 #$(1): the src:dest pair
     24 define check-product-copy-files
     25 $(if $(filter %.apk, $(call word-colon, 2, $(1))),$(error \
     26     Prebuilt apk found in PRODUCT_COPY_FILES: $(1), use BUILD_PREBUILT instead!))
     27 endef
     28 # filter out the duplicate <source file>:<dest file> pairs.
     29 unique_product_copy_files_pairs :=
     30 $(foreach cf,$(PRODUCT_COPY_FILES), \
     31     $(if $(filter $(unique_product_copy_files_pairs),$(cf)),,\
     32         $(eval unique_product_copy_files_pairs += $(cf))))
     33 unique_product_copy_files_destinations :=
     34 $(foreach cf,$(unique_product_copy_files_pairs), \
     35     $(eval _src := $(call word-colon,1,$(cf))) \
     36     $(eval _dest := $(call word-colon,2,$(cf))) \
     37     $(call check-product-copy-files,$(cf)) \
     38     $(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \
     39         $(info PRODUCT_COPY_FILES $(cf) ignored.), \
     40         $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
     41         $(if $(filter %.xml,$(_dest)),\
     42             $(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\
     43             $(eval $(call copy-one-file,$(_src),$(_fulldest)))) \
     44         $(eval ALL_DEFAULT_INSTALLED_MODULES += $(_fulldest)) \
     45         $(eval unique_product_copy_files_destinations += $(_dest))))
     46 unique_product_copy_files_pairs :=
     47 unique_product_copy_files_destinations :=
     48 
     49 # -----------------------------------------------------------------
     50 # docs/index.html
     51 ifeq (,$(TARGET_BUILD_APPS))
     52 gen := $(OUT_DOCS)/index.html
     53 ALL_DOCS += $(gen)
     54 $(gen): frameworks/base/docs/docs-redirect-index.html
     55 	@mkdir -p $(dir $@)
     56 	@cp -f $< $@
     57 endif
     58 
     59 # -----------------------------------------------------------------
     60 # default.prop
     61 INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_ROOT_OUT)/default.prop
     62 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_TARGET)
     63 ADDITIONAL_DEFAULT_PROPERTIES := \
     64     $(call collapse-pairs, $(ADDITIONAL_DEFAULT_PROPERTIES))
     65 ADDITIONAL_DEFAULT_PROPERTIES += \
     66     $(call collapse-pairs, $(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))
     67 ADDITIONAL_DEFAULT_PROPERTIES := $(call uniq-pairs-by-first-component, \
     68     $(ADDITIONAL_DEFAULT_PROPERTIES),=)
     69 
     70 $(INSTALLED_DEFAULT_PROP_TARGET):
     71 	@echo Target buildinfo: $@
     72 	@mkdir -p $(dir $@)
     73 	$(hide) echo "#" > $@; \
     74 	        echo "# ADDITIONAL_DEFAULT_PROPERTIES" >> $@; \
     75 	        echo "#" >> $@;
     76 	$(hide) $(foreach line,$(ADDITIONAL_DEFAULT_PROPERTIES), \
     77 		echo "$(line)" >> $@;)
     78 	build/tools/post_process_props.py $@
     79 
     80 # -----------------------------------------------------------------
     81 # build.prop
     82 INSTALLED_BUILD_PROP_TARGET := $(TARGET_OUT)/build.prop
     83 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_BUILD_PROP_TARGET)
     84 ADDITIONAL_BUILD_PROPERTIES := \
     85     $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))
     86 ADDITIONAL_BUILD_PROPERTIES := $(call uniq-pairs-by-first-component, \
     87     $(ADDITIONAL_BUILD_PROPERTIES),=)
     88 
     89 # A list of arbitrary tags describing the build configuration.
     90 # Force ":=" so we can use +=
     91 BUILD_VERSION_TAGS := $(BUILD_VERSION_TAGS)
     92 ifeq ($(TARGET_BUILD_TYPE),debug)
     93   BUILD_VERSION_TAGS += debug
     94 endif
     95 # The "test-keys" tag marks builds signed with the old test keys,
     96 # which are available in the SDK.  "dev-keys" marks builds signed with
     97 # non-default dev keys (usually private keys from a vendor directory).
     98 # Both of these tags will be removed and replaced with "release-keys"
     99 # when the target-files is signed in a post-build step.
    100 ifeq ($(DEFAULT_SYSTEM_DEV_CERTIFICATE),build/target/product/security/testkey)
    101 BUILD_KEYS := test-keys
    102 else
    103 BUILD_KEYS := dev-keys
    104 endif
    105 BUILD_VERSION_TAGS += $(BUILD_KEYS)
    106 BUILD_VERSION_TAGS := $(subst $(space),$(comma),$(sort $(BUILD_VERSION_TAGS)))
    107 
    108 # A human-readable string that descibes this build in detail.
    109 build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER) $(BUILD_VERSION_TAGS)
    110 $(INSTALLED_BUILD_PROP_TARGET): PRIVATE_BUILD_DESC := $(build_desc)
    111 
    112 # The string used to uniquely identify the combined build and product; used by the OTA server.
    113 ifeq (,$(strip $(BUILD_FINGERPRINT)))
    114   ifneq ($(filter eng.%,$(BUILD_NUMBER)),)
    115     # Trim down BUILD_FINGERPRINT: the default BUILD_NUMBER makes it easily exceed
    116     # the Android system property length limit (PROPERTY_VALUE_MAX=92).
    117     BF_BUILD_NUMBER := $(USER)$(shell date +%m%d%H%M)
    118   else
    119     BF_BUILD_NUMBER := $(BUILD_NUMBER)
    120   endif
    121   BUILD_FINGERPRINT := $(PRODUCT_BRAND)/$(TARGET_PRODUCT)/$(TARGET_DEVICE):$(PLATFORM_VERSION)/$(BUILD_ID)/$(BF_BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)
    122 endif
    123 ifneq ($(words $(BUILD_FINGERPRINT)),1)
    124   $(error BUILD_FINGERPRINT cannot contain spaces: "$(BUILD_FINGERPRINT)")
    125 endif
    126 
    127 # The string used to uniquely identify the system build; used by the OTA server.
    128 # This purposefully excludes any product-specific variables.
    129 ifeq (,$(strip $(BUILD_THUMBPRINT)))
    130   BUILD_THUMBPRINT := $(PLATFORM_VERSION)/$(BUILD_ID)/$(BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)
    131 endif
    132 ifneq ($(words $(BUILD_THUMBPRINT)),1)
    133   $(error BUILD_THUMBPRINT cannot contain spaces: "$(BUILD_THUMBPRINT)")
    134 endif
    135 
    136 KNOWN_OEM_THUMBPRINT_PROPERTIES := \
    137     ro.product.brand \
    138     ro.product.name \
    139     ro.product.device
    140 OEM_THUMBPRINT_PROPERTIES := $(filter $(KNOWN_OEM_THUMBPRINT_PROPERTIES),\
    141     $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES))
    142 
    143 # Display parameters shown under Settings -> About Phone
    144 ifeq ($(TARGET_BUILD_VARIANT),user)
    145   # User builds should show:
    146   # release build number or branch.buld_number non-release builds
    147 
    148   # Dev. branches should have DISPLAY_BUILD_NUMBER set
    149   ifeq "true" "$(DISPLAY_BUILD_NUMBER)"
    150     BUILD_DISPLAY_ID := $(BUILD_ID).$(BUILD_NUMBER) $(BUILD_KEYS)
    151   else
    152     BUILD_DISPLAY_ID := $(BUILD_ID) $(BUILD_KEYS)
    153   endif
    154 else
    155   # Non-user builds should show detailed build information
    156   BUILD_DISPLAY_ID := $(build_desc)
    157 endif
    158 
    159 # Whether there is default locale set in PRODUCT_PROPERTY_OVERRIDES
    160 product_property_override_locale_language := $(strip \
    161     $(patsubst ro.product.locale.language=%,%,\
    162     $(filter ro.product.locale.language=%,$(PRODUCT_PROPERTY_OVERRIDES))))
    163 product_property_overrides_locale_region := $(strip \
    164     $(patsubst ro.product.locale.region=%,%,\
    165     $(filter ro.product.locale.region=%,$(PRODUCT_PROPERTY_OVERRIDES))))
    166 
    167 # Selects the first locale in the list given as the argument,
    168 # and splits it into language and region, which each may be
    169 # empty.
    170 define default-locale
    171 $(subst _, , $(firstword $(1)))
    172 endef
    173 
    174 # Selects the first locale in the list given as the argument
    175 # and returns the language (or the region), if it's not set in PRODUCT_PROPERTY_OVERRIDES;
    176 # Return empty string if it's already set in PRODUCT_PROPERTY_OVERRIDES.
    177 define default-locale-language
    178 $(if $(product_property_override_locale_language),,$(word 1, $(call default-locale, $(1))))
    179 endef
    180 define default-locale-region
    181 $(if $(product_property_overrides_locale_region),,$(word 2, $(call default-locale, $(1))))
    182 endef
    183 
    184 BUILDINFO_SH := build/tools/buildinfo.sh
    185 
    186 ifdef TARGET_SYSTEM_PROP
    187 system_prop_file := $(TARGET_SYSTEM_PROP)
    188 else
    189 system_prop_file := $(wildcard $(TARGET_DEVICE_DIR)/system.prop)
    190 endif
    191 $(INSTALLED_BUILD_PROP_TARGET): $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(system_prop_file)
    192 	@echo Target buildinfo: $@
    193 	@mkdir -p $(dir $@)
    194 	$(hide) echo > $@
    195 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES),)
    196 	$(hide) echo "#" >> $@; \
    197 	        echo "# PRODUCT_OEM_PROPERTIES" >> $@; \
    198 	        echo "#" >> $@;
    199 	$(hide) $(foreach prop,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES), \
    200 		echo "import /oem/oem.prop $(prop)" >> $@;)
    201 endif
    202 	$(hide) TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \
    203 			TARGET_BUILD_FLAVOR="$(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)" \
    204 			TARGET_DEVICE="$(TARGET_DEVICE)" \
    205 			PRODUCT_NAME="$(TARGET_PRODUCT)" \
    206 			PRODUCT_BRAND="$(PRODUCT_BRAND)" \
    207 			PRODUCT_DEFAULT_LANGUAGE="$(call default-locale-language,$(PRODUCT_LOCALES))" \
    208 			PRODUCT_DEFAULT_REGION="$(call default-locale-region,$(PRODUCT_LOCALES))" \
    209 			PRODUCT_DEFAULT_WIFI_CHANNELS="$(PRODUCT_DEFAULT_WIFI_CHANNELS)" \
    210 			PRODUCT_MODEL="$(PRODUCT_MODEL)" \
    211 			PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
    212 			PRIVATE_BUILD_DESC="$(PRIVATE_BUILD_DESC)" \
    213 			BUILD_ID="$(BUILD_ID)" \
    214 			BUILD_DISPLAY_ID="$(BUILD_DISPLAY_ID)" \
    215 			BUILD_NUMBER="$(BUILD_NUMBER)" \
    216 			PLATFORM_VERSION="$(PLATFORM_VERSION)" \
    217 			PLATFORM_SDK_VERSION="$(PLATFORM_SDK_VERSION)" \
    218 			PLATFORM_VERSION_CODENAME="$(PLATFORM_VERSION_CODENAME)" \
    219 			PLATFORM_VERSION_ALL_CODENAMES="$(PLATFORM_VERSION_ALL_CODENAMES)" \
    220 			BUILD_VERSION_TAGS="$(BUILD_VERSION_TAGS)" \
    221 			TARGET_BOOTLOADER_BOARD_NAME="$(TARGET_BOOTLOADER_BOARD_NAME)" \
    222 			BUILD_FINGERPRINT="$(BUILD_FINGERPRINT)" \
    223 			$(if $(OEM_THUMBPRINT_PROPERTIES),BUILD_THUMBPRINT="$(BUILD_THUMBPRINT)") \
    224 			TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \
    225 			TARGET_CPU_ABI_LIST="$(TARGET_CPU_ABI_LIST)" \
    226 			TARGET_CPU_ABI_LIST_32_BIT="$(TARGET_CPU_ABI_LIST_32_BIT)" \
    227 			TARGET_CPU_ABI_LIST_64_BIT="$(TARGET_CPU_ABI_LIST_64_BIT)" \
    228 			TARGET_CPU_ABI="$(TARGET_CPU_ABI)" \
    229 			TARGET_CPU_ABI2="$(TARGET_CPU_ABI2)" \
    230 			TARGET_AAPT_CHARACTERISTICS="$(TARGET_AAPT_CHARACTERISTICS)" \
    231 	        bash $(BUILDINFO_SH) >> $@
    232 	$(hide) $(foreach file,$(system_prop_file), \
    233 		if [ -f "$(file)" ]; then \
    234 			echo "#" >> $@; \
    235 			echo Target buildinfo from: "$(file)"; \
    236 			echo "# from $(file)" >> $@; \
    237 			echo "#" >> $@; \
    238 			cat $(file) >> $@; \
    239 		fi;)
    240 	$(if $(ADDITIONAL_BUILD_PROPERTIES), \
    241 		$(hide) echo >> $@; \
    242 		        echo "#" >> $@; \
    243 		        echo "# ADDITIONAL_BUILD_PROPERTIES" >> $@; \
    244 		        echo "#" >> $@; )
    245 	$(hide) $(foreach line,$(ADDITIONAL_BUILD_PROPERTIES), \
    246 		echo "$(line)" >> $@;)
    247 	$(hide) build/tools/post_process_props.py $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_PROPERTY_BLACKLIST)
    248 
    249 build_desc :=
    250 
    251 # -----------------------------------------------------------------
    252 # vendor build.prop
    253 #
    254 # For verifying that the vendor build is what we thing it is
    255 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
    256 INSTALLED_VENDOR_BUILD_PROP_TARGET := $(TARGET_OUT_VENDOR)/build.prop
    257 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_VENDOR_BUILD_PROP_TARGET)
    258 $(INSTALLED_VENDOR_BUILD_PROP_TARGET): $(INSTALLED_BUILD_PROP_TARGET)
    259 	@echo Target vendor buildinfo: $@
    260 	@mkdir -p $(dir $@)
    261 	$(hide) echo > $@
    262 	$(hide) echo ro.vendor.build.date=`date`>>$@
    263 	$(hide) echo ro.vendor.build.date.utc=`date +%s`>>$@
    264 	$(hide) echo ro.vendor.build.fingerprint="$(BUILD_FINGERPRINT)">>$@
    265 endif
    266 
    267 # -----------------------------------------------------------------
    268 # sdk-build.prop
    269 #
    270 # There are certain things in build.prop that we don't want to
    271 # ship with the sdk; remove them.
    272 
    273 # This must be a list of entire property keys followed by
    274 # "=" characters, without any internal spaces.
    275 sdk_build_prop_remove := \
    276 	ro.build.user= \
    277 	ro.build.host= \
    278 	ro.product.brand= \
    279 	ro.product.manufacturer= \
    280 	ro.product.device=
    281 # TODO: Remove this soon-to-be obsolete property
    282 sdk_build_prop_remove += ro.build.product=
    283 INSTALLED_SDK_BUILD_PROP_TARGET := $(PRODUCT_OUT)/sdk/sdk-build.prop
    284 $(INSTALLED_SDK_BUILD_PROP_TARGET): $(INSTALLED_BUILD_PROP_TARGET)
    285 	@echo SDK buildinfo: $@
    286 	@mkdir -p $(dir $@)
    287 	$(hide) grep -v "$(subst $(space),\|,$(strip \
    288 				$(sdk_build_prop_remove)))" $< > $@.tmp
    289 	$(hide) for x in $(sdk_build_prop_remove); do \
    290 				echo "$$x"generic >> $@.tmp; done
    291 	$(hide) mv $@.tmp $@
    292 
    293 # -----------------------------------------------------------------
    294 # package stats
    295 PACKAGE_STATS_FILE := $(PRODUCT_OUT)/package-stats.txt
    296 PACKAGES_TO_STAT := \
    297     $(sort $(filter $(TARGET_OUT)/% $(TARGET_OUT_DATA)/%, \
    298 	$(filter %.jar %.apk, $(ALL_DEFAULT_INSTALLED_MODULES))))
    299 $(PACKAGE_STATS_FILE): $(PACKAGES_TO_STAT)
    300 	@echo Package stats: $@
    301 	@mkdir -p $(dir $@)
    302 	$(hide) rm -f $@
    303 	$(hide) build/tools/dump-package-stats $^ > $@
    304 
    305 .PHONY: package-stats
    306 package-stats: $(PACKAGE_STATS_FILE)
    307 
    308 # -----------------------------------------------------------------
    309 # Cert-to-package mapping.  Used by the post-build signing tools.
    310 # Use a macro to add newline to each echo command
    311 define _apkcerts_echo_with_newline
    312 $(hide) echo $(1)
    313 
    314 endef
    315 
    316 name := $(TARGET_PRODUCT)
    317 ifeq ($(TARGET_BUILD_TYPE),debug)
    318   name := $(name)_debug
    319 endif
    320 name := $(name)-apkcerts-$(FILE_NAME_TAG)
    321 intermediates := \
    322 	$(call intermediates-dir-for,PACKAGING,apkcerts)
    323 APKCERTS_FILE := $(intermediates)/$(name).txt
    324 # We don't need to really build all the modules.
    325 # TODO: rebuild APKCERTS_FILE if any app change its cert.
    326 $(APKCERTS_FILE):
    327 	@echo APK certs list: $@
    328 	@mkdir -p $(dir $@)
    329 	@rm -f $@
    330 	$(foreach p,$(PACKAGES),\
    331 	  $(if $(PACKAGES.$(p).EXTERNAL_KEY),\
    332 	    $(call _apkcerts_echo_with_newline,\
    333 	      'name="$(p).apk" certificate="EXTERNAL" \
    334 	      private_key=""' >> $@),\
    335 	    $(call _apkcerts_echo_with_newline,\
    336 	      'name="$(p).apk" certificate="$(PACKAGES.$(p).CERTIFICATE)" \
    337 	      private_key="$(PACKAGES.$(p).PRIVATE_KEY)"' >> $@)))
    338 	# In case value of PACKAGES is empty.
    339 	$(hide) touch $@
    340 
    341 .PHONY: apkcerts-list
    342 apkcerts-list: $(APKCERTS_FILE)
    343 
    344 ifneq (,$(TARGET_BUILD_APPS))
    345   $(call dist-for-goals, apps_only, $(APKCERTS_FILE):apkcerts.txt)
    346 endif
    347 
    348 # -----------------------------------------------------------------
    349 # module info file
    350 ifdef CREATE_MODULE_INFO_FILE
    351   MODULE_INFO_FILE := $(PRODUCT_OUT)/module-info.txt
    352   $(info Generating $(MODULE_INFO_FILE)...)
    353   $(shell rm -f $(MODULE_INFO_FILE))
    354   $(foreach m,$(ALL_MODULES), \
    355     $(shell echo "NAME=\"$(m)\"" \
    356 	"PATH=\"$(strip $(ALL_MODULES.$(m).PATH))\"" \
    357 	"TAGS=\"$(strip $(filter-out _%,$(ALL_MODULES.$(m).TAGS)))\"" \
    358 	"BUILT=\"$(strip $(ALL_MODULES.$(m).BUILT))\"" \
    359 	"INSTALLED=\"$(strip $(ALL_MODULES.$(m).INSTALLED))\"" >> $(MODULE_INFO_FILE)))
    360 endif
    361 
    362 # -----------------------------------------------------------------
    363 
    364 # The dev key is used to sign this package, and as the key required
    365 # for future OTA packages installed by this system.  Actual product
    366 # deliverables will be re-signed by hand.  We expect this file to
    367 # exist with the suffixes ".x509.pem" and ".pk8".
    368 DEFAULT_KEY_CERT_PAIR := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
    369 
    370 
    371 # Rules that need to be present for the all targets, even
    372 # if they don't do anything.
    373 .PHONY: systemimage
    374 systemimage:
    375 
    376 # -----------------------------------------------------------------
    377 
    378 .PHONY: event-log-tags
    379 
    380 # Produce an event logs tag file for everything we know about, in order
    381 # to properly allocate numbers.  Then produce a file that's filtered
    382 # for what's going to be installed.
    383 
    384 all_event_log_tags_file := $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
    385 
    386 event_log_tags_file := $(TARGET_OUT)/etc/event-log-tags
    387 
    388 # Include tags from all packages that we know about
    389 all_event_log_tags_src := \
    390     $(sort $(foreach m, $(ALL_MODULES), $(ALL_MODULES.$(m).EVENT_LOG_TAGS)))
    391 
    392 # PDK builds will already have a full list of tags that needs to get merged
    393 # in with the ones from source
    394 pdk_fusion_log_tags_file := $(patsubst $(PRODUCT_OUT)/%,$(_pdk_fusion_intermediates)/%,$(filter $(event_log_tags_file),$(ALL_PDK_FUSION_FILES)))
    395 
    396 $(all_event_log_tags_file): PRIVATE_SRC_FILES := $(all_event_log_tags_src) $(pdk_fusion_log_tags_file)
    397 $(all_event_log_tags_file): $(all_event_log_tags_src) $(pdk_fusion_log_tags_file)
    398 	$(hide) mkdir -p $(dir $@)
    399 	$(hide) build/tools/merge-event-log-tags.py -o $@ $(PRIVATE_SRC_FILES)
    400 
    401 # Include tags from all packages included in this product, plus all
    402 # tags that are part of the system (ie, not in a vendor/ or device/
    403 # directory).
    404 event_log_tags_src := \
    405     $(sort $(foreach m,\
    406       $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES) \
    407       $(call module-names-for-tag-list,user), \
    408       $(ALL_MODULES.$(m).EVENT_LOG_TAGS)) \
    409       $(filter-out vendor/% device/% out/%,$(all_event_log_tags_src)))
    410 
    411 $(event_log_tags_file): PRIVATE_SRC_FILES := $(event_log_tags_src) $(pdk_fusion_log_tags_file)
    412 $(event_log_tags_file): PRIVATE_MERGED_FILE := $(all_event_log_tags_file)
    413 $(event_log_tags_file): $(event_log_tags_src) $(all_event_log_tags_file) $(pdk_fusion_log_tags_file)
    414 	$(hide) mkdir -p $(dir $@)
    415 	$(hide) build/tools/merge-event-log-tags.py -o $@ -m $(PRIVATE_MERGED_FILE) $(PRIVATE_SRC_FILES)
    416 
    417 event-log-tags: $(event_log_tags_file)
    418 
    419 ALL_DEFAULT_INSTALLED_MODULES += $(event_log_tags_file)
    420 
    421 
    422 # #################################################################
    423 # Targets for boot/OS images
    424 # #################################################################
    425 ifneq ($(strip $(TARGET_NO_BOOTLOADER)),true)
    426   INSTALLED_BOOTLOADER_MODULE := $(PRODUCT_OUT)/bootloader
    427   ifeq ($(strip $(TARGET_BOOTLOADER_IS_2ND)),true)
    428     INSTALLED_2NDBOOTLOADER_TARGET := $(PRODUCT_OUT)/2ndbootloader
    429   else
    430     INSTALLED_2NDBOOTLOADER_TARGET :=
    431   endif
    432 else
    433   INSTALLED_BOOTLOADER_MODULE :=
    434   INSTALLED_2NDBOOTLOADER_TARGET :=
    435 endif # TARGET_NO_BOOTLOADER
    436 ifneq ($(strip $(TARGET_NO_KERNEL)),true)
    437   INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
    438 else
    439   INSTALLED_KERNEL_TARGET :=
    440 endif
    441 
    442 # -----------------------------------------------------------------
    443 # the ramdisk
    444 INTERNAL_RAMDISK_FILES := $(filter $(TARGET_ROOT_OUT)/%, \
    445 	$(ALL_PREBUILT) \
    446 	$(ALL_COPIED_HEADERS) \
    447 	$(ALL_GENERATED_SOURCES) \
    448 	$(ALL_DEFAULT_INSTALLED_MODULES))
    449 
    450 BUILT_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img
    451 
    452 # We just build this directly to the install location.
    453 INSTALLED_RAMDISK_TARGET := $(BUILT_RAMDISK_TARGET)
    454 $(INSTALLED_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_RAMDISK_FILES) | $(MINIGZIP)
    455 	$(call pretty,"Target ram disk: $@")
    456 	$(hide) $(MKBOOTFS) $(TARGET_ROOT_OUT) | $(MINIGZIP) > $@
    457 
    458 .PHONY: ramdisk-nodeps
    459 ramdisk-nodeps: $(MKBOOTFS) | $(MINIGZIP)
    460 	@echo "make $@: ignoring dependencies"
    461 	$(hide) $(MKBOOTFS) $(TARGET_ROOT_OUT) | $(MINIGZIP) > $(INSTALLED_RAMDISK_TARGET)
    462 
    463 ifneq ($(strip $(TARGET_NO_KERNEL)),true)
    464 
    465 # -----------------------------------------------------------------
    466 # the boot image, which is a collection of other images.
    467 INTERNAL_BOOTIMAGE_ARGS := \
    468 	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
    469 	--kernel $(INSTALLED_KERNEL_TARGET) \
    470 	--ramdisk $(INSTALLED_RAMDISK_TARGET)
    471 
    472 INTERNAL_BOOTIMAGE_FILES := $(filter-out --%,$(INTERNAL_BOOTIMAGE_ARGS))
    473 
    474 BOARD_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE))
    475 ifdef BOARD_KERNEL_CMDLINE
    476   INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)"
    477 endif
    478 
    479 BOARD_KERNEL_BASE := $(strip $(BOARD_KERNEL_BASE))
    480 ifdef BOARD_KERNEL_BASE
    481   INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
    482 endif
    483 
    484 BOARD_KERNEL_PAGESIZE := $(strip $(BOARD_KERNEL_PAGESIZE))
    485 ifdef BOARD_KERNEL_PAGESIZE
    486   INTERNAL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
    487 endif
    488 
    489 INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
    490 
    491 ifeq ($(TARGET_BOOTIMAGE_USE_EXT2),true)
    492 tmp_dir_for_image := $(call intermediates-dir-for,EXECUTABLES,boot_img)/bootimg
    493 INTERNAL_BOOTIMAGE_ARGS += --tmpdir $(tmp_dir_for_image)
    494 INTERNAL_BOOTIMAGE_ARGS += --genext2fs $(MKEXT2IMG)
    495 
    496 ifeq ($(TARGET_BOOTIMAGE_USE_EXTLINUX),true)
    497 INTERNAL_BOOTIMAGE_ARGS += --extlinuxconf $(TARGET_BOOTIMAGE_EXTLINUX_CONFIG)
    498 endif
    499 
    500 $(INSTALLED_BOOTIMAGE_TARGET): $(MKEXT2IMG) $(INTERNAL_BOOTIMAGE_FILES)
    501 	$(call pretty,"Target boot image: $@")
    502 	$(hide) $(MKEXT2BOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) --output $@
    503 
    504 .PHONY: bootimage-nodeps
    505 bootimage-nodeps: $(MKEXT2IMG)
    506 	@echo "make $@: ignoring dependencies"
    507 	$(hide) $(MKEXT2BOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
    508 
    509 else ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY)) # TARGET_BOOTIMAGE_USE_EXT2 != true
    510 
    511 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(BOOT_SIGNER)
    512 	$(call pretty,"Target boot image: $@")
    513 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
    514 	$(BOOT_SIGNER) /boot $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $@
    515 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    516 
    517 .PHONY: bootimage-nodeps
    518 bootimage-nodeps: $(MKBOOTIMG) $(BOOT_SIGNER)
    519 	@echo "make $@: ignoring dependencies"
    520 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
    521 	$(BOOT_SIGNER) /boot $(INSTALLED_BOOTIMAGE_TARGET) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $(INSTALLED_BOOTIMAGE_TARGET)
    522 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    523 
    524 else # PRODUCT_SUPPORTS_VERITY != true
    525 
    526 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES)
    527 	$(call pretty,"Target boot image: $@")
    528 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
    529 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    530 
    531 .PHONY: bootimage-nodeps
    532 bootimage-nodeps: $(MKBOOTIMG)
    533 	@echo "make $@: ignoring dependencies"
    534 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
    535 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    536 
    537 endif # TARGET_BOOTIMAGE_USE_EXT2
    538 
    539 else	# TARGET_NO_KERNEL
    540 # HACK: The top-level targets depend on the bootimage.  Not all targets
    541 # can produce a bootimage, though, and emulator targets need the ramdisk
    542 # instead.  Fake it out by calling the ramdisk the bootimage.
    543 # TODO: make the emulator use bootimages, and make mkbootimg accept
    544 #       kernel-less inputs.
    545 INSTALLED_BOOTIMAGE_TARGET := $(INSTALLED_RAMDISK_TARGET)
    546 endif
    547 
    548 # -----------------------------------------------------------------
    549 # NOTICE files
    550 #
    551 # We are required to publish the licenses for all code under BSD, GPL and
    552 # Apache licenses (and possibly other more exotic ones as well). We err on the
    553 # side of caution, so the licenses for other third-party code are included here
    554 # too.
    555 #
    556 # This needs to be before the systemimage rules, because it adds to
    557 # ALL_DEFAULT_INSTALLED_MODULES, which those use to pick which files
    558 # go into the systemimage.
    559 
    560 .PHONY: notice_files
    561 
    562 # Create the rule to combine the files into text and html forms
    563 # $(1) - Plain text output file
    564 # $(2) - HTML output file
    565 # $(3) - File title
    566 # $(4) - Directory to use.  Notice files are all $(4)/src.  Other
    567 #		 directories in there will be used for scratch
    568 # $(5) - Dependencies for the output files
    569 #
    570 # The algorithm here is that we go collect a hash for each of the notice
    571 # files and write the names of the files that match that hash.  Then
    572 # to generate the real files, we go print out all of the files and their
    573 # hashes.
    574 #
    575 # These rules are fairly complex, so they depend on this makefile so if
    576 # it changes, they'll run again.
    577 #
    578 # TODO: We could clean this up so that we just record the locations of the
    579 # original notice files instead of making rules to copy them somwehere.
    580 # Then we could traverse that without quite as much bash drama.
    581 define combine-notice-files
    582 $(1) $(2): PRIVATE_MESSAGE := $(3)
    583 $(1) $(2): PRIVATE_DIR := $(4)
    584 $(1) : $(2)
    585 $(2) : $(5) $(BUILD_SYSTEM)/Makefile build/tools/generate-notice-files.py
    586 	build/tools/generate-notice-files.py $(1) $(2) $$(PRIVATE_MESSAGE) $$(PRIVATE_DIR)/src
    587 notice_files: $(1) $(2)
    588 endef
    589 
    590 # TODO These intermediate NOTICE.txt/NOTICE.html files should go into
    591 # TARGET_OUT_NOTICE_FILES now that the notice files are gathered from
    592 # the src subdirectory.
    593 
    594 target_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE.txt
    595 target_notice_file_html := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html
    596 target_notice_file_html_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html.gz
    597 tools_notice_file_txt := $(HOST_OUT_INTERMEDIATES)/NOTICE.txt
    598 tools_notice_file_html := $(HOST_OUT_INTERMEDIATES)/NOTICE.html
    599 
    600 ifndef TARGET_BUILD_APPS
    601 kernel_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/kernel.txt
    602 pdk_fusion_notice_files := $(filter $(TARGET_OUT_NOTICE_FILES)/%, $(ALL_PDK_FUSION_FILES))
    603 
    604 $(eval $(call combine-notice-files, \
    605 			$(target_notice_file_txt), \
    606 			$(target_notice_file_html), \
    607 			"Notices for files contained in the filesystem images in this directory:", \
    608 			$(TARGET_OUT_NOTICE_FILES), \
    609 			$(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file) $(pdk_fusion_notice_files)))
    610 
    611 $(eval $(call combine-notice-files, \
    612 			$(tools_notice_file_txt), \
    613 			$(tools_notice_file_html), \
    614 			"Notices for files contained in the tools directory:", \
    615 			$(HOST_OUT_NOTICE_FILES), \
    616 			$(ALL_DEFAULT_INSTALLED_MODULES)))
    617 
    618 # Install the html file at /system/etc/NOTICE.html.gz.
    619 # This is not ideal, but this is very late in the game, after a lot of
    620 # the module processing has already been done -- in fact, we used the
    621 # fact that all that has been done to get the list of modules that we
    622 # need notice files for.
    623 $(target_notice_file_html_gz): $(target_notice_file_html) | $(MINIGZIP)
    624 	$(hide) $(MINIGZIP) -9 < $< > $@
    625 installed_notice_html_gz := $(TARGET_OUT)/etc/NOTICE.html.gz
    626 $(installed_notice_html_gz): $(target_notice_file_html_gz) | $(ACP)
    627 	$(copy-file-to-target)
    628 
    629 # if we've been run my mm, mmm, etc, don't reinstall this every time
    630 ifeq ($(ONE_SHOT_MAKEFILE),)
    631 ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_gz)
    632 endif
    633 endif  # TARGET_BUILD_APPS
    634 
    635 # The kernel isn't really a module, so to get its module file in there, we
    636 # make the target NOTICE files depend on this particular file too, which will
    637 # then be in the right directory for the find in combine-notice-files to work.
    638 $(kernel_notice_file): \
    639 	    prebuilts/qemu-kernel/arm/LINUX_KERNEL_COPYING \
    640 	    | $(ACP)
    641 	@echo Copying: $@
    642 	$(hide) mkdir -p $(dir $@)
    643 	$(hide) $(ACP) $< $@
    644 
    645 
    646 # -----------------------------------------------------------------
    647 # Build a keystore with the authorized keys in it, used to verify the
    648 # authenticity of downloaded OTA packages.
    649 #
    650 # This rule adds to ALL_DEFAULT_INSTALLED_MODULES, so it needs to come
    651 # before the rules that use that variable to build the image.
    652 ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_ETC)/security/otacerts.zip
    653 $(TARGET_OUT_ETC)/security/otacerts.zip: KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
    654 $(TARGET_OUT_ETC)/security/otacerts.zip: $(addsuffix .x509.pem,$(DEFAULT_KEY_CERT_PAIR))
    655 	$(hide) rm -f $@
    656 	$(hide) mkdir -p $(dir $@)
    657 	$(hide) zip -qj $@ $<
    658 
    659 .PHONY: otacerts
    660 otacerts: $(TARGET_OUT_ETC)/security/otacerts.zip
    661 
    662 
    663 # #################################################################
    664 # Targets for user images
    665 # #################################################################
    666 
    667 INTERNAL_USERIMAGES_EXT_VARIANT :=
    668 ifeq ($(TARGET_USERIMAGES_USE_EXT2),true)
    669 INTERNAL_USERIMAGES_USE_EXT := true
    670 INTERNAL_USERIMAGES_EXT_VARIANT := ext2
    671 else
    672 ifeq ($(TARGET_USERIMAGES_USE_EXT3),true)
    673 INTERNAL_USERIMAGES_USE_EXT := true
    674 INTERNAL_USERIMAGES_EXT_VARIANT := ext3
    675 else
    676 ifeq ($(TARGET_USERIMAGES_USE_EXT4),true)
    677 INTERNAL_USERIMAGES_USE_EXT := true
    678 INTERNAL_USERIMAGES_EXT_VARIANT := ext4
    679 endif
    680 endif
    681 endif
    682 
    683 # These options tell the recovery updater/installer how to mount the partitions writebale.
    684 # <fstype>=<fstype_opts>[|<fstype_opts>]...
    685 # fstype_opts := <opt>[,<opt>]...
    686 #         opt := <name>[=<value>]
    687 # The following worked on Nexus devices with Kernel 3.1, 3.4, 3.10
    688 DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS := ext4=max_batch_time=0,commit=1,data=ordered,barrier=1,errors=panic,nodelalloc
    689 
    690 ifneq (true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED))
    691   INTERNAL_USERIMAGES_SPARSE_EXT_FLAG := -s
    692 endif
    693 
    694 ifeq ($(INTERNAL_USERIMAGES_USE_EXT),true)
    695 INTERNAL_USERIMAGES_DEPS := $(SIMG2IMG)
    696 INTERNAL_USERIMAGES_DEPS += $(MKEXTUSERIMG) $(MAKE_EXT4FS) $(E2FSCK)
    697 ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
    698 INTERNAL_USERIMAGES_DEPS += $(MKF2FSUSERIMG) $(MAKE_F2FS)
    699 endif
    700 else
    701 INTERNAL_USERIMAGES_DEPS := $(MKYAFFS2)
    702 endif
    703 
    704 INTERNAL_USERIMAGES_BINARY_PATHS := $(sort $(dir $(INTERNAL_USERIMAGES_DEPS)))
    705 
    706 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY))
    707 INTERNAL_USERIMAGES_DEPS += $(BUILD_VERITY_TREE) $(APPEND2SIMG) $(VERITY_SIGNER)
    708 endif
    709 
    710 SELINUX_FC := $(TARGET_ROOT_OUT)/file_contexts
    711 INTERNAL_USERIMAGES_DEPS += $(SELINUX_FC)
    712 
    713 # $(1): the path of the output dictionary file
    714 # $(2): additional "key=value" pairs to append to the dictionary file.
    715 define generate-userimage-prop-dictionary
    716 $(if $(INTERNAL_USERIMAGES_EXT_VARIANT),$(hide) echo "fs_type=$(INTERNAL_USERIMAGES_EXT_VARIANT)" >> $(1))
    717 $(if $(BOARD_SYSTEMIMAGE_PARTITION_SIZE),$(hide) echo "system_size=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE)" >> $(1))
    718 $(if $(BOARD_SYSTEMIMAGE_JOURNAL_SIZE),$(hide) echo "system_journal_size=$(BOARD_SYSTEMIMAGE_JOURNAL_SIZE)" >> $(1))
    719 $(if $(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "userdata_fs_type=$(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    720 $(if $(BOARD_USERDATAIMAGE_PARTITION_SIZE),$(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(1))
    721 $(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    722 $(if $(BOARD_CACHEIMAGE_PARTITION_SIZE),$(hide) echo "cache_size=$(BOARD_CACHEIMAGE_PARTITION_SIZE)" >> $(1))
    723 $(if $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "vendor_fs_type=$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    724 $(if $(BOARD_VENDORIMAGE_PARTITION_SIZE),$(hide) echo "vendor_size=$(BOARD_VENDORIMAGE_PARTITION_SIZE)" >> $(1))
    725 $(if $(BOARD_VENDORIMAGE_JOURNAL_SIZE),$(hide) echo "vendor_journal_size=$(BOARD_VENDORIMAGE_JOURNAL_SIZE)" >> $(1))
    726 $(if $(BOARD_OEMIMAGE_PARTITION_SIZE),$(hide) echo "oem_size=$(BOARD_OEMIMAGE_PARTITION_SIZE)" >> $(1))
    727 $(if $(BOARD_OEMIMAGE_JOURNAL_SIZE),$(hide) echo "oem_journal_size=$(BOARD_OEMIMAGE_JOURNAL_SIZE)" >> $(1))
    728 $(if $(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG),$(hide) echo "extfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG)" >> $(1))
    729 $(if $(mkyaffs2_extra_flags),$(hide) echo "mkyaffs2_extra_flags=$(mkyaffs2_extra_flags)" >> $(1))
    730 $(hide) echo "selinux_fc=$(SELINUX_FC)" >> $(1)
    731 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY)" >> $(1))
    732 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_key=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY)" >> $(1))
    733 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_signer_cmd=$(VERITY_SIGNER)" >> $(1))
    734 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION),$(hide) echo "system_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION)" >> $(1))
    735 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION),$(hide) echo "vendor_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION)" >> $(1))
    736 $(if $(2),$(hide) $(foreach kv,$(2),echo "$(kv)" >> $(1);))
    737 endef
    738 
    739 # -----------------------------------------------------------------
    740 # Recovery image
    741 
    742 # If neither TARGET_NO_KERNEL nor TARGET_NO_RECOVERY are true
    743 ifeq (,$(filter true, $(TARGET_NO_KERNEL) $(TARGET_NO_RECOVERY)))
    744 
    745 INSTALLED_RECOVERYIMAGE_TARGET := $(PRODUCT_OUT)/recovery.img
    746 
    747 recovery_initrc := $(call include-path-for, recovery)/etc/init.rc
    748 recovery_sepolicy := $(call intermediates-dir-for,ETC,sepolicy.recovery)/sepolicy.recovery
    749 recovery_kernel := $(INSTALLED_KERNEL_TARGET) # same as a non-recovery system
    750 recovery_ramdisk := $(PRODUCT_OUT)/ramdisk-recovery.img
    751 recovery_build_prop := $(INSTALLED_BUILD_PROP_TARGET)
    752 recovery_binary := $(call intermediates-dir-for,EXECUTABLES,recovery)/recovery
    753 recovery_resources_common := $(call include-path-for, recovery)/res
    754 
    755 # Set recovery_density to the density bucket of the device.
    756 recovery_density := unknown
    757 ifneq (,$(PRODUCT_AAPT_PREF_CONFIG))
    758 # If PRODUCT_AAPT_PREF_CONFIG includes a dpi bucket, then use that value.
    759 recovery_density := $(filter %dpi,$(PRODUCT_AAPT_PREF_CONFIG))
    760 else
    761 # Otherwise, use the default medium density.
    762 recovery_densities := mdpi
    763 endif
    764 
    765 ifneq (,$(wildcard $(recovery_resources_common)-$(recovery_density)))
    766 recovery_resources_common := $(recovery_resources_common)-$(recovery_density)
    767 else
    768 recovery_resources_common := $(recovery_resources_common)-xhdpi
    769 endif
    770 
    771 # Select the 18x32 font on high-density devices (xhdpi and up); and
    772 # the 12x22 font on other devices.  Note that the font selected here
    773 # can be overridden for a particular device by putting a font.png in
    774 # its private recovery resources.
    775 
    776 ifneq (,$(filter xxxhdpi xxhdpi xhdpi,$(recovery_density)))
    777 recovery_font := $(call include-path-for, recovery)/fonts/18x32.png
    778 else
    779 recovery_font := $(call include-path-for, recovery)/fonts/12x22.png
    780 endif
    781 
    782 recovery_resources_private := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery/res))
    783 recovery_resource_deps := $(shell find $(recovery_resources_common) \
    784   $(recovery_resources_private) -type f)
    785 ifdef TARGET_RECOVERY_FSTAB
    786 recovery_fstab := $(TARGET_RECOVERY_FSTAB)
    787 else
    788 recovery_fstab := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery.fstab))
    789 endif
    790 # Named '.dat' so we don't attempt to use imgdiff for patching it.
    791 RECOVERY_RESOURCE_ZIP := $(TARGET_OUT)/etc/recovery-resource.dat
    792 
    793 ifeq ($(recovery_resources_private),)
    794   $(info No private recovery resources for TARGET_DEVICE $(TARGET_DEVICE))
    795 endif
    796 
    797 ifeq ($(recovery_fstab),)
    798   $(info No recovery.fstab for TARGET_DEVICE $(TARGET_DEVICE))
    799 endif
    800 
    801 INTERNAL_RECOVERYIMAGE_ARGS := \
    802 	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
    803 	--kernel $(recovery_kernel) \
    804 	--ramdisk $(recovery_ramdisk)
    805 
    806 # Assumes this has already been stripped
    807 ifdef BOARD_KERNEL_CMDLINE
    808   INTERNAL_RECOVERYIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)"
    809 endif
    810 ifdef BOARD_KERNEL_BASE
    811   INTERNAL_RECOVERYIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
    812 endif
    813 BOARD_KERNEL_PAGESIZE := $(strip $(BOARD_KERNEL_PAGESIZE))
    814 ifdef BOARD_KERNEL_PAGESIZE
    815   INTERNAL_RECOVERYIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
    816 endif
    817 
    818 # Keys authorized to sign OTA packages this build will accept.  The
    819 # build always uses dev-keys for this; release packaging tools will
    820 # substitute other keys for this one.
    821 OTA_PUBLIC_KEYS := $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem
    822 
    823 # Generate a file containing the keys that will be read by the
    824 # recovery binary.
    825 RECOVERY_INSTALL_OTA_KEYS := \
    826 	$(call intermediates-dir-for,PACKAGING,ota_keys)/keys
    827 DUMPKEY_JAR := $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar
    828 $(RECOVERY_INSTALL_OTA_KEYS): PRIVATE_OTA_PUBLIC_KEYS := $(OTA_PUBLIC_KEYS)
    829 $(RECOVERY_INSTALL_OTA_KEYS): extra_keys := $(patsubst %,%.x509.pem,$(PRODUCT_EXTRA_RECOVERY_KEYS))
    830 $(RECOVERY_INSTALL_OTA_KEYS): $(OTA_PUBLIC_KEYS) $(DUMPKEY_JAR) $(extra_keys)
    831 	@echo "DumpPublicKey: $@ <= $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys)"
    832 	@rm -rf $@
    833 	@mkdir -p $(dir $@)
    834 	java -jar $(DUMPKEY_JAR) $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys) > $@
    835 
    836 $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
    837 		$(INSTALLED_RAMDISK_TARGET) \
    838 		$(INSTALLED_BOOTIMAGE_TARGET) \
    839 		$(recovery_binary) \
    840 		$(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
    841 		$(INSTALLED_2NDBOOTLOADER_TARGET) \
    842 		$(recovery_build_prop) $(recovery_resource_deps) \
    843 		$(recovery_fstab) \
    844 		$(RECOVERY_INSTALL_OTA_KEYS)
    845 	@echo ----- Making recovery image ------
    846 	$(hide) rm -rf $(TARGET_RECOVERY_OUT)
    847 	$(hide) mkdir -p $(TARGET_RECOVERY_OUT)
    848 	$(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/etc $(TARGET_RECOVERY_ROOT_OUT)/tmp
    849 	@echo Copying baseline ramdisk...
    850 	$(hide) cp -R $(TARGET_ROOT_OUT) $(TARGET_RECOVERY_OUT)
    851 	@echo Modifying ramdisk contents...
    852 	$(hide) rm -f $(TARGET_RECOVERY_ROOT_OUT)/init*.rc
    853 	$(hide) cp -f $(recovery_initrc) $(TARGET_RECOVERY_ROOT_OUT)/
    854 	$(hide) rm -f $(TARGET_RECOVERY_ROOT_OUT)/sepolicy
    855 	$(hide) cp -f $(recovery_sepolicy) $(TARGET_RECOVERY_ROOT_OUT)/sepolicy
    856 	$(hide) -cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/
    857 	$(hide) cp -f $(recovery_binary) $(TARGET_RECOVERY_ROOT_OUT)/sbin/
    858 	$(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/res
    859 	$(hide) rm -rf $(TARGET_RECOVERY_ROOT_OUT)/res/*
    860 	$(hide) cp -rf $(recovery_resources_common)/* $(TARGET_RECOVERY_ROOT_OUT)/res
    861 	$(hide) cp -f $(recovery_font) $(TARGET_RECOVERY_ROOT_OUT)/res/images/font.png
    862 	$(hide) $(foreach item,$(recovery_resources_private), \
    863 	  cp -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/)
    864 	$(hide) $(foreach item,$(recovery_fstab), \
    865 	  cp -f $(item) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.fstab)
    866 	$(hide) cp $(RECOVERY_INSTALL_OTA_KEYS) $(TARGET_RECOVERY_ROOT_OUT)/res/keys
    867 	$(hide) cat $(INSTALLED_DEFAULT_PROP_TARGET) $(recovery_build_prop) \
    868 	        > $(TARGET_RECOVERY_ROOT_OUT)/default.prop
    869 	$(hide) $(MKBOOTFS) $(TARGET_RECOVERY_ROOT_OUT) | $(MINIGZIP) > $(recovery_ramdisk)
    870 	$(hide) $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
    871 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY))
    872 	$(BOOT_SIGNER) /recovery $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $@
    873 endif
    874 	$(hide) $(call assert-max-image-size,$@,$(BOARD_RECOVERYIMAGE_PARTITION_SIZE))
    875 	@echo ----- Made recovery image: $@ --------
    876 
    877 $(RECOVERY_RESOURCE_ZIP): $(INSTALLED_RECOVERYIMAGE_TARGET)
    878 	$(hide) mkdir -p $(dir $@)
    879 	$(hide) find $(TARGET_RECOVERY_ROOT_OUT)/res -type f | sort | zip -0qrj $@ -@
    880 
    881 else
    882 INSTALLED_RECOVERYIMAGE_TARGET :=
    883 RECOVERY_RESOURCE_ZIP :=
    884 endif
    885 
    886 .PHONY: recoveryimage
    887 recoveryimage: $(INSTALLED_RECOVERYIMAGE_TARGET) $(RECOVERY_RESOURCE_ZIP)
    888 
    889 ifneq ($(BOARD_NAND_PAGE_SIZE),)
    890 mkyaffs2_extra_flags := -c $(BOARD_NAND_PAGE_SIZE)
    891 else
    892 mkyaffs2_extra_flags :=
    893 BOARD_NAND_PAGE_SIZE := 2048
    894 endif
    895 
    896 ifneq ($(BOARD_NAND_SPARE_SIZE),)
    897 mkyaffs2_extra_flags += -s $(BOARD_NAND_SPARE_SIZE)
    898 else
    899 BOARD_NAND_SPARE_SIZE := 64
    900 endif
    901 
    902 # -----------------------------------------------------------------
    903 # system image
    904 #
    905 # Remove overridden packages from $(ALL_PDK_FUSION_FILES)
    906 PDK_FUSION_SYSIMG_FILES := \
    907     $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
    908         $(ALL_PDK_FUSION_FILES))
    909 
    910 INTERNAL_SYSTEMIMAGE_FILES := $(filter $(TARGET_OUT)/%, \
    911     $(ALL_PREBUILT) \
    912     $(ALL_COPIED_HEADERS) \
    913     $(ALL_GENERATED_SOURCES) \
    914     $(ALL_DEFAULT_INSTALLED_MODULES) \
    915     $(PDK_FUSION_SYSIMG_FILES) \
    916     $(RECOVERY_RESOURCE_ZIP))
    917 
    918 FULL_SYSTEMIMAGE_DEPS := $(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_USERIMAGES_DEPS)
    919 # -----------------------------------------------------------------
    920 # installed file list
    921 # Depending on anything that $(BUILT_SYSTEMIMAGE) depends on.
    922 # We put installed-files.txt ahead of image itself in the dependency graph
    923 # so that we can get the size stat even if the build fails due to too large
    924 # system image.
    925 INSTALLED_FILES_FILE := $(PRODUCT_OUT)/installed-files.txt
    926 $(INSTALLED_FILES_FILE): $(FULL_SYSTEMIMAGE_DEPS)
    927 	@echo Installed file list: $@
    928 	@mkdir -p $(dir $@)
    929 	@rm -f $@
    930 	$(hide) build/tools/fileslist.py $(TARGET_OUT) > $@
    931 
    932 .PHONY: installed-file-list
    933 installed-file-list: $(INSTALLED_FILES_FILE)
    934 
    935 $(call dist-for-goals, sdk win_sdk sdk_addon, $(INSTALLED_FILES_FILE))
    936 
    937 systemimage_intermediates := \
    938     $(call intermediates-dir-for,PACKAGING,systemimage)
    939 BUILT_SYSTEMIMAGE := $(systemimage_intermediates)/system.img
    940 
    941 # Create symlink /system/vendor to /vendor if necessary.
    942 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
    943 define create-system-vendor-symlink
    944 $(hide) if [ -d $(TARGET_OUT)/vendor ] && [ ! -h $(TARGET_OUT)/vendor ]; then \
    945   echo 'Non-symlink $(TARGET_OUT)/vendor detected!' 1>&2; \
    946   echo 'You cannot install files to $(TARGET_OUT)/vendor while building a separate vendor.img!' 1>&2; \
    947   exit 1; \
    948 fi
    949 $(hide) ln -sf /vendor $(TARGET_OUT)/vendor
    950 endef
    951 else
    952 define create-system-vendor-symlink
    953 endef
    954 endif
    955 
    956 # $(1): output file
    957 define build-systemimage-target
    958   @echo "Target system fs image: $(1)"
    959   $(call create-system-vendor-symlink)
    960   @mkdir -p $(dir $(1)) $(systemimage_intermediates) && rm -rf $(systemimage_intermediates)/system_image_info.txt
    961   $(call generate-userimage-prop-dictionary, $(systemimage_intermediates)/system_image_info.txt, \
    962       skip_fsck=true)
    963   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
    964       ./build/tools/releasetools/build_image.py \
    965       $(TARGET_OUT) $(systemimage_intermediates)/system_image_info.txt $(1) \
    966       || ( echo "Out of space? the tree size of $(TARGET_OUT) is (MB): " 1>&2 ;\
    967            du -sm $(TARGET_OUT) 1>&2;\
    968            echo "The max is $$(( $(BOARD_SYSTEMIMAGE_PARTITION_SIZE) / 1048576 )) MB." 1>&2 ;\
    969            mkdir -p $(DIST_DIR); cp $(INSTALLED_FILES_FILE) $(DIST_DIR)/installed-files-rescued.txt; \
    970            exit 1 )
    971 endef
    972 
    973 $(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE)
    974 	$(call build-systemimage-target,$@)
    975 
    976 INSTALLED_SYSTEMIMAGE := $(PRODUCT_OUT)/system.img
    977 SYSTEMIMAGE_SOURCE_DIR := $(TARGET_OUT)
    978 
    979 # The system partition needs room for the recovery image as well.  We
    980 # now store the recovery image as a binary patch using the boot image
    981 # as the source (since they are very similar).  Generate the patch so
    982 # we can see how big it's going to be, and include that in the system
    983 # image size check calculation.
    984 ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
    985 intermediates := $(call intermediates-dir-for,PACKAGING,recovery_patch)
    986 RECOVERY_FROM_BOOT_PATCH := $(intermediates)/recovery_from_boot.p
    987 $(RECOVERY_FROM_BOOT_PATCH): $(INSTALLED_RECOVERYIMAGE_TARGET) \
    988                              $(INSTALLED_BOOTIMAGE_TARGET) \
    989 			     $(HOST_OUT_EXECUTABLES)/imgdiff \
    990 	                     $(HOST_OUT_EXECUTABLES)/bsdiff
    991 	@echo "Construct recovery from boot"
    992 	mkdir -p $(dir $@)
    993 	PATH=$(HOST_OUT_EXECUTABLES):$$PATH $(HOST_OUT_EXECUTABLES)/imgdiff $(INSTALLED_BOOTIMAGE_TARGET) $(INSTALLED_RECOVERYIMAGE_TARGET) $@
    994 endif
    995 
    996 
    997 $(INSTALLED_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE) $(RECOVERY_FROM_BOOT_PATCH) | $(ACP)
    998 	@echo "Install system fs image: $@"
    999 	$(copy-file-to-target)
   1000 	$(hide) $(call assert-max-image-size,$@ $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
   1001 
   1002 systemimage: $(INSTALLED_SYSTEMIMAGE)
   1003 
   1004 .PHONY: systemimage-nodeps snod
   1005 systemimage-nodeps snod: $(filter-out systemimage-nodeps snod,$(MAKECMDGOALS)) \
   1006 	            | $(INTERNAL_USERIMAGES_DEPS)
   1007 	@echo "make $@: ignoring dependencies"
   1008 	$(call build-systemimage-target,$(INSTALLED_SYSTEMIMAGE))
   1009 	$(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMIMAGE),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
   1010 
   1011 ifneq (,$(filter systemimage-nodeps snod, $(MAKECMDGOALS)))
   1012 ifeq (true,$(WITH_DEXPREOPT))
   1013 $(warning Warning: with dexpreopt enabled, you may need a full rebuild.)
   1014 endif
   1015 endif
   1016 
   1017 #######
   1018 ## system tarball
   1019 define build-systemtarball-target
   1020   $(call pretty,"Target system fs tarball: $(INSTALLED_SYSTEMTARBALL_TARGET)")
   1021   $(call create-system-vendor-symlink)
   1022   $(MKTARBALL) $(FS_GET_STATS) \
   1023     $(PRODUCT_OUT) system $(PRIVATE_SYSTEM_TAR) \
   1024     $(INSTALLED_SYSTEMTARBALL_TARGET)
   1025 endef
   1026 
   1027 ifndef SYSTEM_TARBALL_FORMAT
   1028     SYSTEM_TARBALL_FORMAT := bz2
   1029 endif
   1030 
   1031 system_tar := $(PRODUCT_OUT)/system.tar
   1032 INSTALLED_SYSTEMTARBALL_TARGET := $(system_tar).$(SYSTEM_TARBALL_FORMAT)
   1033 $(INSTALLED_SYSTEMTARBALL_TARGET): PRIVATE_SYSTEM_TAR := $(system_tar)
   1034 $(INSTALLED_SYSTEMTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_SYSTEMIMAGE_FILES)
   1035 	$(build-systemtarball-target)
   1036 
   1037 .PHONY: systemtarball-nodeps
   1038 systemtarball-nodeps: $(FS_GET_STATS) \
   1039                       $(filter-out systemtarball-nodeps stnod,$(MAKECMDGOALS))
   1040 	$(build-systemtarball-target)
   1041 
   1042 .PHONY: stnod
   1043 stnod: systemtarball-nodeps
   1044 
   1045 #######
   1046 ## platform.zip: system, plus other files to be used in PDK fusion build,
   1047 ## in a zip file
   1048 ##
   1049 ## PDK_PLATFORM_ZIP_PRODUCT_BINARIES is used to store specified files to platform.zip.
   1050 ## The variable will be typically set from BoardConfig.mk.
   1051 ## Files under out dir will be rejected to prevent possible conflicts with other rules.
   1052 PDK_PLATFORM_ZIP_PRODUCT_BINARIES := $(filter-out $(OUT_DIR)/%,$(PDK_PLATFORM_ZIP_PRODUCT_BINARIES))
   1053 INSTALLED_PLATFORM_ZIP := $(PRODUCT_OUT)/platform.zip
   1054 $(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES)
   1055 	$(call pretty,"Platform zip package: $(INSTALLED_PLATFORM_ZIP)")
   1056 	$(hide) rm -f $@
   1057 	$(hide) cd $(dir $@) && zip -qry $(notdir $@) \
   1058 		$(TARGET_COPY_OUT_SYSTEM) \
   1059 		$(patsubst $(PRODUCT_OUT)/%, %, $(TARGET_OUT_NOTICE_FILES)) \
   1060 		$(addprefix symbols/,$(PDK_SYMBOL_FILES_LIST))
   1061 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1062 	$(hide) cd $(dir $@) && zip -qry $(notdir $@) \
   1063 		$(TARGET_COPY_OUT_VENDOR)
   1064 endif
   1065 ifneq ($(PDK_PLATFORM_JAVA_ZIP_CONTENTS),)
   1066 	$(hide) cd $(OUT_DIR) && zip -qry $(patsubst $(OUT_DIR)/%,%,$@) $(PDK_PLATFORM_JAVA_ZIP_CONTENTS)
   1067 endif
   1068 ifneq ($(PDK_PLATFORM_ZIP_PRODUCT_BINARIES),)
   1069 	$(hide) zip -qry $@ $(PDK_PLATFORM_ZIP_PRODUCT_BINARIES)
   1070 endif
   1071 
   1072 .PHONY: platform
   1073 platform: $(INSTALLED_PLATFORM_ZIP)
   1074 
   1075 .PHONY: platform-java
   1076 platform-java: platform
   1077 
   1078 # Dist the platform.zip
   1079 ifneq (,$(filter platform platform-java, $(MAKECMDGOALS)))
   1080 $(call dist-for-goals, platform platform-java, $(INSTALLED_PLATFORM_ZIP))
   1081 endif
   1082 
   1083 #######
   1084 ## boot tarball
   1085 define build-boottarball-target
   1086     $(hide) echo "Target boot fs tarball: $(INSTALLED_BOOTTARBALL_TARGET)"
   1087     $(hide) mkdir -p $(PRODUCT_OUT)/boot
   1088     $(hide) cp -f $(INTERNAL_BOOTIMAGE_FILES) $(PRODUCT_OUT)/boot/.
   1089     $(hide) echo $(BOARD_KERNEL_CMDLINE) > $(PRODUCT_OUT)/boot/cmdline
   1090     $(hide) $(MKTARBALL) $(FS_GET_STATS) \
   1091                  $(PRODUCT_OUT) boot $(PRIVATE_BOOT_TAR) \
   1092                  $(INSTALLED_BOOTTARBALL_TARGET)
   1093 endef
   1094 
   1095 ifndef BOOT_TARBALL_FORMAT
   1096     BOOT_TARBALL_FORMAT := bz2
   1097 endif
   1098 
   1099 boot_tar := $(PRODUCT_OUT)/boot.tar
   1100 INSTALLED_BOOTTARBALL_TARGET := $(boot_tar).$(BOOT_TARBALL_FORMAT)
   1101 $(INSTALLED_BOOTTARBALL_TARGET): PRIVATE_BOOT_TAR := $(boot_tar)
   1102 $(INSTALLED_BOOTTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_BOOTIMAGE_FILES)
   1103 	$(build-boottarball-target)
   1104 
   1105 .PHONY: boottarball-nodeps btnod
   1106 boottarball-nodeps btnod: $(FS_GET_STATS) \
   1107                       $(filter-out boottarball-nodeps btnod,$(MAKECMDGOALS))
   1108 	$(build-boottarball-target)
   1109 
   1110 
   1111 # -----------------------------------------------------------------
   1112 # data partition image
   1113 INTERNAL_USERDATAIMAGE_FILES := \
   1114     $(filter $(TARGET_OUT_DATA)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
   1115 
   1116 # Don't build userdata.img if it's extfs but no partition size
   1117 skip_userdata.img :=
   1118 ifdef INTERNAL_USERIMAGES_EXT_VARIANT
   1119 ifndef BOARD_USERDATAIMAGE_PARTITION_SIZE
   1120 skip_userdata.img := true
   1121 endif
   1122 endif
   1123 
   1124 ifneq ($(skip_userdata.img),true)
   1125 userdataimage_intermediates := \
   1126     $(call intermediates-dir-for,PACKAGING,userdata)
   1127 BUILT_USERDATAIMAGE_TARGET := $(PRODUCT_OUT)/userdata.img
   1128 
   1129 define build-userdataimage-target
   1130   $(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
   1131   @mkdir -p $(TARGET_OUT_DATA)
   1132   @mkdir -p $(userdataimage_intermediates) && rm -rf $(userdataimage_intermediates)/userdata_image_info.txt
   1133   $(call generate-userimage-prop-dictionary, $(userdataimage_intermediates)/userdata_image_info.txt, skip_fsck=true)
   1134   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1135       ./build/tools/releasetools/build_image.py \
   1136       $(TARGET_OUT_DATA) $(userdataimage_intermediates)/userdata_image_info.txt $(INSTALLED_USERDATAIMAGE_TARGET)
   1137   $(hide) $(call assert-max-image-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_PARTITION_SIZE))
   1138 endef
   1139 
   1140 # We just build this directly to the install location.
   1141 INSTALLED_USERDATAIMAGE_TARGET := $(BUILT_USERDATAIMAGE_TARGET)
   1142 $(INSTALLED_USERDATAIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) \
   1143                                    $(INTERNAL_USERDATAIMAGE_FILES)
   1144 	$(build-userdataimage-target)
   1145 
   1146 .PHONY: userdataimage-nodeps
   1147 userdataimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1148 	$(build-userdataimage-target)
   1149 
   1150 endif # not skip_userdata.img
   1151 skip_userdata.img :=
   1152 
   1153 #######
   1154 ## data partition tarball
   1155 define build-userdatatarball-target
   1156     $(call pretty,"Target userdata fs tarball: " \
   1157                   "$(INSTALLED_USERDATATARBALL_TARGET)")
   1158     $(MKTARBALL) $(FS_GET_STATS) \
   1159 		$(PRODUCT_OUT) data $(PRIVATE_USERDATA_TAR) \
   1160 		$(INSTALLED_USERDATATARBALL_TARGET)
   1161 endef
   1162 
   1163 userdata_tar := $(PRODUCT_OUT)/userdata.tar
   1164 INSTALLED_USERDATATARBALL_TARGET := $(userdata_tar).bz2
   1165 $(INSTALLED_USERDATATARBALL_TARGET): PRIVATE_USERDATA_TAR := $(userdata_tar)
   1166 $(INSTALLED_USERDATATARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_USERDATAIMAGE_FILES)
   1167 	$(build-userdatatarball-target)
   1168 
   1169 .PHONY: userdatatarball-nodeps
   1170 userdatatarball-nodeps: $(FS_GET_STATS)
   1171 	$(build-userdatatarball-target)
   1172 
   1173 
   1174 # -----------------------------------------------------------------
   1175 # cache partition image
   1176 ifdef BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
   1177 INTERNAL_CACHEIMAGE_FILES := \
   1178     $(filter $(TARGET_OUT_CACHE)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
   1179 
   1180 cacheimage_intermediates := \
   1181     $(call intermediates-dir-for,PACKAGING,cache)
   1182 BUILT_CACHEIMAGE_TARGET := $(PRODUCT_OUT)/cache.img
   1183 
   1184 define build-cacheimage-target
   1185   $(call pretty,"Target cache fs image: $(INSTALLED_CACHEIMAGE_TARGET)")
   1186   @mkdir -p $(TARGET_OUT_CACHE)
   1187   @mkdir -p $(cacheimage_intermediates) && rm -rf $(cacheimage_intermediates)/cache_image_info.txt
   1188   $(call generate-userimage-prop-dictionary, $(cacheimage_intermediates)/cache_image_info.txt, skip_fsck=true)
   1189   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1190       ./build/tools/releasetools/build_image.py \
   1191       $(TARGET_OUT_CACHE) $(cacheimage_intermediates)/cache_image_info.txt $(INSTALLED_CACHEIMAGE_TARGET)
   1192   $(hide) $(call assert-max-image-size,$(INSTALLED_CACHEIMAGE_TARGET),$(BOARD_CACHEIMAGE_PARTITION_SIZE))
   1193 endef
   1194 
   1195 # We just build this directly to the install location.
   1196 INSTALLED_CACHEIMAGE_TARGET := $(BUILT_CACHEIMAGE_TARGET)
   1197 $(INSTALLED_CACHEIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_CACHEIMAGE_FILES)
   1198 	$(build-cacheimage-target)
   1199 
   1200 .PHONY: cacheimage-nodeps
   1201 cacheimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1202 	$(build-cacheimage-target)
   1203 
   1204 endif # BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
   1205 
   1206 
   1207 # -----------------------------------------------------------------
   1208 # vendor partition image
   1209 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1210 INTERNAL_VENDORIMAGE_FILES := \
   1211     $(filter $(TARGET_OUT_VENDOR)/%,\
   1212       $(ALL_DEFAULT_INSTALLED_MODULES)\
   1213       $(ALL_PDK_FUSION_FILES))
   1214 
   1215 # platform.zip depends on $(INTERNAL_VENDORIMAGE_FILES).
   1216 $(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_VENDORIMAGE_FILES)
   1217 
   1218 vendorimage_intermediates := \
   1219     $(call intermediates-dir-for,PACKAGING,vendor)
   1220 BUILT_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
   1221 
   1222 define build-vendorimage-target
   1223   $(call pretty,"Target vendor fs image: $(INSTALLED_VENDORIMAGE_TARGET)")
   1224   @mkdir -p $(TARGET_OUT_VENDOR)
   1225   @mkdir -p $(vendorimage_intermediates) && rm -rf $(vendorimage_intermediates)/vendor_image_info.txt
   1226   $(call generate-userimage-prop-dictionary, $(vendorimage_intermediates)/vendor_image_info.txt, skip_fsck=true)
   1227   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1228       ./build/tools/releasetools/build_image.py \
   1229       $(TARGET_OUT_VENDOR) $(vendorimage_intermediates)/vendor_image_info.txt $(INSTALLED_VENDORIMAGE_TARGET)
   1230   $(hide) $(call assert-max-image-size,$(INSTALLED_VENDORIMAGE_TARGET),$(BOARD_VENDORIMAGE_PARTITION_SIZE))
   1231 endef
   1232 
   1233 # We just build this directly to the install location.
   1234 INSTALLED_VENDORIMAGE_TARGET := $(BUILT_VENDORIMAGE_TARGET)
   1235 $(INSTALLED_VENDORIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_VENDORIMAGE_FILES)
   1236 	$(build-vendorimage-target)
   1237 
   1238 .PHONY: vendorimage-nodeps
   1239 vendorimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1240 	$(build-vendorimage-target)
   1241 
   1242 endif # BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1243 
   1244 # -----------------------------------------------------------------
   1245 # bring in the installer image generation defines if necessary
   1246 ifeq ($(TARGET_USE_DISKINSTALLER),true)
   1247 include bootable/diskinstaller/config.mk
   1248 endif
   1249 
   1250 # -----------------------------------------------------------------
   1251 # host tools needed to build dist and OTA packages
   1252 
   1253 DISTTOOLS :=  $(HOST_OUT_EXECUTABLES)/minigzip \
   1254 	  $(HOST_OUT_EXECUTABLES)/mkbootfs \
   1255 	  $(HOST_OUT_EXECUTABLES)/mkbootimg \
   1256 	  $(HOST_OUT_EXECUTABLES)/fs_config \
   1257 	  $(HOST_OUT_EXECUTABLES)/mkyaffs2image \
   1258 	  $(HOST_OUT_EXECUTABLES)/zipalign \
   1259 	  $(HOST_OUT_EXECUTABLES)/bsdiff \
   1260 	  $(HOST_OUT_EXECUTABLES)/imgdiff \
   1261 	  $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar \
   1262 	  $(HOST_OUT_JAVA_LIBRARIES)/signapk.jar \
   1263 	  $(HOST_OUT_EXECUTABLES)/mkuserimg.sh \
   1264 	  $(HOST_OUT_EXECUTABLES)/make_ext4fs \
   1265 	  $(HOST_OUT_EXECUTABLES)/simg2img \
   1266 	  $(HOST_OUT_EXECUTABLES)/e2fsck \
   1267 	  $(HOST_OUT_EXECUTABLES)/build_verity_tree \
   1268 	  $(HOST_OUT_EXECUTABLES)/verity_signer \
   1269 	  $(HOST_OUT_EXECUTABLES)/append2simg \
   1270 	  $(HOST_OUT_EXECUTABLES)/boot_signer
   1271 
   1272 OTATOOLS := $(DISTTOOLS) \
   1273 	  $(HOST_OUT_EXECUTABLES)/aapt
   1274 
   1275 .PHONY: otatools
   1276 otatools: $(OTATOOLS)
   1277 
   1278 # -----------------------------------------------------------------
   1279 # A zip of the directories that map to the target filesystem.
   1280 # This zip can be used to create an OTA package or filesystem image
   1281 # as a post-build step.
   1282 #
   1283 name := $(TARGET_PRODUCT)
   1284 ifeq ($(TARGET_BUILD_TYPE),debug)
   1285   name := $(name)_debug
   1286 endif
   1287 name := $(name)-target_files-$(FILE_NAME_TAG)
   1288 
   1289 intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
   1290 BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
   1291 $(BUILT_TARGET_FILES_PACKAGE): intermediates := $(intermediates)
   1292 $(BUILT_TARGET_FILES_PACKAGE): \
   1293 		zip_root := $(intermediates)/$(name)
   1294 
   1295 # $(1): Directory to copy
   1296 # $(2): Location to copy it to
   1297 # The "ls -A" is to prevent "acp s/* d" from failing if s is empty.
   1298 define package_files-copy-root
   1299   if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
   1300     mkdir -p $(2) && \
   1301     $(ACP) -rd $(strip $(1))/* $(2); \
   1302   fi
   1303 endef
   1304 
   1305 built_ota_tools := \
   1306 	$(call intermediates-dir-for,EXECUTABLES,applypatch)/applypatch \
   1307 	$(call intermediates-dir-for,EXECUTABLES,applypatch_static)/applypatch_static \
   1308 	$(call intermediates-dir-for,EXECUTABLES,check_prereq)/check_prereq \
   1309 	$(call intermediates-dir-for,EXECUTABLES,sqlite3)/sqlite3 \
   1310 	$(call intermediates-dir-for,EXECUTABLES,updater)/updater
   1311 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_OTA_TOOLS := $(built_ota_tools)
   1312 
   1313 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_API_VERSION := $(RECOVERY_API_VERSION)
   1314 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_FSTAB_VERSION := $(RECOVERY_FSTAB_VERSION)
   1315 
   1316 ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
   1317 # default to common dir for device vendor
   1318 $(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_DEVICE_DIR)/../common
   1319 else
   1320 $(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
   1321 endif
   1322 
   1323 # Depending on the various images guarantees that the underlying
   1324 # directories are up-to-date.
   1325 $(BUILT_TARGET_FILES_PACKAGE): \
   1326 		$(INSTALLED_BOOTIMAGE_TARGET) \
   1327 		$(INSTALLED_RADIOIMAGE_TARGET) \
   1328 		$(INSTALLED_RECOVERYIMAGE_TARGET) \
   1329 		$(INSTALLED_SYSTEMIMAGE) \
   1330 		$(INSTALLED_USERDATAIMAGE_TARGET) \
   1331 		$(INSTALLED_CACHEIMAGE_TARGET) \
   1332 		$(INSTALLED_VENDORIMAGE_TARGET) \
   1333 		$(INSTALLED_ANDROID_INFO_TXT_TARGET) \
   1334 		$(SELINUX_FC) \
   1335 		$(built_ota_tools) \
   1336 		$(APKCERTS_FILE) \
   1337 		$(HOST_OUT_EXECUTABLES)/fs_config \
   1338 		| $(ACP)
   1339 	@echo "Package target files: $@"
   1340 	$(hide) rm -rf $@ $(zip_root)
   1341 	$(hide) mkdir -p $(dir $@) $(zip_root)
   1342 	@# Components of the recovery image
   1343 	$(hide) mkdir -p $(zip_root)/RECOVERY
   1344 	$(hide) $(call package_files-copy-root, \
   1345 		$(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/RECOVERY/RAMDISK)
   1346 ifdef INSTALLED_KERNEL_TARGET
   1347 	$(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/RECOVERY/kernel
   1348 endif
   1349 ifdef INSTALLED_2NDBOOTLOADER_TARGET
   1350 	$(hide) $(ACP) \
   1351 		$(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/RECOVERY/second
   1352 endif
   1353 ifdef BOARD_KERNEL_CMDLINE
   1354 	$(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/RECOVERY/cmdline
   1355 endif
   1356 ifdef BOARD_KERNEL_BASE
   1357 	$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/RECOVERY/base
   1358 endif
   1359 ifdef BOARD_KERNEL_PAGESIZE
   1360 	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/RECOVERY/pagesize
   1361 endif
   1362 	@# Components of the boot image
   1363 	$(hide) mkdir -p $(zip_root)/BOOT
   1364 	$(hide) $(call package_files-copy-root, \
   1365 		$(TARGET_ROOT_OUT),$(zip_root)/BOOT/RAMDISK)
   1366 ifdef INSTALLED_KERNEL_TARGET
   1367 	$(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/kernel
   1368 endif
   1369 ifdef INSTALLED_2NDBOOTLOADER_TARGET
   1370 	$(hide) $(ACP) \
   1371 		$(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second
   1372 endif
   1373 ifdef BOARD_KERNEL_CMDLINE
   1374 	$(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
   1375 endif
   1376 ifdef BOARD_KERNEL_BASE
   1377 	$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base
   1378 endif
   1379 ifdef BOARD_KERNEL_PAGESIZE
   1380 	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesize
   1381 endif
   1382 	$(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\
   1383 	            mkdir -p $(zip_root)/RADIO; \
   1384 	            $(ACP) $(t) $(zip_root)/RADIO/$(notdir $(t));)
   1385 	@# Contents of the system image
   1386 	$(hide) $(call package_files-copy-root, \
   1387 		$(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
   1388 	@# Contents of the data image
   1389 	$(hide) $(call package_files-copy-root, \
   1390 		$(TARGET_OUT_DATA),$(zip_root)/DATA)
   1391 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1392 	@# Contents of the vendor image
   1393 	$(hide) $(call package_files-copy-root, \
   1394 		$(TARGET_OUT_VENDOR),$(zip_root)/VENDOR)
   1395 endif
   1396 	@# Extra contents of the OTA package
   1397 	$(hide) mkdir -p $(zip_root)/OTA/bin
   1398 	$(hide) $(ACP) $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/
   1399 	$(hide) $(ACP) $(PRIVATE_OTA_TOOLS) $(zip_root)/OTA/bin/
   1400 	@# Files that do not end up in any images, but are necessary to
   1401 	@# build them.
   1402 	$(hide) mkdir -p $(zip_root)/META
   1403 	$(hide) $(ACP) $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
   1404 	$(hide) if test -e $(tool_extensions)/releasetools.py; then $(ACP) $(tool_extensions)/releasetools.py $(zip_root)/META/; fi
   1405 	$(hide)	echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
   1406 	$(hide) echo "recovery_api_version=$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/misc_info.txt
   1407 	$(hide) echo "fstab_version=$(PRIVATE_RECOVERY_FSTAB_VERSION)" >> $(zip_root)/META/misc_info.txt
   1408 ifdef BOARD_FLASH_BLOCK_SIZE
   1409 	$(hide) echo "blocksize=$(BOARD_FLASH_BLOCK_SIZE)" >> $(zip_root)/META/misc_info.txt
   1410 endif
   1411 ifdef BOARD_BOOTIMAGE_PARTITION_SIZE
   1412 	$(hide) echo "boot_size=$(BOARD_BOOTIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
   1413 endif
   1414 ifdef BOARD_RECOVERYIMAGE_PARTITION_SIZE
   1415 	$(hide) echo "recovery_size=$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
   1416 endif
   1417 ifdef TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS
   1418 	@# TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS can be empty to indicate that nothing but defaults should be used.
   1419 	$(hide) echo "recovery_mount_options=$(TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $(zip_root)/META/misc_info.txt
   1420 else
   1421 	$(hide) echo "recovery_mount_options=$(DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $(zip_root)/META/misc_info.txt
   1422 endif
   1423 	$(hide) echo "tool_extensions=$(tool_extensions)" >> $(zip_root)/META/misc_info.txt
   1424 	$(hide) echo "default_system_dev_certificate=$(DEFAULT_SYSTEM_DEV_CERTIFICATE)" >> $(zip_root)/META/misc_info.txt
   1425 ifdef PRODUCT_EXTRA_RECOVERY_KEYS
   1426 	$(hide) echo "extra_recovery_keys=$(PRODUCT_EXTRA_RECOVERY_KEYS)" >> $(zip_root)/META/misc_info.txt
   1427 endif
   1428 	$(hide) echo 'mkbootimg_args=$(BOARD_MKBOOTIMG_ARGS)' >> $(zip_root)/META/misc_info.txt
   1429 	$(hide) echo "use_set_metadata=1" >> $(zip_root)/META/misc_info.txt
   1430 	$(hide) echo "multistage_support=1" >> $(zip_root)/META/misc_info.txt
   1431 	$(hide) echo "update_rename_support=1" >> $(zip_root)/META/misc_info.txt
   1432 	$(hide) echo "blockimgdiff_versions=1,2" >> $(zip_root)/META/misc_info.txt
   1433 ifneq ($(OEM_THUMBPRINT_PROPERTIES),)
   1434 	# OTA scripts are only interested in fingerprint related properties
   1435 	$(hide) echo "oem_fingerprint_properties=$(OEM_THUMBPRINT_PROPERTIES)" >> $(zip_root)/META/misc_info.txt
   1436 endif
   1437 	$(call generate-userimage-prop-dictionary, $(zip_root)/META/misc_info.txt)
   1438 	$(hide) ./build/tools/releasetools/make_recovery_patch $(zip_root) $(zip_root)
   1439 	@# Zip everything up, preserving symlinks
   1440 	$(hide) (cd $(zip_root) && zip -qry ../$(notdir $@) .)
   1441 	@# Run fs_config on all the system, vendor, boot ramdisk,
   1442 	@# and recovery ramdisk files in the zip, and save the output
   1443 	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="SYSTEM/" } /^SYSTEM\// {print "system/" $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/filesystem_config.txt
   1444 	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="VENDOR/" } /^VENDOR\// {print "vendor/" $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/vendor_filesystem_config.txt
   1445 	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="BOOT/RAMDISK/" } /^BOOT\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/boot_filesystem_config.txt
   1446 	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="RECOVERY/RAMDISK/" } /^RECOVERY\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/recovery_filesystem_config.txt
   1447 	$(hide) (cd $(zip_root) && zip -q ../$(notdir $@) META/*filesystem_config.txt)
   1448 	$(hide) ./build/tools/releasetools/add_img_to_target_files -p $(HOST_OUT) $@
   1449 
   1450 .PHONY: target-files-package
   1451 target-files-package: $(BUILT_TARGET_FILES_PACKAGE)
   1452 
   1453 ifneq ($(filter $(MAKECMDGOALS),target-files-package),)
   1454 $(call dist-for-goals, target-files-package, $(BUILT_TARGET_FILES_PACKAGE))
   1455 endif
   1456 
   1457 ifneq ($(TARGET_PRODUCT),sdk)
   1458 ifeq ($(filter generic%,$(TARGET_DEVICE)),)
   1459 ifneq ($(TARGET_NO_KERNEL),true)
   1460 ifneq ($(recovery_fstab),)
   1461 
   1462 # -----------------------------------------------------------------
   1463 # OTA update package
   1464 
   1465 name := $(TARGET_PRODUCT)
   1466 ifeq ($(TARGET_BUILD_TYPE),debug)
   1467   name := $(name)_debug
   1468 endif
   1469 name := $(name)-ota-$(FILE_NAME_TAG)
   1470 
   1471 INTERNAL_OTA_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   1472 
   1473 $(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
   1474 
   1475 $(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(DISTTOOLS)
   1476 	@echo "Package OTA: $@"
   1477 	$(hide) MKBOOTIMG=$(MKBOOTIMG) \
   1478 	   ./build/tools/releasetools/ota_from_target_files -v \
   1479 	   --block \
   1480 	   -p $(HOST_OUT) \
   1481 	   -k $(KEY_CERT_PAIR) \
   1482 	   $(if $(OEM_OTA_CONFIG), -o $(OEM_OTA_CONFIG)) \
   1483 	   $(BUILT_TARGET_FILES_PACKAGE) $@
   1484 
   1485 .PHONY: otapackage
   1486 otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)
   1487 
   1488 endif    # recovery_fstab is defined
   1489 endif    # TARGET_NO_KERNEL != true
   1490 endif    # TARGET_DEVICE != generic*
   1491 endif    # TARGET_PRODUCT != sdk
   1492 
   1493 # -----------------------------------------------------------------
   1494 # The update package
   1495 
   1496 name := $(TARGET_PRODUCT)
   1497 ifeq ($(TARGET_BUILD_TYPE),debug)
   1498   name := $(name)_debug
   1499 endif
   1500 name := $(name)-img-$(FILE_NAME_TAG)
   1501 
   1502 INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   1503 
   1504 $(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(DISTTOOLS)
   1505 	@echo "Package: $@"
   1506 	$(hide) MKBOOTIMG=$(MKBOOTIMG) \
   1507 	   ./build/tools/releasetools/img_from_target_files -v \
   1508 	   -p $(HOST_OUT) \
   1509 	   $(BUILT_TARGET_FILES_PACKAGE) $@
   1510 
   1511 .PHONY: updatepackage
   1512 updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
   1513 
   1514 # -----------------------------------------------------------------
   1515 # A zip of the symbols directory.  Keep the full paths to make it
   1516 # more obvious where these files came from.
   1517 #
   1518 name := $(TARGET_PRODUCT)
   1519 ifeq ($(TARGET_BUILD_TYPE),debug)
   1520   name := $(name)_debug
   1521 endif
   1522 name := $(name)-symbols-$(FILE_NAME_TAG)
   1523 
   1524 SYMBOLS_ZIP := $(PRODUCT_OUT)/$(name).zip
   1525 # For apps_only build we'll establish the dependency later in build/core/main.mk.
   1526 ifndef TARGET_BUILD_APPS
   1527 $(SYMBOLS_ZIP): $(INSTALLED_SYSTEMIMAGE) $(INSTALLED_BOOTIMAGE_TARGET)
   1528 endif
   1529 $(SYMBOLS_ZIP):
   1530 	@echo "Package symbols: $@"
   1531 	$(hide) rm -rf $@
   1532 	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_UNSTRIPPED)
   1533 	$(hide) zip -qr $@ $(TARGET_OUT_UNSTRIPPED)
   1534 
   1535 # -----------------------------------------------------------------
   1536 # A zip of the Android Apps. Not keeping full path so that we don't
   1537 # include product names when distributing
   1538 #
   1539 name := $(TARGET_PRODUCT)
   1540 ifeq ($(TARGET_BUILD_TYPE),debug)
   1541   name := $(name)_debug
   1542 endif
   1543 name := $(name)-apps-$(FILE_NAME_TAG)
   1544 
   1545 APPS_ZIP := $(PRODUCT_OUT)/$(name).zip
   1546 $(APPS_ZIP): $(INSTALLED_SYSTEMIMAGE)
   1547 	@echo "Package apps: $@"
   1548 	$(hide) rm -rf $@
   1549 	$(hide) mkdir -p $(dir $@)
   1550 	$(hide) zip -qj $@ $(TARGET_OUT_APPS)/*/*.apk $(TARGET_OUT_APPS_PRIVILEGED)/*/*.apk
   1551 
   1552 
   1553 #------------------------------------------------------------------
   1554 # A zip of emma code coverage meta files. Generated for fully emma
   1555 # instrumented build.
   1556 #
   1557 ifeq (true,$(EMMA_INSTRUMENT))
   1558 EMMA_META_ZIP := $(PRODUCT_OUT)/emma_meta.zip
   1559 # the dependency will be set up later in build/core/main.mk.
   1560 $(EMMA_META_ZIP) :
   1561 	@echo "Collecting Emma coverage meta files."
   1562 	$(hide) find $(TARGET_COMMON_OUT_ROOT) $(HOST_COMMON_OUT_ROOT) -name "coverage.em" | \
   1563 		zip -@ -q $@
   1564 
   1565 endif # EMMA_INSTRUMENT=true
   1566 
   1567 #------------------------------------------------------------------
   1568 # A zip of Proguard obfuscation dictionary files.
   1569 # Only for apps_only build.
   1570 #
   1571 ifdef TARGET_BUILD_APPS
   1572 PROGUARD_DICT_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-$(FILE_NAME_TAG).zip
   1573 # the dependency will be set up later in build/core/main.mk.
   1574 $(PROGUARD_DICT_ZIP) :
   1575 	@echo "Packaging Proguard obfuscation dictionary files."
   1576 	$(hide) dict_files=`find $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS -name proguard_dictionary`; \
   1577 		if [ -n "$$dict_files" ]; then \
   1578 		  unobfuscated_jars=$${dict_files//proguard_dictionary/classes.jar}; \
   1579 		  zip -q $@ $$dict_files $$unobfuscated_jars; \
   1580 		else \
   1581 		  touch $(dir $@)/dummy; \
   1582 		  (cd $(dir $@) && zip -q $(notdir $@) dummy); \
   1583 		  zip -qd $@ dummy; \
   1584 		  rm $(dir $@)/dummy; \
   1585 		fi
   1586 
   1587 endif # TARGET_BUILD_APPS
   1588 
   1589 # -----------------------------------------------------------------
   1590 # dalvik something
   1591 .PHONY: dalvikfiles
   1592 dalvikfiles: $(INTERNAL_DALVIK_MODULES)
   1593 
   1594 # -----------------------------------------------------------------
   1595 # The emulator package
   1596 ifeq ($(BUILD_EMULATOR),true)
   1597 INTERNAL_EMULATOR_PACKAGE_FILES += \
   1598         $(HOST_OUT_EXECUTABLES)/emulator$(HOST_EXECUTABLE_SUFFIX) \
   1599         prebuilts/qemu-kernel/$(TARGET_ARCH)/kernel-qemu \
   1600         $(INSTALLED_RAMDISK_TARGET) \
   1601 		$(INSTALLED_SYSTEMIMAGE) \
   1602 		$(INSTALLED_USERDATAIMAGE_TARGET)
   1603 
   1604 name := $(TARGET_PRODUCT)-emulator-$(FILE_NAME_TAG)
   1605 
   1606 INTERNAL_EMULATOR_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   1607 
   1608 $(INTERNAL_EMULATOR_PACKAGE_TARGET): $(INTERNAL_EMULATOR_PACKAGE_FILES)
   1609 	@echo "Package: $@"
   1610 	$(hide) zip -qj $@ $(INTERNAL_EMULATOR_PACKAGE_FILES)
   1611 
   1612 endif
   1613 # -----------------------------------------------------------------
   1614 # Old PDK stuffs, retired
   1615 # The pdk package (Platform Development Kit)
   1616 
   1617 #ifneq (,$(filter pdk,$(MAKECMDGOALS)))
   1618 #  include development/pdk/Pdk.mk
   1619 #endif
   1620 
   1621 
   1622 # -----------------------------------------------------------------
   1623 # The SDK
   1624 
   1625 # The SDK includes host-specific components, so it belongs under HOST_OUT.
   1626 sdk_dir := $(HOST_OUT)/sdk/$(TARGET_PRODUCT)
   1627 
   1628 # Build a name that looks like:
   1629 #
   1630 #     linux-x86   --> android-sdk_12345_linux-x86
   1631 #     darwin-x86  --> android-sdk_12345_mac-x86
   1632 #     windows-x86 --> android-sdk_12345_windows
   1633 #
   1634 sdk_name := android-sdk_$(FILE_NAME_TAG)
   1635 ifeq ($(HOST_OS),darwin)
   1636   INTERNAL_SDK_HOST_OS_NAME := mac
   1637 else
   1638   INTERNAL_SDK_HOST_OS_NAME := $(HOST_OS)
   1639 endif
   1640 ifneq ($(HOST_OS),windows)
   1641   INTERNAL_SDK_HOST_OS_NAME := $(INTERNAL_SDK_HOST_OS_NAME)-$(SDK_HOST_ARCH)
   1642 endif
   1643 sdk_name := $(sdk_name)_$(INTERNAL_SDK_HOST_OS_NAME)
   1644 
   1645 sdk_dep_file := $(sdk_dir)/sdk_deps.mk
   1646 
   1647 ATREE_FILES :=
   1648 -include $(sdk_dep_file)
   1649 
   1650 # if we don't have a real list, then use "everything"
   1651 ifeq ($(strip $(ATREE_FILES)),)
   1652 ATREE_FILES := \
   1653 	$(ALL_PREBUILT) \
   1654 	$(ALL_COPIED_HEADERS) \
   1655 	$(ALL_DEFAULT_INSTALLED_MODULES) \
   1656 	$(INSTALLED_RAMDISK_TARGET) \
   1657 	$(ALL_DOCS) \
   1658 	$(ALL_SDK_FILES)
   1659 endif
   1660 
   1661 atree_dir := development/build
   1662 
   1663 
   1664 sdk_atree_files := \
   1665 	$(atree_dir)/sdk.exclude.atree \
   1666 	$(atree_dir)/sdk-$(HOST_OS)-$(SDK_HOST_ARCH).atree
   1667 
   1668 # development/build/sdk-android-<abi>.atree is used to differentiate
   1669 # between architecture models (e.g. ARMv5TE versus ARMv7) when copying
   1670 # files like the kernel image. We use TARGET_CPU_ABI because we don't
   1671 # have a better way to distinguish between CPU models.
   1672 ifneq (,$(strip $(wildcard $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree)))
   1673   sdk_atree_files += $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree
   1674 endif
   1675 
   1676 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ATREE_FILES),)
   1677 sdk_atree_files += $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ATREE_FILES)
   1678 else
   1679 sdk_atree_files += $(atree_dir)/sdk.atree
   1680 endif
   1681 
   1682 include $(BUILD_SYSTEM)/sdk_font.mk
   1683 
   1684 deps := \
   1685 	$(target_notice_file_txt) \
   1686 	$(tools_notice_file_txt) \
   1687 	$(OUT_DOCS)/offline-sdk-timestamp \
   1688 	$(SYMBOLS_ZIP) \
   1689 	$(INSTALLED_SYSTEMIMAGE) \
   1690 	$(INSTALLED_USERDATAIMAGE_TARGET) \
   1691 	$(INSTALLED_RAMDISK_TARGET) \
   1692 	$(INSTALLED_SDK_BUILD_PROP_TARGET) \
   1693 	$(INSTALLED_BUILD_PROP_TARGET) \
   1694 	$(ATREE_FILES) \
   1695 	$(sdk_atree_files) \
   1696 	$(HOST_OUT_EXECUTABLES)/atree \
   1697 	$(HOST_OUT_EXECUTABLES)/line_endings \
   1698 	$(SDK_FONT_DEPS)
   1699 
   1700 INTERNAL_SDK_TARGET := $(sdk_dir)/$(sdk_name).zip
   1701 $(INTERNAL_SDK_TARGET): PRIVATE_NAME := $(sdk_name)
   1702 $(INTERNAL_SDK_TARGET): PRIVATE_DIR := $(sdk_dir)/$(sdk_name)
   1703 $(INTERNAL_SDK_TARGET): PRIVATE_DEP_FILE := $(sdk_dep_file)
   1704 $(INTERNAL_SDK_TARGET): PRIVATE_INPUT_FILES := $(sdk_atree_files)
   1705 
   1706 # Set SDK_GNU_ERROR to non-empty to fail when a GNU target is built.
   1707 #
   1708 #SDK_GNU_ERROR := true
   1709 
   1710 $(INTERNAL_SDK_TARGET): $(deps)
   1711 	@echo "Package SDK: $@"
   1712 	$(hide) rm -rf $(PRIVATE_DIR) $@
   1713 	$(hide) for f in $(target_gnu_MODULES); do \
   1714 	  if [ -f $$f ]; then \
   1715 	    echo SDK: $(if $(SDK_GNU_ERROR),ERROR:,warning:) \
   1716 	        including GNU target $$f >&2; \
   1717 	    FAIL=$(SDK_GNU_ERROR); \
   1718 	  fi; \
   1719 	done; \
   1720 	if [ $$FAIL ]; then exit 1; fi
   1721 	$(hide) echo $(notdir $(SDK_FONT_DEPS)) | tr " " "\n"  > $(SDK_FONT_TEMP)/fontsInSdk.txt
   1722 	$(hide) ( \
   1723 		ATREE_STRIP="strip -x" \
   1724 		$(HOST_OUT_EXECUTABLES)/atree \
   1725 		$(addprefix -f ,$(PRIVATE_INPUT_FILES)) \
   1726 			-m $(PRIVATE_DEP_FILE) \
   1727 			-I . \
   1728 			-I $(PRODUCT_OUT) \
   1729 			-I $(HOST_OUT) \
   1730 			-I $(TARGET_COMMON_OUT_ROOT) \
   1731 			-v "PLATFORM_NAME=android-$(PLATFORM_VERSION)" \
   1732 			-v "OUT_DIR=$(OUT_DIR)" \
   1733 			-v "HOST_OUT=$(HOST_OUT)" \
   1734 			-v "TARGET_ARCH=$(TARGET_ARCH)" \
   1735 			-v "TARGET_CPU_ABI=$(TARGET_CPU_ABI)" \
   1736 			-v "DLL_EXTENSION=$(HOST_SHLIB_SUFFIX)" \
   1737 			-v "FONT_OUT=$(SDK_FONT_TEMP)" \
   1738 			-o $(PRIVATE_DIR) && \
   1739 		cp -f $(target_notice_file_txt) \
   1740 				$(PRIVATE_DIR)/system-images/android-$(PLATFORM_VERSION)/$(TARGET_CPU_ABI)/NOTICE.txt && \
   1741 		cp -f $(tools_notice_file_txt) $(PRIVATE_DIR)/platform-tools/NOTICE.txt && \
   1742 		HOST_OUT_EXECUTABLES=$(HOST_OUT_EXECUTABLES) HOST_OS=$(HOST_OS) \
   1743 			development/build/tools/sdk_clean.sh $(PRIVATE_DIR) && \
   1744 		chmod -R ug+rwX $(PRIVATE_DIR) && \
   1745 		cd $(dir $@) && zip -rq $(notdir $@) $(PRIVATE_NAME) \
   1746 	) || ( rm -rf $(PRIVATE_DIR) $@ && exit 44 )
   1747 
   1748 
   1749 # Is a Windows SDK requested? If so, we need some definitions from here
   1750 # in order to find the Linux SDK used to create the Windows one.
   1751 MAIN_SDK_NAME := $(sdk_name)
   1752 MAIN_SDK_DIR  := $(sdk_dir)
   1753 MAIN_SDK_ZIP  := $(INTERNAL_SDK_TARGET)
   1754 ifneq ($(filter win_sdk,$(MAKECMDGOALS)),)
   1755 include $(TOPDIR)development/build/tools/windows_sdk.mk
   1756 endif
   1757 
   1758 # -----------------------------------------------------------------
   1759 # Findbugs
   1760 INTERNAL_FINDBUGS_XML_TARGET := $(PRODUCT_OUT)/findbugs.xml
   1761 INTERNAL_FINDBUGS_HTML_TARGET := $(PRODUCT_OUT)/findbugs.html
   1762 $(INTERNAL_FINDBUGS_XML_TARGET): $(ALL_FINDBUGS_FILES)
   1763 	@echo UnionBugs: $@
   1764 	$(hide) $(FINDBUGS_DIR)/unionBugs $(ALL_FINDBUGS_FILES) \
   1765 	> $@
   1766 $(INTERNAL_FINDBUGS_HTML_TARGET): $(INTERNAL_FINDBUGS_XML_TARGET)
   1767 	@echo ConvertXmlToText: $@
   1768 	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl \
   1769 	$(INTERNAL_FINDBUGS_XML_TARGET) > $@
   1770 
   1771 # -----------------------------------------------------------------
   1772 # Findbugs
   1773 
   1774 # -----------------------------------------------------------------
   1775 # These are some additional build tasks that need to be run.
   1776 ifneq ($(dont_bother),true)
   1777 include $(sort $(wildcard $(BUILD_SYSTEM)/tasks/*.mk))
   1778 -include $(sort $(wildcard vendor/*/build/tasks/*.mk))
   1779 -include $(sort $(wildcard device/*/build/tasks/*.mk))
   1780 # Also the project-specific tasks
   1781 -include $(sort $(wildcard vendor/*/*/build/tasks/*.mk))
   1782 -include $(sort $(wildcard device/*/*/build/tasks/*.mk))
   1783 endif
   1784 
   1785 # -----------------------------------------------------------------
   1786 # Create SDK repository packages. Must be done after tasks/* since
   1787 # we need the addon rules defined.
   1788 ifneq ($(sdk_repo_goal),)
   1789 include $(TOPDIR)development/build/tools/sdk_repo.mk
   1790 endif
   1791