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 # Define rules to copy headers defined in copy_headers.mk
     51 # If more than one makefile declared a header, print a warning,
     52 # then copy the last one defined. This matches the previous make
     53 # behavior.
     54 $(foreach dest,$(ALL_COPIED_HEADERS), \
     55     $(eval _srcs := $(ALL_COPIED_HEADERS.$(dest).SRC)) \
     56     $(eval _src := $(word $(words $(_srcs)),$(_srcs))) \
     57     $(if $(call streq,$(_src),$(_srcs)),, \
     58         $(warning Duplicate header copy: $(dest)) \
     59 	$(warning Defined in: $(ALL_COPIED_HEADERS.$(dest).MAKEFILE))) \
     60     $(eval $(call copy-one-header,$(_src),$(dest))))
     61 all_copied_headers: $(ALL_COPIED_HEADERS)
     62 
     63 # -----------------------------------------------------------------
     64 # docs/index.html
     65 ifeq (,$(TARGET_BUILD_APPS))
     66 gen := $(OUT_DOCS)/index.html
     67 ALL_DOCS += $(gen)
     68 $(gen): frameworks/base/docs/docs-redirect-index.html
     69 	@mkdir -p $(dir $@)
     70 	@cp -f $< $@
     71 endif
     72 
     73 # -----------------------------------------------------------------
     74 # default.prop
     75 INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_ROOT_OUT)/default.prop
     76 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_TARGET)
     77 ADDITIONAL_DEFAULT_PROPERTIES := \
     78     $(call collapse-pairs, $(ADDITIONAL_DEFAULT_PROPERTIES))
     79 ADDITIONAL_DEFAULT_PROPERTIES += \
     80     $(call collapse-pairs, $(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))
     81 ADDITIONAL_DEFAULT_PROPERTIES := $(call uniq-pairs-by-first-component, \
     82     $(ADDITIONAL_DEFAULT_PROPERTIES),=)
     83 
     84 intermediate_system_build_prop := $(call intermediates-dir-for,ETC,system_build_prop)/build.prop
     85 
     86 $(INSTALLED_DEFAULT_PROP_TARGET): $(intermediate_system_build_prop)
     87 	@echo Target buildinfo: $@
     88 	@mkdir -p $(dir $@)
     89 	$(hide) echo "#" > $@; \
     90 	        echo "# ADDITIONAL_DEFAULT_PROPERTIES" >> $@; \
     91 	        echo "#" >> $@;
     92 	$(hide) $(foreach line,$(ADDITIONAL_DEFAULT_PROPERTIES), \
     93 		echo "$(line)" >> $@;)
     94 	$(hide) echo "#" >> $@; \
     95 	        echo "# BOOTIMAGE_BUILD_PROPERTIES" >> $@; \
     96 	        echo "#" >> $@;
     97 	$(hide) echo ro.bootimage.build.date=`$(DATE_FROM_FILE)`>>$@
     98 	$(hide) echo ro.bootimage.build.date.utc=`$(DATE_FROM_FILE) +%s`>>$@
     99 	$(hide) echo ro.bootimage.build.fingerprint="$(BUILD_FINGERPRINT_FROM_FILE)">>$@
    100 	$(hide) build/tools/post_process_props.py $@
    101 
    102 # -----------------------------------------------------------------
    103 # build.prop
    104 INSTALLED_BUILD_PROP_TARGET := $(TARGET_OUT)/build.prop
    105 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_BUILD_PROP_TARGET)
    106 ADDITIONAL_BUILD_PROPERTIES := \
    107     $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))
    108 ADDITIONAL_BUILD_PROPERTIES := $(call uniq-pairs-by-first-component, \
    109     $(ADDITIONAL_BUILD_PROPERTIES),=)
    110 
    111 # A list of arbitrary tags describing the build configuration.
    112 # Force ":=" so we can use +=
    113 BUILD_VERSION_TAGS := $(BUILD_VERSION_TAGS)
    114 ifeq ($(TARGET_BUILD_TYPE),debug)
    115   BUILD_VERSION_TAGS += debug
    116 endif
    117 # The "test-keys" tag marks builds signed with the old test keys,
    118 # which are available in the SDK.  "dev-keys" marks builds signed with
    119 # non-default dev keys (usually private keys from a vendor directory).
    120 # Both of these tags will be removed and replaced with "release-keys"
    121 # when the target-files is signed in a post-build step.
    122 ifeq ($(DEFAULT_SYSTEM_DEV_CERTIFICATE),build/target/product/security/testkey)
    123 BUILD_KEYS := test-keys
    124 else
    125 BUILD_KEYS := dev-keys
    126 endif
    127 BUILD_VERSION_TAGS += $(BUILD_KEYS)
    128 BUILD_VERSION_TAGS := $(subst $(space),$(comma),$(sort $(BUILD_VERSION_TAGS)))
    129 
    130 # A human-readable string that descibes this build in detail.
    131 build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER_FROM_FILE) $(BUILD_VERSION_TAGS)
    132 $(intermediate_system_build_prop): PRIVATE_BUILD_DESC := $(build_desc)
    133 
    134 # The string used to uniquely identify the combined build and product; used by the OTA server.
    135 ifeq (,$(strip $(BUILD_FINGERPRINT)))
    136   ifneq ($(filter eng.%,$(BUILD_NUMBER)),)
    137     # Trim down BUILD_FINGERPRINT: the default BUILD_NUMBER makes it easily exceed
    138     # the Android system property length limit (PROPERTY_VALUE_MAX=92).
    139     BF_BUILD_NUMBER := $(shell echo $${USER:0:6})$(shell $(DATE) +%m%d%H%M)
    140   else
    141     BF_BUILD_NUMBER := $(BUILD_NUMBER)
    142   endif
    143   BUILD_FINGERPRINT := $(PRODUCT_BRAND)/$(TARGET_PRODUCT)/$(TARGET_DEVICE):$(PLATFORM_VERSION)/$(BUILD_ID)/$(BF_BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)
    144 endif
    145 ifneq ($(words $(BUILD_FINGERPRINT)),1)
    146   $(error BUILD_FINGERPRINT cannot contain spaces: "$(BUILD_FINGERPRINT)")
    147 endif
    148 
    149 $(shell mkdir -p $(PRODUCT_OUT) && echo $(BUILD_FINGERPRINT) > $(PRODUCT_OUT)/build_fingerprint.txt)
    150 BUILD_FINGERPRINT_FROM_FILE := $$(cat $(PRODUCT_OUT)/build_fingerprint.txt)
    151 
    152 # The string used to uniquely identify the system build; used by the OTA server.
    153 # This purposefully excludes any product-specific variables.
    154 ifeq (,$(strip $(BUILD_THUMBPRINT)))
    155   BUILD_THUMBPRINT := $(PLATFORM_VERSION)/$(BUILD_ID)/$(BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)
    156 endif
    157 ifneq ($(words $(BUILD_THUMBPRINT)),1)
    158   $(error BUILD_THUMBPRINT cannot contain spaces: "$(BUILD_THUMBPRINT)")
    159 endif
    160 
    161 KNOWN_OEM_THUMBPRINT_PROPERTIES := \
    162     ro.product.brand \
    163     ro.product.name \
    164     ro.product.device
    165 OEM_THUMBPRINT_PROPERTIES := $(filter $(KNOWN_OEM_THUMBPRINT_PROPERTIES),\
    166     $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES))
    167 
    168 # Display parameters shown under Settings -> About Phone
    169 ifeq ($(TARGET_BUILD_VARIANT),user)
    170   # User builds should show:
    171   # release build number or branch.buld_number non-release builds
    172 
    173   # Dev. branches should have DISPLAY_BUILD_NUMBER set
    174   ifeq "true" "$(DISPLAY_BUILD_NUMBER)"
    175     BUILD_DISPLAY_ID := $(BUILD_ID).$(BUILD_NUMBER_FROM_FILE) $(BUILD_KEYS)
    176   else
    177     BUILD_DISPLAY_ID := $(BUILD_ID) $(BUILD_KEYS)
    178   endif
    179 else
    180   # Non-user builds should show detailed build information
    181   BUILD_DISPLAY_ID := $(build_desc)
    182 endif
    183 
    184 # Accepts a whitespace separated list of product locales such as
    185 # (en_US en_AU en_GB...) and returns the first locale in the list with
    186 # underscores replaced with hyphens. In the example above, this will
    187 # return "en-US".
    188 define get-default-product-locale
    189 $(strip $(subst _,-, $(firstword $(1))))
    190 endef
    191 
    192 BUILDINFO_SH := build/tools/buildinfo.sh
    193 
    194 # TARGET_BUILD_FLAVOR and ro.build.flavor are used only by the test harness to distinguish builds.
    195 TARGET_BUILD_FLAVOR := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)
    196 ifdef SANITIZE_TARGET
    197 TARGET_BUILD_FLAVOR := $(TARGET_BUILD_FLAVOR)_asan
    198 endif
    199 
    200 ifdef TARGET_SYSTEM_PROP
    201 system_prop_file := $(TARGET_SYSTEM_PROP)
    202 else
    203 system_prop_file := $(wildcard $(TARGET_DEVICE_DIR)/system.prop)
    204 endif
    205 $(intermediate_system_build_prop): $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(system_prop_file) $(INSTALLED_ANDROID_INFO_TXT_TARGET)
    206 	@echo Target buildinfo: $@
    207 	@mkdir -p $(dir $@)
    208 	$(hide) echo > $@
    209 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES),)
    210 	$(hide) echo "#" >> $@; \
    211 	        echo "# PRODUCT_OEM_PROPERTIES" >> $@; \
    212 	        echo "#" >> $@;
    213 	$(hide) $(foreach prop,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES), \
    214 		echo "import /oem/oem.prop $(prop)" >> $@;)
    215 endif
    216 	$(hide) TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \
    217 			TARGET_BUILD_FLAVOR="$(TARGET_BUILD_FLAVOR)" \
    218 			TARGET_DEVICE="$(TARGET_DEVICE)" \
    219 			PRODUCT_NAME="$(TARGET_PRODUCT)" \
    220 			PRODUCT_BRAND="$(PRODUCT_BRAND)" \
    221 			PRODUCT_DEFAULT_LOCALE="$(call get-default-product-locale,$(PRODUCT_LOCALES))" \
    222 			PRODUCT_DEFAULT_WIFI_CHANNELS="$(PRODUCT_DEFAULT_WIFI_CHANNELS)" \
    223 			PRODUCT_MODEL="$(PRODUCT_MODEL)" \
    224 			PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
    225 			PRIVATE_BUILD_DESC="$(PRIVATE_BUILD_DESC)" \
    226 			BUILD_ID="$(BUILD_ID)" \
    227 			BUILD_DISPLAY_ID="$(BUILD_DISPLAY_ID)" \
    228 			DATE="$(DATE_FROM_FILE)" \
    229 			BUILD_NUMBER="$(BUILD_NUMBER_FROM_FILE)" \
    230 			BOARD_BUILD_SYSTEM_ROOT_IMAGE="$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)" \
    231 			AB_OTA_UPDATER="$(AB_OTA_UPDATER)" \
    232 			PLATFORM_VERSION="$(PLATFORM_VERSION)" \
    233 			PLATFORM_SECURITY_PATCH="$(PLATFORM_SECURITY_PATCH)" \
    234 			PLATFORM_BASE_OS="$(PLATFORM_BASE_OS)" \
    235 			PLATFORM_SDK_VERSION="$(PLATFORM_SDK_VERSION)" \
    236 			PLATFORM_PREVIEW_SDK_VERSION="$(PLATFORM_PREVIEW_SDK_VERSION)" \
    237 			PLATFORM_VERSION_CODENAME="$(PLATFORM_VERSION_CODENAME)" \
    238 			PLATFORM_VERSION_ALL_CODENAMES="$(PLATFORM_VERSION_ALL_CODENAMES)" \
    239 			BUILD_VERSION_TAGS="$(BUILD_VERSION_TAGS)" \
    240 			TARGET_BOOTLOADER_BOARD_NAME="$(TARGET_BOOTLOADER_BOARD_NAME)" \
    241 			BUILD_FINGERPRINT="$(BUILD_FINGERPRINT_FROM_FILE)" \
    242 			$(if $(OEM_THUMBPRINT_PROPERTIES),BUILD_THUMBPRINT="$(BUILD_THUMBPRINT)") \
    243 			TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \
    244 			TARGET_CPU_ABI_LIST="$(TARGET_CPU_ABI_LIST)" \
    245 			TARGET_CPU_ABI_LIST_32_BIT="$(TARGET_CPU_ABI_LIST_32_BIT)" \
    246 			TARGET_CPU_ABI_LIST_64_BIT="$(TARGET_CPU_ABI_LIST_64_BIT)" \
    247 			TARGET_CPU_ABI="$(TARGET_CPU_ABI)" \
    248 			TARGET_CPU_ABI2="$(TARGET_CPU_ABI2)" \
    249 			TARGET_AAPT_CHARACTERISTICS="$(TARGET_AAPT_CHARACTERISTICS)" \
    250 	        bash $(BUILDINFO_SH) >> $@
    251 	$(hide) $(foreach file,$(system_prop_file), \
    252 		if [ -f "$(file)" ]; then \
    253 			echo "#" >> $@; \
    254 			echo Target buildinfo from: "$(file)"; \
    255 			echo "# from $(file)" >> $@; \
    256 			echo "#" >> $@; \
    257 			cat $(file) >> $@; \
    258 		fi;)
    259 	$(if $(ADDITIONAL_BUILD_PROPERTIES), \
    260 		$(hide) echo >> $@; \
    261 		        echo "#" >> $@; \
    262 		        echo "# ADDITIONAL_BUILD_PROPERTIES" >> $@; \
    263 		        echo "#" >> $@; )
    264 	$(hide) $(foreach line,$(ADDITIONAL_BUILD_PROPERTIES), \
    265 		echo "$(line)" >> $@;)
    266 	$(hide) cat $(INSTALLED_ANDROID_INFO_TXT_TARGET) | grep 'require version-' | sed -e 's/require version-/ro.build.expect./g' >> $@
    267 	$(hide) build/tools/post_process_props.py $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_PROPERTY_BLACKLIST)
    268 
    269 build_desc :=
    270 
    271 ifeq (,$(filter true, $(TARGET_NO_KERNEL) $(TARGET_NO_RECOVERY)))
    272 INSTALLED_RECOVERYIMAGE_TARGET := $(PRODUCT_OUT)/recovery.img
    273 else
    274 INSTALLED_RECOVERYIMAGE_TARGET :=
    275 endif
    276 
    277 $(INSTALLED_BUILD_PROP_TARGET): $(intermediate_system_build_prop) $(INSTALLED_RECOVERYIMAGE_TARGET)
    278 	@echo "Target build info: $@"
    279 	$(hide) cat $(intermediate_system_build_prop) > $@
    280 ifdef INSTALLED_RECOVERYIMAGE_TARGET
    281 	$(hide) echo ro.expect.recovery_id=`cat $(RECOVERYIMAGE_ID_FILE)` >> $@
    282 endif
    283 
    284 # -----------------------------------------------------------------
    285 # vendor build.prop
    286 #
    287 # For verifying that the vendor build is what we thing it is
    288 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
    289 INSTALLED_VENDOR_BUILD_PROP_TARGET := $(TARGET_OUT_VENDOR)/build.prop
    290 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_VENDOR_BUILD_PROP_TARGET)
    291 $(INSTALLED_VENDOR_BUILD_PROP_TARGET): $(INSTALLED_BUILD_PROP_TARGET)
    292 	@echo Target vendor buildinfo: $@
    293 	@mkdir -p $(dir $@)
    294 	$(hide) echo > $@
    295 	$(hide) echo ro.vendor.build.date=`$(DATE_FROM_FILE)`>>$@
    296 	$(hide) echo ro.vendor.build.date.utc=`$(DATE_FROM_FILE) +%s`>>$@
    297 	$(hide) echo ro.vendor.build.fingerprint="$(BUILD_FINGERPRINT_FROM_FILE)">>$@
    298 endif
    299 
    300 # ----------------------------------------------------------------
    301 
    302 # -----------------------------------------------------------------
    303 # sdk-build.prop
    304 #
    305 # There are certain things in build.prop that we don't want to
    306 # ship with the sdk; remove them.
    307 
    308 # This must be a list of entire property keys followed by
    309 # "=" characters, without any internal spaces.
    310 sdk_build_prop_remove := \
    311 	ro.build.user= \
    312 	ro.build.host= \
    313 	ro.product.brand= \
    314 	ro.product.manufacturer= \
    315 	ro.product.device=
    316 # TODO: Remove this soon-to-be obsolete property
    317 sdk_build_prop_remove += ro.build.product=
    318 INSTALLED_SDK_BUILD_PROP_TARGET := $(PRODUCT_OUT)/sdk/sdk-build.prop
    319 $(INSTALLED_SDK_BUILD_PROP_TARGET): $(INSTALLED_BUILD_PROP_TARGET)
    320 	@echo SDK buildinfo: $@
    321 	@mkdir -p $(dir $@)
    322 	$(hide) grep -v "$(subst $(space),\|,$(strip \
    323 				$(sdk_build_prop_remove)))" $< > $@.tmp
    324 	$(hide) for x in $(sdk_build_prop_remove); do \
    325 				echo "$$x"generic >> $@.tmp; done
    326 	$(hide) mv $@.tmp $@
    327 
    328 # -----------------------------------------------------------------
    329 # package stats
    330 PACKAGE_STATS_FILE := $(PRODUCT_OUT)/package-stats.txt
    331 PACKAGES_TO_STAT := \
    332     $(sort $(filter $(TARGET_OUT)/% $(TARGET_OUT_DATA)/%, \
    333 	$(filter %.jar %.apk, $(ALL_DEFAULT_INSTALLED_MODULES))))
    334 $(PACKAGE_STATS_FILE): $(PACKAGES_TO_STAT)
    335 	@echo Package stats: $@
    336 	@mkdir -p $(dir $@)
    337 	$(hide) rm -f $@
    338 ifeq ($(PACKAGES_TO_STAT),)
    339 # Create empty package stats file if target builds no jar(s) or apk(s).
    340 	$(hide) touch $@
    341 else
    342 	$(hide) build/tools/dump-package-stats $^ > $@
    343 endif
    344 
    345 .PHONY: package-stats
    346 package-stats: $(PACKAGE_STATS_FILE)
    347 
    348 # -----------------------------------------------------------------
    349 # Cert-to-package mapping.  Used by the post-build signing tools.
    350 # Use a macro to add newline to each echo command
    351 define _apkcerts_echo_with_newline
    352 $(hide) echo $(1)
    353 
    354 endef
    355 
    356 name := $(TARGET_PRODUCT)
    357 ifeq ($(TARGET_BUILD_TYPE),debug)
    358   name := $(name)_debug
    359 endif
    360 name := $(name)-apkcerts-$(FILE_NAME_TAG)
    361 intermediates := \
    362 	$(call intermediates-dir-for,PACKAGING,apkcerts)
    363 APKCERTS_FILE := $(intermediates)/$(name).txt
    364 # We don't need to really build all the modules.
    365 # TODO: rebuild APKCERTS_FILE if any app change its cert.
    366 $(APKCERTS_FILE):
    367 	@echo APK certs list: $@
    368 	@mkdir -p $(dir $@)
    369 	@rm -f $@
    370 	$(foreach p,$(PACKAGES),\
    371 	  $(if $(PACKAGES.$(p).EXTERNAL_KEY),\
    372 	    $(call _apkcerts_echo_with_newline,\
    373 	      'name="$(p).apk" certificate="EXTERNAL" \
    374 	      private_key=""' >> $@),\
    375 	    $(call _apkcerts_echo_with_newline,\
    376 	      'name="$(p).apk" certificate="$(PACKAGES.$(p).CERTIFICATE)" \
    377 	      private_key="$(PACKAGES.$(p).PRIVATE_KEY)"' >> $@)))
    378 	# In case value of PACKAGES is empty.
    379 	$(hide) touch $@
    380 
    381 .PHONY: apkcerts-list
    382 apkcerts-list: $(APKCERTS_FILE)
    383 
    384 ifneq (,$(TARGET_BUILD_APPS))
    385   $(call dist-for-goals, apps_only, $(APKCERTS_FILE):apkcerts.txt)
    386 endif
    387 
    388 # -----------------------------------------------------------------
    389 
    390 # The dev key is used to sign this package, and as the key required
    391 # for future OTA packages installed by this system.  Actual product
    392 # deliverables will be re-signed by hand.  We expect this file to
    393 # exist with the suffixes ".x509.pem" and ".pk8".
    394 DEFAULT_KEY_CERT_PAIR := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
    395 
    396 
    397 # Rules that need to be present for the all targets, even
    398 # if they don't do anything.
    399 .PHONY: systemimage
    400 systemimage:
    401 
    402 # -----------------------------------------------------------------
    403 
    404 .PHONY: event-log-tags
    405 
    406 # Produce an event logs tag file for everything we know about, in order
    407 # to properly allocate numbers.  Then produce a file that's filtered
    408 # for what's going to be installed.
    409 
    410 all_event_log_tags_file := $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
    411 
    412 event_log_tags_file := $(TARGET_OUT)/etc/event-log-tags
    413 
    414 # Include tags from all packages that we know about
    415 all_event_log_tags_src := \
    416     $(sort $(foreach m, $(ALL_MODULES), $(ALL_MODULES.$(m).EVENT_LOG_TAGS)))
    417 
    418 # PDK builds will already have a full list of tags that needs to get merged
    419 # in with the ones from source
    420 pdk_fusion_log_tags_file := $(patsubst $(PRODUCT_OUT)/%,$(_pdk_fusion_intermediates)/%,$(filter $(event_log_tags_file),$(ALL_PDK_FUSION_FILES)))
    421 
    422 $(all_event_log_tags_file): PRIVATE_SRC_FILES := $(all_event_log_tags_src) $(pdk_fusion_log_tags_file)
    423 $(all_event_log_tags_file): $(all_event_log_tags_src) $(pdk_fusion_log_tags_file)
    424 	$(hide) mkdir -p $(dir $@)
    425 	$(hide) build/tools/merge-event-log-tags.py -o $@ $(PRIVATE_SRC_FILES)
    426 
    427 # Include tags from all packages included in this product, plus all
    428 # tags that are part of the system (ie, not in a vendor/ or device/
    429 # directory).
    430 event_log_tags_src := \
    431     $(sort $(foreach m,\
    432       $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES) \
    433       $(call module-names-for-tag-list,user), \
    434       $(ALL_MODULES.$(m).EVENT_LOG_TAGS)) \
    435       $(filter-out vendor/% device/% out/%,$(all_event_log_tags_src)))
    436 
    437 $(event_log_tags_file): PRIVATE_SRC_FILES := $(event_log_tags_src) $(pdk_fusion_log_tags_file)
    438 $(event_log_tags_file): PRIVATE_MERGED_FILE := $(all_event_log_tags_file)
    439 $(event_log_tags_file): $(event_log_tags_src) $(all_event_log_tags_file) $(pdk_fusion_log_tags_file)
    440 	$(hide) mkdir -p $(dir $@)
    441 	$(hide) build/tools/merge-event-log-tags.py -o $@ -m $(PRIVATE_MERGED_FILE) $(PRIVATE_SRC_FILES)
    442 
    443 event-log-tags: $(event_log_tags_file)
    444 
    445 ALL_DEFAULT_INSTALLED_MODULES += $(event_log_tags_file)
    446 
    447 
    448 # #################################################################
    449 # Targets for boot/OS images
    450 # #################################################################
    451 ifneq ($(strip $(TARGET_NO_BOOTLOADER)),true)
    452   INSTALLED_BOOTLOADER_MODULE := $(PRODUCT_OUT)/bootloader
    453   ifeq ($(strip $(TARGET_BOOTLOADER_IS_2ND)),true)
    454     INSTALLED_2NDBOOTLOADER_TARGET := $(PRODUCT_OUT)/2ndbootloader
    455   else
    456     INSTALLED_2NDBOOTLOADER_TARGET :=
    457   endif
    458 else
    459   INSTALLED_BOOTLOADER_MODULE :=
    460   INSTALLED_2NDBOOTLOADER_TARGET :=
    461 endif # TARGET_NO_BOOTLOADER
    462 ifneq ($(strip $(TARGET_NO_KERNEL)),true)
    463   INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
    464 else
    465   INSTALLED_KERNEL_TARGET :=
    466 endif
    467 
    468 # -----------------------------------------------------------------
    469 # the ramdisk
    470 INTERNAL_RAMDISK_FILES := $(filter $(TARGET_ROOT_OUT)/%, \
    471 	$(ALL_PREBUILT) \
    472 	$(ALL_GENERATED_SOURCES) \
    473 	$(ALL_DEFAULT_INSTALLED_MODULES))
    474 
    475 BUILT_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img
    476 
    477 # We just build this directly to the install location.
    478 INSTALLED_RAMDISK_TARGET := $(BUILT_RAMDISK_TARGET)
    479 $(INSTALLED_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_RAMDISK_FILES) | $(MINIGZIP)
    480 	$(call pretty,"Target ram disk: $@")
    481 	$(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_ROOT_OUT) | $(MINIGZIP) > $@
    482 
    483 .PHONY: ramdisk-nodeps
    484 ramdisk-nodeps: $(MKBOOTFS) | $(MINIGZIP)
    485 	@echo "make $@: ignoring dependencies"
    486 	$(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_ROOT_OUT) | $(MINIGZIP) > $(INSTALLED_RAMDISK_TARGET)
    487 
    488 ifneq ($(strip $(TARGET_NO_KERNEL)),true)
    489 
    490 # -----------------------------------------------------------------
    491 # the boot image, which is a collection of other images.
    492 INTERNAL_BOOTIMAGE_ARGS := \
    493 	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
    494 	--kernel $(INSTALLED_KERNEL_TARGET)
    495 
    496 ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
    497 INTERNAL_BOOTIMAGE_ARGS += --ramdisk $(INSTALLED_RAMDISK_TARGET)
    498 endif
    499 
    500 INTERNAL_BOOTIMAGE_FILES := $(filter-out --%,$(INTERNAL_BOOTIMAGE_ARGS))
    501 
    502 BOARD_KERNEL_BASE := $(strip $(BOARD_KERNEL_BASE))
    503 ifdef BOARD_KERNEL_BASE
    504   INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
    505 endif
    506 
    507 BOARD_KERNEL_PAGESIZE := $(strip $(BOARD_KERNEL_PAGESIZE))
    508 ifdef BOARD_KERNEL_PAGESIZE
    509   INTERNAL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
    510 endif
    511 
    512 ifeq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),true)
    513 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
    514 VERITY_KEYID := veritykeyid=id:`openssl x509 -in $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem -text \
    515                 | grep keyid | sed 's/://g' | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]' | sed 's/keyid//g'`
    516 endif
    517 endif
    518 
    519 BOARD_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE) buildvariant=$(TARGET_BUILD_VARIANT) $(VERITY_KEYID))
    520 ifdef BOARD_KERNEL_CMDLINE
    521 INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)"
    522 endif
    523 
    524 INTERNAL_MKBOOTIMG_VERSION_ARGS := \
    525     --os_version $(PLATFORM_VERSION) \
    526     --os_patch_level $(PLATFORM_SECURITY_PATCH)
    527 
    528 INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
    529 
    530 # BOARD_USES_RECOVERY_AS_BOOT = true must have BOARD_BUILD_SYSTEM_ROOT_IMAGE = true.
    531 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
    532 ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
    533   $(error BOARD_BUILD_SYSTEM_ROOT_IMAGE must be enabled for BOARD_USES_RECOVERY_AS_BOOT.)
    534 endif
    535 endif
    536 
    537 # We build recovery as boot image if BOARD_USES_RECOVERY_AS_BOOT is true.
    538 ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
    539 ifeq ($(TARGET_BOOTIMAGE_USE_EXT2),true)
    540 $(error TARGET_BOOTIMAGE_USE_EXT2 is not supported anymore)
    541 else ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER)) # TARGET_BOOTIMAGE_USE_EXT2 != true
    542 
    543 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(BOOT_SIGNER)
    544 	$(call pretty,"Target boot image: $@")
    545 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
    546 	$(BOOT_SIGNER) /boot $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $@
    547 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    548 
    549 .PHONY: bootimage-nodeps
    550 bootimage-nodeps: $(MKBOOTIMG) $(BOOT_SIGNER)
    551 	@echo "make $@: ignoring dependencies"
    552 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
    553 	$(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)
    554 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    555 
    556 else ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)) # PRODUCT_SUPPORTS_BOOT_SIGNER != true
    557 
    558 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(VBOOT_SIGNER)
    559 	$(call pretty,"Target boot image: $@")
    560 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@.unsigned
    561 	$(VBOOT_SIGNER) $(FUTILITY) $@.unsigned $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $@.keyblock $@
    562 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    563 
    564 .PHONY: bootimage-nodeps
    565 bootimage-nodeps: $(MKBOOTIMG) $(VBOOT_SIGNER)
    566 	@echo "make $@: ignoring dependencies"
    567 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET).unsigned
    568 	$(VBOOT_SIGNER) $(FUTILITY) $(INSTALLED_BOOTIMAGE_TARGET).unsigned $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(INSTALLED_BOOTIMAGE_TARGET).keyblock $(INSTALLED_BOOTIMAGE_TARGET)
    569 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    570 
    571 else # PRODUCT_SUPPORTS_VBOOT != true
    572 
    573 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES)
    574 	$(call pretty,"Target boot image: $@")
    575 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
    576 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    577 
    578 .PHONY: bootimage-nodeps
    579 bootimage-nodeps: $(MKBOOTIMG)
    580 	@echo "make $@: ignoring dependencies"
    581 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
    582 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    583 
    584 endif # TARGET_BOOTIMAGE_USE_EXT2
    585 endif # BOARD_USES_RECOVERY_AS_BOOT
    586 
    587 else	# TARGET_NO_KERNEL
    588 # HACK: The top-level targets depend on the bootimage.  Not all targets
    589 # can produce a bootimage, though, and emulator targets need the ramdisk
    590 # instead.  Fake it out by calling the ramdisk the bootimage.
    591 # TODO: make the emulator use bootimages, and make mkbootimg accept
    592 #       kernel-less inputs.
    593 INSTALLED_BOOTIMAGE_TARGET := $(INSTALLED_RAMDISK_TARGET)
    594 endif
    595 
    596 # -----------------------------------------------------------------
    597 # NOTICE files
    598 #
    599 # We are required to publish the licenses for all code under BSD, GPL and
    600 # Apache licenses (and possibly other more exotic ones as well). We err on the
    601 # side of caution, so the licenses for other third-party code are included here
    602 # too.
    603 #
    604 # This needs to be before the systemimage rules, because it adds to
    605 # ALL_DEFAULT_INSTALLED_MODULES, which those use to pick which files
    606 # go into the systemimage.
    607 
    608 .PHONY: notice_files
    609 
    610 # Create the rule to combine the files into text and html forms
    611 # $(1) - Plain text output file
    612 # $(2) - HTML output file
    613 # $(3) - File title
    614 # $(4) - Directory to use.  Notice files are all $(4)/src.  Other
    615 #		 directories in there will be used for scratch
    616 # $(5) - Dependencies for the output files
    617 #
    618 # The algorithm here is that we go collect a hash for each of the notice
    619 # files and write the names of the files that match that hash.  Then
    620 # to generate the real files, we go print out all of the files and their
    621 # hashes.
    622 #
    623 # These rules are fairly complex, so they depend on this makefile so if
    624 # it changes, they'll run again.
    625 #
    626 # TODO: We could clean this up so that we just record the locations of the
    627 # original notice files instead of making rules to copy them somwehere.
    628 # Then we could traverse that without quite as much bash drama.
    629 define combine-notice-files
    630 $(1) $(2): PRIVATE_MESSAGE := $(3)
    631 $(1) $(2): PRIVATE_DIR := $(4)
    632 $(1) : $(2)
    633 $(2) : $(5) $(BUILD_SYSTEM)/Makefile build/tools/generate-notice-files.py
    634 	build/tools/generate-notice-files.py $(1) $(2) $$(PRIVATE_MESSAGE) $$(PRIVATE_DIR)/src
    635 notice_files: $(1) $(2)
    636 endef
    637 
    638 # TODO These intermediate NOTICE.txt/NOTICE.html files should go into
    639 # TARGET_OUT_NOTICE_FILES now that the notice files are gathered from
    640 # the src subdirectory.
    641 
    642 target_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE.txt
    643 target_notice_file_html := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html
    644 target_notice_file_html_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html.gz
    645 tools_notice_file_txt := $(HOST_OUT_INTERMEDIATES)/NOTICE.txt
    646 tools_notice_file_html := $(HOST_OUT_INTERMEDIATES)/NOTICE.html
    647 
    648 ifndef TARGET_BUILD_APPS
    649 kernel_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/kernel.txt
    650 pdk_fusion_notice_files := $(filter $(TARGET_OUT_NOTICE_FILES)/%, $(ALL_PDK_FUSION_FILES))
    651 
    652 $(eval $(call combine-notice-files, \
    653 			$(target_notice_file_txt), \
    654 			$(target_notice_file_html), \
    655 			"Notices for files contained in the filesystem images in this directory:", \
    656 			$(TARGET_OUT_NOTICE_FILES), \
    657 			$(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file) $(pdk_fusion_notice_files)))
    658 
    659 $(eval $(call combine-notice-files, \
    660 			$(tools_notice_file_txt), \
    661 			$(tools_notice_file_html), \
    662 			"Notices for files contained in the tools directory:", \
    663 			$(HOST_OUT_NOTICE_FILES), \
    664 			$(ALL_DEFAULT_INSTALLED_MODULES)))
    665 
    666 # Install the html file at /system/etc/NOTICE.html.gz.
    667 # This is not ideal, but this is very late in the game, after a lot of
    668 # the module processing has already been done -- in fact, we used the
    669 # fact that all that has been done to get the list of modules that we
    670 # need notice files for.
    671 $(target_notice_file_html_gz): $(target_notice_file_html) | $(MINIGZIP)
    672 	$(hide) $(MINIGZIP) -9 < $< > $@
    673 installed_notice_html_gz := $(TARGET_OUT)/etc/NOTICE.html.gz
    674 $(installed_notice_html_gz): $(target_notice_file_html_gz) | $(ACP)
    675 	$(copy-file-to-target)
    676 
    677 # if we've been run my mm, mmm, etc, don't reinstall this every time
    678 ifeq ($(ONE_SHOT_MAKEFILE),)
    679 ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_gz)
    680 endif
    681 endif  # TARGET_BUILD_APPS
    682 
    683 # The kernel isn't really a module, so to get its module file in there, we
    684 # make the target NOTICE files depend on this particular file too, which will
    685 # then be in the right directory for the find in combine-notice-files to work.
    686 $(kernel_notice_file): \
    687 	    $(BUILD_SYSTEM)/LINUX_KERNEL_COPYING \
    688 	    | $(ACP)
    689 	@echo Copying: $@
    690 	$(hide) mkdir -p $(dir $@)
    691 	$(hide) $(ACP) $< $@
    692 
    693 
    694 # -----------------------------------------------------------------
    695 # Build a keystore with the authorized keys in it, used to verify the
    696 # authenticity of downloaded OTA packages.
    697 #
    698 # This rule adds to ALL_DEFAULT_INSTALLED_MODULES, so it needs to come
    699 # before the rules that use that variable to build the image.
    700 ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_ETC)/security/otacerts.zip
    701 $(TARGET_OUT_ETC)/security/otacerts.zip: KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
    702 $(TARGET_OUT_ETC)/security/otacerts.zip: $(addsuffix .x509.pem,$(DEFAULT_KEY_CERT_PAIR)) | $(ZIPTIME)
    703 	$(hide) rm -f $@
    704 	$(hide) mkdir -p $(dir $@)
    705 	$(hide) zip -qjX $@ $<
    706 	$(remove-timestamps-from-package)
    707 
    708 # Carry the public key for update_engine if it's a non-Brillo target that
    709 # uses the AB updater. We use the same key as otacerts but in RSA public key
    710 # format.
    711 ifeq ($(AB_OTA_UPDATER),true)
    712 ifeq ($(BRILLO),)
    713 ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem
    714 $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem: $(addsuffix .x509.pem,$(DEFAULT_KEY_CERT_PAIR))
    715 	$(hide) rm -f $@
    716 	$(hide) mkdir -p $(dir $@)
    717 	$(hide) openssl x509 -pubkey -noout -in $< > $@
    718 
    719 ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_RECOVERY_ROOT_OUT)/etc/update_engine/update-payload-key.pub.pem
    720 $(TARGET_RECOVERY_ROOT_OUT)/etc/update_engine/update-payload-key.pub.pem: $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem
    721 	$(hide) cp -f $< $@
    722 endif
    723 endif
    724 
    725 .PHONY: otacerts
    726 otacerts: $(TARGET_OUT_ETC)/security/otacerts.zip
    727 
    728 
    729 # #################################################################
    730 # Targets for user images
    731 # #################################################################
    732 
    733 INTERNAL_USERIMAGES_EXT_VARIANT :=
    734 ifeq ($(TARGET_USERIMAGES_USE_EXT2),true)
    735 INTERNAL_USERIMAGES_USE_EXT := true
    736 INTERNAL_USERIMAGES_EXT_VARIANT := ext2
    737 else
    738 ifeq ($(TARGET_USERIMAGES_USE_EXT3),true)
    739 INTERNAL_USERIMAGES_USE_EXT := true
    740 INTERNAL_USERIMAGES_EXT_VARIANT := ext3
    741 else
    742 ifeq ($(TARGET_USERIMAGES_USE_EXT4),true)
    743 INTERNAL_USERIMAGES_USE_EXT := true
    744 INTERNAL_USERIMAGES_EXT_VARIANT := ext4
    745 endif
    746 endif
    747 endif
    748 
    749 # These options tell the recovery updater/installer how to mount the partitions writebale.
    750 # <fstype>=<fstype_opts>[|<fstype_opts>]...
    751 # fstype_opts := <opt>[,<opt>]...
    752 #         opt := <name>[=<value>]
    753 # The following worked on Nexus devices with Kernel 3.1, 3.4, 3.10
    754 DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS := ext4=max_batch_time=0,commit=1,data=ordered,barrier=1,errors=panic,nodelalloc
    755 
    756 ifneq (true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED))
    757   INTERNAL_USERIMAGES_SPARSE_EXT_FLAG := -s
    758 endif
    759 
    760 ifeq ($(INTERNAL_USERIMAGES_USE_EXT),true)
    761 INTERNAL_USERIMAGES_DEPS := $(SIMG2IMG)
    762 INTERNAL_USERIMAGES_DEPS += $(MKEXTUSERIMG) $(MAKE_EXT4FS) $(E2FSCK)
    763 ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
    764 INTERNAL_USERIMAGES_DEPS += $(MKF2FSUSERIMG) $(MAKE_F2FS)
    765 endif
    766 endif
    767 
    768 ifneq (true,$(TARGET_USERIMAGES_SPARSE_SQUASHFS_DISABLED))
    769   INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG := -s
    770 endif
    771 ifneq ($(filter $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE) $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE),squashfs),)
    772 INTERNAL_USERIMAGES_DEPS += $(MAKE_SQUASHFS) $(MKSQUASHFSUSERIMG) $(IMG2SIMG)
    773 endif
    774 
    775 INTERNAL_USERIMAGES_BINARY_PATHS := $(sort $(dir $(INTERNAL_USERIMAGES_DEPS)))
    776 
    777 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY))
    778 INTERNAL_USERIMAGES_DEPS += $(BUILD_VERITY_TREE) $(APPEND2SIMG) $(VERITY_SIGNER)
    779 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC))
    780 INTERNAL_USERIMAGES_DEPS += $(FEC)
    781 endif
    782 endif
    783 
    784 SELINUX_FC := $(TARGET_ROOT_OUT)/file_contexts.bin
    785 INTERNAL_USERIMAGES_DEPS += $(SELINUX_FC)
    786 
    787 INTERNAL_USERIMAGES_DEPS += $(BLK_ALLOC_TO_BASE_FS)
    788 
    789 # $(1): the path of the output dictionary file
    790 # $(2): additional "key=value" pairs to append to the dictionary file.
    791 define generate-userimage-prop-dictionary
    792 $(if $(INTERNAL_USERIMAGES_EXT_VARIANT),$(hide) echo "fs_type=$(INTERNAL_USERIMAGES_EXT_VARIANT)" >> $(1))
    793 $(if $(BOARD_SYSTEMIMAGE_PARTITION_SIZE),$(hide) echo "system_size=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE)" >> $(1))
    794 $(if $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "system_fs_type=$(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    795 $(if $(BOARD_SYSTEMIMAGE_JOURNAL_SIZE),$(hide) echo "system_journal_size=$(BOARD_SYSTEMIMAGE_JOURNAL_SIZE)" >> $(1))
    796 $(if $(BOARD_HAS_EXT4_RESERVED_BLOCKS),$(hide) echo "has_ext4_reserved_blocks=$(BOARD_HAS_EXT4_RESERVED_BLOCKS)" >> $(1))
    797 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "system_squashfs_compressor=$(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
    798 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "system_squashfs_compressor_opt=$(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
    799 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "system_squashfs_block_size=$(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
    800 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "system_squashfs_disable_4k_align=$(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
    801 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH),$(hide) echo "system_base_fs_file=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH)" >> $(1))
    802 $(if $(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "userdata_fs_type=$(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    803 $(if $(BOARD_USERDATAIMAGE_PARTITION_SIZE),$(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(1))
    804 $(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    805 $(if $(BOARD_CACHEIMAGE_PARTITION_SIZE),$(hide) echo "cache_size=$(BOARD_CACHEIMAGE_PARTITION_SIZE)" >> $(1))
    806 $(if $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "vendor_fs_type=$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    807 $(if $(BOARD_VENDORIMAGE_PARTITION_SIZE),$(hide) echo "vendor_size=$(BOARD_VENDORIMAGE_PARTITION_SIZE)" >> $(1))
    808 $(if $(BOARD_VENDORIMAGE_JOURNAL_SIZE),$(hide) echo "vendor_journal_size=$(BOARD_VENDORIMAGE_JOURNAL_SIZE)" >> $(1))
    809 $(if $(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "vendor_squashfs_compressor=$(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
    810 $(if $(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "vendor_squashfs_compressor_opt=$(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
    811 $(if $(BOARD_VENDORIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "vendor_squashfs_block_size=$(BOARD_VENDORIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
    812 $(if $(BOARD_VENDORIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "vendor_squashfs_disable_4k_align=$(BOARD_VENDORIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
    813 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH),$(hide) echo "vendor_base_fs_file=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH)" >> $(1))
    814 $(if $(BOARD_OEMIMAGE_PARTITION_SIZE),$(hide) echo "oem_size=$(BOARD_OEMIMAGE_PARTITION_SIZE)" >> $(1))
    815 $(if $(BOARD_OEMIMAGE_JOURNAL_SIZE),$(hide) echo "oem_journal_size=$(BOARD_OEMIMAGE_JOURNAL_SIZE)" >> $(1))
    816 $(if $(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG),$(hide) echo "extfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG)" >> $(1))
    817 $(if $(INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG),$(hide) echo "squashfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG)" >> $(1))
    818 $(hide) echo "selinux_fc=$(SELINUX_FC)" >> $(1)
    819 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER),$(hide) echo "boot_signer=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER)" >> $(1))
    820 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY)" >> $(1))
    821 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_key=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY)" >> $(1))
    822 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_signer_cmd=$(notdir $(VERITY_SIGNER))" >> $(1))
    823 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC),$(hide) echo "verity_fec=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC)" >> $(1))
    824 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION),$(hide) echo "system_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION)" >> $(1))
    825 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION),$(hide) echo "vendor_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION)" >> $(1))
    826 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)" >> $(1))
    827 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_key=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY)" >> $(1))
    828 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_subkey=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY)" >> $(1))
    829 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "futility=$(FUTILITY)" >> $(1))
    830 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_signer_cmd=$(VBOOT_SIGNER)" >> $(1))
    831 $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
    832     $(hide) echo "recovery_as_boot=true" >> $(1))
    833 $(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)),\
    834     $(hide) echo "system_root_image=true" >> $(1);\
    835     echo "ramdisk_dir=$(TARGET_ROOT_OUT)" >> $(1))
    836 $(if $(2),$(hide) $(foreach kv,$(2),echo "$(kv)" >> $(1);))
    837 endef
    838 
    839 # -----------------------------------------------------------------
    840 # Recovery image
    841 
    842 # Recovery image exists if we are building recovery, or building recovery as boot.
    843 ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)))
    844 
    845 INTERNAL_RECOVERYIMAGE_FILES := $(filter $(TARGET_RECOVERY_OUT)/%, \
    846     $(ALL_DEFAULT_INSTALLED_MODULES))
    847 
    848 recovery_initrc := $(call include-path-for, recovery)/etc/init.rc
    849 recovery_sepolicy := $(call intermediates-dir-for,ETC,sepolicy.recovery)/sepolicy.recovery
    850 recovery_kernel := $(INSTALLED_KERNEL_TARGET) # same as a non-recovery system
    851 recovery_ramdisk := $(PRODUCT_OUT)/ramdisk-recovery.img
    852 recovery_build_prop := $(intermediate_system_build_prop)
    853 recovery_resources_common := $(call include-path-for, recovery)/res
    854 
    855 # Set recovery_density to the density bucket of the device.
    856 recovery_density := unknown
    857 ifneq (,$(PRODUCT_AAPT_PREF_CONFIG))
    858 # If PRODUCT_AAPT_PREF_CONFIG includes a dpi bucket, then use that value.
    859 recovery_density := $(filter %dpi,$(PRODUCT_AAPT_PREF_CONFIG))
    860 else
    861 # Otherwise, use the default medium density.
    862 recovery_densities := mdpi
    863 endif
    864 
    865 ifneq (,$(wildcard $(recovery_resources_common)-$(recovery_density)))
    866 recovery_resources_common := $(recovery_resources_common)-$(recovery_density)
    867 else
    868 recovery_resources_common := $(recovery_resources_common)-xhdpi
    869 endif
    870 
    871 # Select the 18x32 font on high-density devices (xhdpi and up); and
    872 # the 12x22 font on other devices.  Note that the font selected here
    873 # can be overridden for a particular device by putting a font.png in
    874 # its private recovery resources.
    875 
    876 ifneq (,$(filter xxxhdpi 560dpi xxhdpi 400dpi xhdpi,$(recovery_density)))
    877 recovery_font := $(call include-path-for, recovery)/fonts/18x32.png
    878 else
    879 recovery_font := $(call include-path-for, recovery)/fonts/12x22.png
    880 endif
    881 
    882 ifndef TARGET_PRIVATE_RES_DIRS
    883 TARGET_PRIVATE_RES_DIRS := $(wildcard $(TARGET_DEVICE_DIR)/recovery/res)
    884 endif
    885 recovery_resource_deps := $(shell find $(recovery_resources_common) \
    886   $(TARGET_PRIVATE_RES_DIRS) -type f)
    887 ifdef TARGET_RECOVERY_FSTAB
    888 recovery_fstab := $(TARGET_RECOVERY_FSTAB)
    889 else
    890 recovery_fstab := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery.fstab))
    891 endif
    892 ifdef TARGET_RECOVERY_WIPE
    893 recovery_wipe := $(TARGET_RECOVERY_WIPE)
    894 else
    895 recovery_wipe :=
    896 endif
    897 
    898 # Prior to A/B update, we used to have:
    899 #   boot.img + recovery-from-boot.p + recovery-resource.dat = recovery.img.
    900 # recovery-resource.dat is needed only if we carry a patch of the boot and
    901 # recovery images and invoke install-recovery.sh on the first boot post an
    902 # OTA update.
    903 #
    904 # We no longer need that if one of the following conditions holds:
    905 #   a) We carry a full copy of the recovery image
    906 #      (BOARD_USES_FULL_RECOVERY_IMAGE = true);
    907 #   b) We build a single image that contains boot and recovery both
    908 #      (BOARD_USES_RECOVERY_AS_BOOT = true).
    909 
    910 ifeq (,$(filter true, $(BOARD_USES_FULL_RECOVERY_IMAGE) $(BOARD_USES_RECOVERY_AS_BOOT)))
    911 # Named '.dat' so we don't attempt to use imgdiff for patching it.
    912 RECOVERY_RESOURCE_ZIP := $(TARGET_OUT)/etc/recovery-resource.dat
    913 else
    914 RECOVERY_RESOURCE_ZIP :=
    915 endif
    916 
    917 ifeq ($(TARGET_PRIVATE_RES_DIRS),)
    918   $(info No private recovery resources for TARGET_DEVICE $(TARGET_DEVICE))
    919 endif
    920 
    921 ifeq ($(recovery_fstab),)
    922   $(info No recovery.fstab for TARGET_DEVICE $(TARGET_DEVICE))
    923 endif
    924 
    925 INTERNAL_RECOVERYIMAGE_ARGS := \
    926 	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
    927 	--kernel $(recovery_kernel) \
    928 	--ramdisk $(recovery_ramdisk)
    929 
    930 # Assumes this has already been stripped
    931 ifdef BOARD_KERNEL_CMDLINE
    932   INTERNAL_RECOVERYIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)"
    933 endif
    934 ifdef BOARD_KERNEL_BASE
    935   INTERNAL_RECOVERYIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
    936 endif
    937 BOARD_KERNEL_PAGESIZE := $(strip $(BOARD_KERNEL_PAGESIZE))
    938 ifdef BOARD_KERNEL_PAGESIZE
    939   INTERNAL_RECOVERYIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
    940 endif
    941 
    942 # Keys authorized to sign OTA packages this build will accept.  The
    943 # build always uses dev-keys for this; release packaging tools will
    944 # substitute other keys for this one.
    945 OTA_PUBLIC_KEYS := $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem
    946 
    947 # Generate a file containing the keys that will be read by the
    948 # recovery binary.
    949 RECOVERY_INSTALL_OTA_KEYS := \
    950 	$(call intermediates-dir-for,PACKAGING,ota_keys)/keys
    951 DUMPKEY_JAR := $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar
    952 $(RECOVERY_INSTALL_OTA_KEYS): PRIVATE_OTA_PUBLIC_KEYS := $(OTA_PUBLIC_KEYS)
    953 $(RECOVERY_INSTALL_OTA_KEYS): extra_keys := $(patsubst %,%.x509.pem,$(PRODUCT_EXTRA_RECOVERY_KEYS))
    954 $(RECOVERY_INSTALL_OTA_KEYS): $(OTA_PUBLIC_KEYS) $(DUMPKEY_JAR) $(extra_keys)
    955 	@echo "DumpPublicKey: $@ <= $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys)"
    956 	@rm -rf $@
    957 	@mkdir -p $(dir $@)
    958 	java -jar $(DUMPKEY_JAR) $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys) > $@
    959 
    960 RECOVERYIMAGE_ID_FILE := $(PRODUCT_OUT)/recovery.id
    961 # $(1): output file
    962 define build-recoveryimage-target
    963   @echo ----- Making recovery image ------
    964   $(hide) mkdir -p $(TARGET_RECOVERY_OUT)
    965   $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/etc $(TARGET_RECOVERY_ROOT_OUT)/sdcard $(TARGET_RECOVERY_ROOT_OUT)/tmp
    966   @echo Copying baseline ramdisk...
    967   $(hide) rsync -a --exclude=etc --exclude=sdcard $(IGNORE_CACHE_LINK) $(TARGET_ROOT_OUT) $(TARGET_RECOVERY_OUT) # "cp -Rf" fails to overwrite broken symlinks on Mac.
    968   @echo Modifying ramdisk contents...
    969   $(hide) rm -f $(TARGET_RECOVERY_ROOT_OUT)/init*.rc
    970   $(hide) cp -f $(recovery_initrc) $(TARGET_RECOVERY_ROOT_OUT)/
    971   $(hide) rm -f $(TARGET_RECOVERY_ROOT_OUT)/sepolicy
    972   $(hide) cp -f $(recovery_sepolicy) $(TARGET_RECOVERY_ROOT_OUT)/sepolicy
    973   $(hide) cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/ || true # Ignore error when the src file doesn't exist.
    974   $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/res
    975   $(hide) rm -rf $(TARGET_RECOVERY_ROOT_OUT)/res/*
    976   $(hide) cp -rf $(recovery_resources_common)/* $(TARGET_RECOVERY_ROOT_OUT)/res
    977   $(hide) cp -f $(recovery_font) $(TARGET_RECOVERY_ROOT_OUT)/res/images/font.png
    978   $(hide) $(foreach item,$(TARGET_PRIVATE_RES_DIRS), \
    979     cp -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/$(newline))
    980   $(hide) $(foreach item,$(recovery_fstab), \
    981     cp -f $(item) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.fstab)
    982   $(if $(strip $(recovery_wipe)), \
    983     $(hide) cp -f $(recovery_wipe) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.wipe)
    984   $(hide) cp $(RECOVERY_INSTALL_OTA_KEYS) $(TARGET_RECOVERY_ROOT_OUT)/res/keys
    985   $(hide) cat $(INSTALLED_DEFAULT_PROP_TARGET) $(recovery_build_prop) \
    986           > $(TARGET_RECOVERY_ROOT_OUT)/default.prop
    987   $(BOARD_RECOVERY_IMAGE_PREPARE)
    988   $(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)), \
    989     $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/system_root; \
    990             rm -rf $(TARGET_RECOVERY_ROOT_OUT)/system; \
    991             ln -sf /system_root/system $(TARGET_RECOVERY_ROOT_OUT)/system) # Mount the system_root_image to /system_root and symlink /system.
    992   $(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RECOVERY_ROOT_OUT) | $(MINIGZIP) > $(recovery_ramdisk)
    993   $(if $(filter true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)), \
    994     $(hide) $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1).unsigned, \
    995     $(hide) $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1) --id > $(RECOVERYIMAGE_ID_FILE))
    996   $(if $(filter true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER)),\
    997     $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
    998       $(BOOT_SIGNER) /boot $(1) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1),\
    999       $(BOOT_SIGNER) /recovery $(1) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1)\
   1000     )\
   1001   )
   1002   $(if $(filter true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)), \
   1003     $(VBOOT_SIGNER) $(FUTILITY) $(1).unsigned $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(1).keyblock $(1))
   1004   $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)), \
   1005     $(hide) $(call assert-max-image-size,$(1),$(BOARD_BOOTIMAGE_PARTITION_SIZE)), \
   1006     $(hide) $(call assert-max-image-size,$(1),$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)))
   1007   @echo ----- Made recovery image: $(1) --------
   1008 endef
   1009 
   1010 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
   1011 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER))
   1012 $(INSTALLED_BOOTIMAGE_TARGET) : $(BOOT_SIGNER)
   1013 endif
   1014 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT))
   1015 $(INSTALLED_BOOTIMAGE_TARGET) : $(VBOOT_SIGNER)
   1016 endif
   1017 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
   1018 		$(INSTALLED_RAMDISK_TARGET) \
   1019 		$(INTERNAL_RECOVERYIMAGE_FILES) \
   1020 		$(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
   1021 		$(INSTALLED_2NDBOOTLOADER_TARGET) \
   1022 		$(recovery_build_prop) $(recovery_resource_deps) \
   1023 		$(recovery_fstab) \
   1024 		$(RECOVERY_INSTALL_OTA_KEYS)
   1025 		$(call pretty,"Target boot image from recovery: $@")
   1026 		$(call build-recoveryimage-target, $@)
   1027 endif
   1028 
   1029 $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
   1030 		$(INSTALLED_RAMDISK_TARGET) \
   1031 		$(INSTALLED_BOOTIMAGE_TARGET) \
   1032 		$(INTERNAL_RECOVERYIMAGE_FILES) \
   1033 		$(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
   1034 		$(INSTALLED_2NDBOOTLOADER_TARGET) \
   1035 		$(recovery_build_prop) $(recovery_resource_deps) \
   1036 		$(recovery_fstab) \
   1037 		$(RECOVERY_INSTALL_OTA_KEYS)
   1038 		$(call build-recoveryimage-target, $@)
   1039 
   1040 ifdef RECOVERY_RESOURCE_ZIP
   1041 $(RECOVERY_RESOURCE_ZIP): $(INSTALLED_RECOVERYIMAGE_TARGET) | $(ZIPTIME)
   1042 	$(hide) mkdir -p $(dir $@)
   1043 	$(hide) find $(TARGET_RECOVERY_ROOT_OUT)/res -type f | sort | zip -0qrjX $@ -@
   1044 	$(remove-timestamps-from-package)
   1045 endif
   1046 
   1047 .PHONY: recoveryimage-nodeps
   1048 recoveryimage-nodeps:
   1049 	@echo "make $@: ignoring dependencies"
   1050 	$(call build-recoveryimage-target, $(INSTALLED_RECOVERYIMAGE_TARGET))
   1051 
   1052 else # INSTALLED_RECOVERYIMAGE_TARGET not defined
   1053 RECOVERY_RESOURCE_ZIP :=
   1054 endif
   1055 
   1056 .PHONY: recoveryimage
   1057 recoveryimage: $(INSTALLED_RECOVERYIMAGE_TARGET) $(RECOVERY_RESOURCE_ZIP)
   1058 
   1059 ifeq ($(BOARD_NAND_PAGE_SIZE),)
   1060 BOARD_NAND_PAGE_SIZE := 2048
   1061 endif
   1062 
   1063 ifeq ($(BOARD_NAND_SPARE_SIZE),)
   1064 BOARD_NAND_SPARE_SIZE := 64
   1065 endif
   1066 
   1067 # -----------------------------------------------------------------
   1068 # system image
   1069 #
   1070 # Remove overridden packages from $(ALL_PDK_FUSION_FILES)
   1071 PDK_FUSION_SYSIMG_FILES := \
   1072     $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
   1073         $(ALL_PDK_FUSION_FILES))
   1074 
   1075 INTERNAL_SYSTEMIMAGE_FILES := $(filter $(TARGET_OUT)/%, \
   1076     $(ALL_PREBUILT) \
   1077     $(ALL_GENERATED_SOURCES) \
   1078     $(ALL_DEFAULT_INSTALLED_MODULES) \
   1079     $(PDK_FUSION_SYSIMG_FILES) \
   1080     $(RECOVERY_RESOURCE_ZIP))
   1081 
   1082 
   1083 FULL_SYSTEMIMAGE_DEPS := $(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_USERIMAGES_DEPS)
   1084 # -----------------------------------------------------------------
   1085 # installed file list
   1086 # Depending on anything that $(BUILT_SYSTEMIMAGE) depends on.
   1087 # We put installed-files.txt ahead of image itself in the dependency graph
   1088 # so that we can get the size stat even if the build fails due to too large
   1089 # system image.
   1090 INSTALLED_FILES_FILE := $(PRODUCT_OUT)/installed-files.txt
   1091 $(INSTALLED_FILES_FILE): $(FULL_SYSTEMIMAGE_DEPS)
   1092 	@echo Installed file list: $@
   1093 	@mkdir -p $(dir $@)
   1094 	@rm -f $@
   1095 	$(hide) build/tools/fileslist.py $(TARGET_OUT) > $@
   1096 
   1097 .PHONY: installed-file-list
   1098 installed-file-list: $(INSTALLED_FILES_FILE)
   1099 
   1100 $(call dist-for-goals, sdk win_sdk sdk_addon, $(INSTALLED_FILES_FILE))
   1101 
   1102 systemimage_intermediates := \
   1103     $(call intermediates-dir-for,PACKAGING,systemimage)
   1104 BUILT_SYSTEMIMAGE := $(systemimage_intermediates)/system.img
   1105 
   1106 # Create symlink /system/vendor to /vendor if necessary.
   1107 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1108 define create-system-vendor-symlink
   1109 $(hide) if [ -d $(TARGET_OUT)/vendor ] && [ ! -h $(TARGET_OUT)/vendor ]; then \
   1110   echo 'Non-symlink $(TARGET_OUT)/vendor detected!' 1>&2; \
   1111   echo 'You cannot install files to $(TARGET_OUT)/vendor while building a separate vendor.img!' 1>&2; \
   1112   exit 1; \
   1113 fi
   1114 $(hide) ln -sf /vendor $(TARGET_OUT)/vendor
   1115 endef
   1116 else
   1117 define create-system-vendor-symlink
   1118 endef
   1119 endif
   1120 
   1121 # $(1): output file
   1122 define build-systemimage-target
   1123   @echo "Target system fs image: $(1)"
   1124   $(call create-system-vendor-symlink)
   1125   @mkdir -p $(dir $(1)) $(systemimage_intermediates) && rm -rf $(systemimage_intermediates)/system_image_info.txt
   1126   $(call generate-userimage-prop-dictionary, $(systemimage_intermediates)/system_image_info.txt, \
   1127       skip_fsck=true)
   1128   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1129       ./build/tools/releasetools/build_image.py \
   1130       $(TARGET_OUT) $(systemimage_intermediates)/system_image_info.txt $(1) $(TARGET_OUT) \
   1131       || ( echo "Out of space? the tree size of $(TARGET_OUT) is (MB): " 1>&2 ;\
   1132            du -sm $(TARGET_OUT) 1>&2;\
   1133            if [ "$(INTERNAL_USERIMAGES_EXT_VARIANT)" == "ext4" ]; then \
   1134                maxsize=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE); \
   1135                if [ "$(BOARD_HAS_EXT4_RESERVED_BLOCKS)" == "true" ]; then \
   1136                    maxsize=$$((maxsize - 4096 * 4096)); \
   1137                fi; \
   1138                echo "The max is $$(( maxsize / 1048576 )) MB." 1>&2 ;\
   1139            else \
   1140                echo "The max is $$(( $(BOARD_SYSTEMIMAGE_PARTITION_SIZE) / 1048576 )) MB." 1>&2 ;\
   1141            fi; \
   1142            mkdir -p $(DIST_DIR); cp $(INSTALLED_FILES_FILE) $(DIST_DIR)/installed-files-rescued.txt; \
   1143            exit 1 )
   1144 endef
   1145 
   1146 $(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE)
   1147 	$(call build-systemimage-target,$@)
   1148 
   1149 INSTALLED_SYSTEMIMAGE := $(PRODUCT_OUT)/system.img
   1150 SYSTEMIMAGE_SOURCE_DIR := $(TARGET_OUT)
   1151 
   1152 # The system partition needs room for the recovery image as well.  We
   1153 # now store the recovery image as a binary patch using the boot image
   1154 # as the source (since they are very similar).  Generate the patch so
   1155 # we can see how big it's going to be, and include that in the system
   1156 # image size check calculation.
   1157 ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   1158 ifneq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
   1159 intermediates := $(call intermediates-dir-for,PACKAGING,recovery_patch)
   1160 RECOVERY_FROM_BOOT_PATCH := $(intermediates)/recovery_from_boot.p
   1161 $(RECOVERY_FROM_BOOT_PATCH): $(INSTALLED_RECOVERYIMAGE_TARGET) \
   1162                              $(INSTALLED_BOOTIMAGE_TARGET) \
   1163 			     $(HOST_OUT_EXECUTABLES)/imgdiff \
   1164 	                     $(HOST_OUT_EXECUTABLES)/bsdiff
   1165 	@echo "Construct recovery from boot"
   1166 	mkdir -p $(dir $@)
   1167 	PATH=$(HOST_OUT_EXECUTABLES):$$PATH $(HOST_OUT_EXECUTABLES)/imgdiff $(INSTALLED_BOOTIMAGE_TARGET) $(INSTALLED_RECOVERYIMAGE_TARGET) $@
   1168 else # $(BOARD_USES_FULL_RECOVERY_IMAGE) == true
   1169 RECOVERY_FROM_BOOT_PATCH := $(INSTALLED_RECOVERYIMAGE_TARGET)
   1170 endif
   1171 endif
   1172 
   1173 
   1174 $(INSTALLED_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE) $(RECOVERY_FROM_BOOT_PATCH) | $(ACP)
   1175 	@echo "Install system fs image: $@"
   1176 	$(copy-file-to-target)
   1177 	$(hide) $(call assert-max-image-size,$@ $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
   1178 
   1179 systemimage: $(INSTALLED_SYSTEMIMAGE)
   1180 
   1181 .PHONY: systemimage-nodeps snod
   1182 systemimage-nodeps snod: $(filter-out systemimage-nodeps snod,$(MAKECMDGOALS)) \
   1183 	            | $(INTERNAL_USERIMAGES_DEPS)
   1184 	@echo "make $@: ignoring dependencies"
   1185 	$(call build-systemimage-target,$(INSTALLED_SYSTEMIMAGE))
   1186 	$(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMIMAGE),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
   1187 
   1188 ifneq (,$(filter systemimage-nodeps snod, $(MAKECMDGOALS)))
   1189 ifeq (true,$(WITH_DEXPREOPT))
   1190 $(warning Warning: with dexpreopt enabled, you may need a full rebuild.)
   1191 endif
   1192 endif
   1193 
   1194 #######
   1195 ## system tarball
   1196 define build-systemtarball-target
   1197   $(call pretty,"Target system fs tarball: $(INSTALLED_SYSTEMTARBALL_TARGET)")
   1198   $(call create-system-vendor-symlink)
   1199   $(MKTARBALL) $(FS_GET_STATS) \
   1200     $(PRODUCT_OUT) system $(PRIVATE_SYSTEM_TAR) \
   1201     $(INSTALLED_SYSTEMTARBALL_TARGET) $(TARGET_OUT)
   1202 endef
   1203 
   1204 ifndef SYSTEM_TARBALL_FORMAT
   1205     SYSTEM_TARBALL_FORMAT := bz2
   1206 endif
   1207 
   1208 system_tar := $(PRODUCT_OUT)/system.tar
   1209 INSTALLED_SYSTEMTARBALL_TARGET := $(system_tar).$(SYSTEM_TARBALL_FORMAT)
   1210 $(INSTALLED_SYSTEMTARBALL_TARGET): PRIVATE_SYSTEM_TAR := $(system_tar)
   1211 $(INSTALLED_SYSTEMTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_SYSTEMIMAGE_FILES)
   1212 	$(build-systemtarball-target)
   1213 
   1214 .PHONY: systemtarball-nodeps
   1215 systemtarball-nodeps: $(FS_GET_STATS) \
   1216                       $(filter-out systemtarball-nodeps stnod,$(MAKECMDGOALS))
   1217 	$(build-systemtarball-target)
   1218 
   1219 .PHONY: stnod
   1220 stnod: systemtarball-nodeps
   1221 
   1222 # -----------------------------------------------------------------
   1223 ## platform.zip: system, plus other files to be used in PDK fusion build,
   1224 ## in a zip file
   1225 ##
   1226 ## PDK_PLATFORM_ZIP_PRODUCT_BINARIES is used to store specified files to platform.zip.
   1227 ## The variable will be typically set from BoardConfig.mk.
   1228 ## Files under out dir will be rejected to prevent possible conflicts with other rules.
   1229 pdk_odex_javalibs := $(strip $(foreach m,$(DEXPREOPT.MODULES.JAVA_LIBRARIES),\
   1230   $(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m))))
   1231 pdk_odex_apps := $(strip $(foreach m,$(DEXPREOPT.MODULES.APPS),\
   1232   $(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m))))
   1233 pdk_classes_dex := $(strip \
   1234   $(foreach m,$(pdk_odex_javalibs),$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar) \
   1235   $(foreach m,$(pdk_odex_apps),$(call intermediates-dir-for,APPS,$(m))/package.dex.apk))
   1236 
   1237 pdk_odex_config_mk := $(PRODUCT_OUT)/pdk_dexpreopt_config.mk
   1238 $(pdk_odex_config_mk): PRIVATE_JAVA_LIBRARIES := $(pdk_odex_javalibs)
   1239 $(pdk_odex_config_mk): PRIVATE_APPS := $(pdk_odex_apps)
   1240 $(pdk_odex_config_mk) :
   1241 	@echo "PDK odex config makefile: $@"
   1242 	$(hide) mkdir -p $(dir $@)
   1243 	$(hide) echo "# Auto-generated. Do not modify." > $@
   1244 	$(hide) echo "PDK.DEXPREOPT.JAVA_LIBRARIES:=$(PRIVATE_JAVA_LIBRARIES)" >> $@
   1245 	$(hide) echo "PDK.DEXPREOPT.APPS:=$(PRIVATE_APPS)" >> $@
   1246 	$(foreach m,$(PRIVATE_JAVA_LIBRARIES),\
   1247 	  $(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar)" >> $@$(newline)\
   1248 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\
   1249 	  $(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\
   1250 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\
   1251 	  )
   1252 	$(foreach m,$(PRIVATE_APPS),\
   1253 	  $(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,APPS,$(m))/package.dex.apk)" >> $@$(newline)\
   1254 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\
   1255 	  $(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\
   1256 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\
   1257 	  $(hide) echo "PDK.DEXPREOPT.$(m).PRIVILEGED_MODULE:=$(DEXPREOPT.$(m).PRIVILEGED_MODULE)" >> $@$(newline)\
   1258 	  $(hide) echo "PDK.DEXPREOPT.$(m).PROPRIETARY_MODULE:=$(DEXPREOPT.$(m).PROPRIETARY_MODULE)" >> $@$(newline)\
   1259 	  $(hide) echo "PDK.DEXPREOPT.$(m).TARGET_ARCH:=$(DEXPREOPT.$(m).TARGET_ARCH)" >> $@$(newline)\
   1260 	  $(hide) echo "PDK.DEXPREOPT.$(m).STRIPPED_SRC:=$(patsubst $(PRODUCT_OUT)/%,%,$(DEXPREOPT.$(m).INSTALLED_STRIPPED))" >> $@$(newline)\
   1261 	  )
   1262 
   1263 PDK_PLATFORM_ZIP_PRODUCT_BINARIES := $(filter-out $(OUT_DIR)/%,$(PDK_PLATFORM_ZIP_PRODUCT_BINARIES))
   1264 INSTALLED_PLATFORM_ZIP := $(PRODUCT_OUT)/platform.zip
   1265 
   1266 $(INSTALLED_PLATFORM_ZIP): PRIVATE_DEX_FILES := $(pdk_classes_dex)
   1267 $(INSTALLED_PLATFORM_ZIP): PRIVATE_ODEX_CONFIG := $(pdk_odex_config_mk)
   1268 $(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES) $(pdk_odex_config_mk)
   1269 	$(call pretty,"Platform zip package: $(INSTALLED_PLATFORM_ZIP)")
   1270 	$(hide) rm -f $@
   1271 	$(hide) cd $(dir $@) && zip -qryX $(notdir $@) \
   1272 		$(TARGET_COPY_OUT_SYSTEM) \
   1273 		$(patsubst $(PRODUCT_OUT)/%, %, $(TARGET_OUT_NOTICE_FILES)) \
   1274 		$(addprefix symbols/,$(PDK_SYMBOL_FILES_LIST))
   1275 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1276 	$(hide) cd $(dir $@) && zip -qryX $(notdir $@) \
   1277 		$(TARGET_COPY_OUT_VENDOR)
   1278 endif
   1279 ifneq ($(PDK_PLATFORM_JAVA_ZIP_CONTENTS),)
   1280 	$(hide) cd $(OUT_DIR) && zip -qryX $(patsubst $(OUT_DIR)/%,%,$@) $(PDK_PLATFORM_JAVA_ZIP_CONTENTS)
   1281 endif
   1282 ifneq ($(PDK_PLATFORM_ZIP_PRODUCT_BINARIES),)
   1283 	$(hide) zip -qryX $@ $(PDK_PLATFORM_ZIP_PRODUCT_BINARIES)
   1284 endif
   1285 	@# Add dex-preopt files and config.
   1286 	$(if $(PRIVATE_DEX_FILES),$(hide) cd $(OUT_DIR) && zip -qryX $(patsubst $(OUT_DIR)/%,%,$@ $(PRIVATE_DEX_FILES)))
   1287 	$(hide) zip -qryXj $@ $(PRIVATE_ODEX_CONFIG)
   1288 
   1289 .PHONY: platform
   1290 platform: $(INSTALLED_PLATFORM_ZIP)
   1291 
   1292 .PHONY: platform-java
   1293 platform-java: platform
   1294 
   1295 # Dist the platform.zip
   1296 ifneq (,$(filter platform platform-java, $(MAKECMDGOALS)))
   1297 $(call dist-for-goals, platform platform-java, $(INSTALLED_PLATFORM_ZIP))
   1298 endif
   1299 
   1300 # -----------------------------------------------------------------
   1301 ## boot tarball
   1302 define build-boottarball-target
   1303     $(hide) echo "Target boot fs tarball: $(INSTALLED_BOOTTARBALL_TARGET)"
   1304     $(hide) mkdir -p $(PRODUCT_OUT)/boot
   1305     $(hide) cp -f $(INTERNAL_BOOTIMAGE_FILES) $(PRODUCT_OUT)/boot/.
   1306     $(hide) echo $(BOARD_KERNEL_CMDLINE) > $(PRODUCT_OUT)/boot/cmdline
   1307     $(hide) $(MKTARBALL) $(FS_GET_STATS) \
   1308                  $(PRODUCT_OUT) boot $(PRIVATE_BOOT_TAR) \
   1309                  $(INSTALLED_BOOTTARBALL_TARGET) $(TARGET_OUT)
   1310 endef
   1311 
   1312 ifndef BOOT_TARBALL_FORMAT
   1313     BOOT_TARBALL_FORMAT := bz2
   1314 endif
   1315 
   1316 boot_tar := $(PRODUCT_OUT)/boot.tar
   1317 INSTALLED_BOOTTARBALL_TARGET := $(boot_tar).$(BOOT_TARBALL_FORMAT)
   1318 $(INSTALLED_BOOTTARBALL_TARGET): PRIVATE_BOOT_TAR := $(boot_tar)
   1319 $(INSTALLED_BOOTTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_BOOTIMAGE_FILES)
   1320 	$(build-boottarball-target)
   1321 
   1322 .PHONY: boottarball-nodeps btnod
   1323 boottarball-nodeps btnod: $(FS_GET_STATS) \
   1324                       $(filter-out boottarball-nodeps btnod,$(MAKECMDGOALS))
   1325 	$(build-boottarball-target)
   1326 
   1327 
   1328 # -----------------------------------------------------------------
   1329 # data partition image
   1330 INTERNAL_USERDATAIMAGE_FILES := \
   1331     $(filter $(TARGET_OUT_DATA)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
   1332 
   1333 # Don't build userdata.img if it's extfs but no partition size
   1334 skip_userdata.img :=
   1335 ifdef INTERNAL_USERIMAGES_EXT_VARIANT
   1336 ifndef BOARD_USERDATAIMAGE_PARTITION_SIZE
   1337 skip_userdata.img := true
   1338 endif
   1339 endif
   1340 
   1341 ifneq ($(skip_userdata.img),true)
   1342 userdataimage_intermediates := \
   1343     $(call intermediates-dir-for,PACKAGING,userdata)
   1344 BUILT_USERDATAIMAGE_TARGET := $(PRODUCT_OUT)/userdata.img
   1345 
   1346 define build-userdataimage-target
   1347   $(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
   1348   @mkdir -p $(TARGET_OUT_DATA)
   1349   @mkdir -p $(userdataimage_intermediates) && rm -rf $(userdataimage_intermediates)/userdata_image_info.txt
   1350   $(call generate-userimage-prop-dictionary, $(userdataimage_intermediates)/userdata_image_info.txt, skip_fsck=true)
   1351   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1352       ./build/tools/releasetools/build_image.py \
   1353       $(TARGET_OUT_DATA) $(userdataimage_intermediates)/userdata_image_info.txt $(INSTALLED_USERDATAIMAGE_TARGET) $(TARGET_OUT)
   1354   $(hide) $(call assert-max-image-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_PARTITION_SIZE))
   1355 endef
   1356 
   1357 # We just build this directly to the install location.
   1358 INSTALLED_USERDATAIMAGE_TARGET := $(BUILT_USERDATAIMAGE_TARGET)
   1359 $(INSTALLED_USERDATAIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) \
   1360                                    $(INTERNAL_USERDATAIMAGE_FILES)
   1361 	$(build-userdataimage-target)
   1362 
   1363 .PHONY: userdataimage-nodeps
   1364 userdataimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1365 	$(build-userdataimage-target)
   1366 
   1367 endif # not skip_userdata.img
   1368 skip_userdata.img :=
   1369 
   1370 #######
   1371 ## data partition tarball
   1372 define build-userdatatarball-target
   1373     $(call pretty,"Target userdata fs tarball: " \
   1374                   "$(INSTALLED_USERDATATARBALL_TARGET)")
   1375     $(MKTARBALL) $(FS_GET_STATS) \
   1376 		$(PRODUCT_OUT) data $(PRIVATE_USERDATA_TAR) \
   1377 		$(INSTALLED_USERDATATARBALL_TARGET) $(TARGET_OUT)
   1378 endef
   1379 
   1380 userdata_tar := $(PRODUCT_OUT)/userdata.tar
   1381 INSTALLED_USERDATATARBALL_TARGET := $(userdata_tar).bz2
   1382 $(INSTALLED_USERDATATARBALL_TARGET): PRIVATE_USERDATA_TAR := $(userdata_tar)
   1383 $(INSTALLED_USERDATATARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_USERDATAIMAGE_FILES)
   1384 	$(build-userdatatarball-target)
   1385 
   1386 .PHONY: userdatatarball-nodeps
   1387 userdatatarball-nodeps: $(FS_GET_STATS)
   1388 	$(build-userdatatarball-target)
   1389 
   1390 
   1391 # -----------------------------------------------------------------
   1392 # cache partition image
   1393 ifdef BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
   1394 INTERNAL_CACHEIMAGE_FILES := \
   1395     $(filter $(TARGET_OUT_CACHE)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
   1396 
   1397 cacheimage_intermediates := \
   1398     $(call intermediates-dir-for,PACKAGING,cache)
   1399 BUILT_CACHEIMAGE_TARGET := $(PRODUCT_OUT)/cache.img
   1400 
   1401 define build-cacheimage-target
   1402   $(call pretty,"Target cache fs image: $(INSTALLED_CACHEIMAGE_TARGET)")
   1403   @mkdir -p $(TARGET_OUT_CACHE)
   1404   @mkdir -p $(cacheimage_intermediates) && rm -rf $(cacheimage_intermediates)/cache_image_info.txt
   1405   $(call generate-userimage-prop-dictionary, $(cacheimage_intermediates)/cache_image_info.txt, skip_fsck=true)
   1406   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1407       ./build/tools/releasetools/build_image.py \
   1408       $(TARGET_OUT_CACHE) $(cacheimage_intermediates)/cache_image_info.txt $(INSTALLED_CACHEIMAGE_TARGET) $(TARGET_OUT)
   1409   $(hide) $(call assert-max-image-size,$(INSTALLED_CACHEIMAGE_TARGET),$(BOARD_CACHEIMAGE_PARTITION_SIZE))
   1410 endef
   1411 
   1412 # We just build this directly to the install location.
   1413 INSTALLED_CACHEIMAGE_TARGET := $(BUILT_CACHEIMAGE_TARGET)
   1414 $(INSTALLED_CACHEIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_CACHEIMAGE_FILES)
   1415 	$(build-cacheimage-target)
   1416 
   1417 .PHONY: cacheimage-nodeps
   1418 cacheimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1419 	$(build-cacheimage-target)
   1420 
   1421 else # BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
   1422 # we need to ignore the broken cache link when doing the rsync
   1423 IGNORE_CACHE_LINK := --exclude=cache
   1424 endif # BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
   1425 
   1426 
   1427 # -----------------------------------------------------------------
   1428 # system_other partition image
   1429 ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
   1430 BOARD_USES_SYSTEM_OTHER := true
   1431 
   1432 # Marker file to identify that odex files are installed
   1433 INSTALLED_SYSTEM_OTHER_ODEX_MARKER := $(TARGET_OUT_SYSTEM_OTHER)/system-other-odex-marker
   1434 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_SYSTEM_OTHER_ODEX_MARKER)
   1435 $(INSTALLED_SYSTEM_OTHER_ODEX_MARKER):
   1436 	$(hide) touch $@
   1437 endif
   1438 
   1439 ifdef BOARD_USES_SYSTEM_OTHER
   1440 INTERNAL_SYSTEMOTHERIMAGE_FILES := \
   1441     $(filter $(TARGET_OUT_SYSTEM_OTHER)/%,\
   1442       $(ALL_DEFAULT_INSTALLED_MODULES)\
   1443       $(ALL_PDK_FUSION_FILES))
   1444 
   1445 INSTALLED_FILES_FILE_SYSTEMOTHER := $(PRODUCT_OUT)/installed-files-system-other.txt
   1446 $(INSTALLED_FILES_FILE_SYSTEMOTHER) : $(INTERNAL_SYSTEMOTHERIMAGE_FILES)
   1447 	@echo Installed file list: $@
   1448 	@mkdir -p $(dir $@)
   1449 	@rm -f $@
   1450 	$(hide) build/tools/fileslist.py $(TARGET_OUT_SYSTEM_OTHER) > $@
   1451 
   1452 systemotherimage_intermediates := \
   1453     $(call intermediates-dir-for,PACKAGING,system_other)
   1454 BUILT_SYSTEMOTHERIMAGE_TARGET := $(PRODUCT_OUT)/system_other.img
   1455 
   1456 # Note that we assert the size is SYSTEMIMAGE_PARTITION_SIZE since this is the 'b' system image.
   1457 define build-systemotherimage-target
   1458   $(call pretty,"Target system_other fs image: $(INSTALLED_SYSTEMOTHERIMAGE_TARGET)")
   1459   @mkdir -p $(TARGET_OUT_SYSTEM_OTHER)
   1460   @mkdir -p $(systemotherimage_intermediates) && rm -rf $(systemotherimage_intermediates)/system_other_image_info.txt
   1461   $(call generate-userimage-prop-dictionary, $(systemotherimage_intermediates)/system_other_image_info.txt, skip_fsck=true)
   1462   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1463       ./build/tools/releasetools/build_image.py \
   1464       $(TARGET_OUT_SYSTEM_OTHER) $(systemotherimage_intermediates)/system_other_image_info.txt $(INSTALLED_SYSTEMOTHERIMAGE_TARGET) $(TARGET_OUT)
   1465   $(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMOTHERIMAGE_TARGET),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
   1466 endef
   1467 
   1468 # We just build this directly to the install location.
   1469 INSTALLED_SYSTEMOTHERIMAGE_TARGET := $(BUILT_SYSTEMOTHERIMAGE_TARGET)
   1470 $(INSTALLED_SYSTEMOTHERIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_SYSTEMOTHERIMAGE_FILES) $(INSTALLED_FILES_FILE_SYSTEMOTHER)
   1471 	$(build-systemotherimage-target)
   1472 
   1473 .PHONY: systemotherimage-nodeps
   1474 systemotherimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1475 	$(build-systemotherimage-target)
   1476 
   1477 endif # BOARD_USES_SYSTEM_OTHER
   1478 
   1479 
   1480 # -----------------------------------------------------------------
   1481 # vendor partition image
   1482 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1483 INTERNAL_VENDORIMAGE_FILES := \
   1484     $(filter $(TARGET_OUT_VENDOR)/%,\
   1485       $(ALL_DEFAULT_INSTALLED_MODULES)\
   1486       $(ALL_PDK_FUSION_FILES))
   1487 
   1488 # platform.zip depends on $(INTERNAL_VENDORIMAGE_FILES).
   1489 $(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_VENDORIMAGE_FILES)
   1490 
   1491 INSTALLED_FILES_FILE_VENDOR := $(PRODUCT_OUT)/installed-files-vendor.txt
   1492 $(INSTALLED_FILES_FILE_VENDOR) : $(INTERNAL_VENDORIMAGE_FILES)
   1493 	@echo Installed file list: $@
   1494 	@mkdir -p $(dir $@)
   1495 	@rm -f $@
   1496 	$(hide) build/tools/fileslist.py $(TARGET_OUT_VENDOR) > $@
   1497 
   1498 vendorimage_intermediates := \
   1499     $(call intermediates-dir-for,PACKAGING,vendor)
   1500 BUILT_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
   1501 
   1502 define build-vendorimage-target
   1503   $(call pretty,"Target vendor fs image: $(INSTALLED_VENDORIMAGE_TARGET)")
   1504   @mkdir -p $(TARGET_OUT_VENDOR)
   1505   @mkdir -p $(vendorimage_intermediates) && rm -rf $(vendorimage_intermediates)/vendor_image_info.txt
   1506   $(call generate-userimage-prop-dictionary, $(vendorimage_intermediates)/vendor_image_info.txt, skip_fsck=true)
   1507   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1508       ./build/tools/releasetools/build_image.py \
   1509       $(TARGET_OUT_VENDOR) $(vendorimage_intermediates)/vendor_image_info.txt $(INSTALLED_VENDORIMAGE_TARGET) $(TARGET_OUT)
   1510   $(hide) $(call assert-max-image-size,$(INSTALLED_VENDORIMAGE_TARGET),$(BOARD_VENDORIMAGE_PARTITION_SIZE))
   1511 endef
   1512 
   1513 # We just build this directly to the install location.
   1514 INSTALLED_VENDORIMAGE_TARGET := $(BUILT_VENDORIMAGE_TARGET)
   1515 $(INSTALLED_VENDORIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_VENDORIMAGE_FILES) $(INSTALLED_FILES_FILE_VENDOR)
   1516 	$(build-vendorimage-target)
   1517 
   1518 .PHONY: vendorimage-nodeps
   1519 vendorimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1520 	$(build-vendorimage-target)
   1521 
   1522 endif # BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1523 
   1524 # -----------------------------------------------------------------
   1525 # bring in the installer image generation defines if necessary
   1526 ifeq ($(TARGET_USE_DISKINSTALLER),true)
   1527 include bootable/diskinstaller/config.mk
   1528 endif
   1529 
   1530 # -----------------------------------------------------------------
   1531 # host tools needed to build dist and OTA packages
   1532 
   1533 build_ota_package := true
   1534 ifeq ($(TARGET_SKIP_OTA_PACKAGE),true)
   1535 build_ota_package := false
   1536 endif
   1537 ifeq ($(BUILD_OS),darwin)
   1538 build_ota_package := false
   1539 endif
   1540 ifneq ($(strip $(SANITIZE_TARGET)),)
   1541 build_ota_package := false
   1542 endif
   1543 ifeq ($(TARGET_PRODUCT),sdk)
   1544 build_ota_package := false
   1545 endif
   1546 ifneq ($(filter generic%,$(TARGET_DEVICE)),)
   1547 build_ota_package := false
   1548 endif
   1549 ifeq ($(TARGET_NO_KERNEL),true)
   1550 build_ota_package := false
   1551 endif
   1552 ifeq ($(recovery_fstab),)
   1553 build_ota_package := false
   1554 endif
   1555 ifeq ($(TARGET_BUILD_PDK),true)
   1556 build_ota_package := false
   1557 endif
   1558 
   1559 ifeq ($(build_ota_package),true)
   1560 OTATOOLS :=  $(HOST_OUT_EXECUTABLES)/minigzip \
   1561   $(HOST_OUT_EXECUTABLES)/aapt \
   1562   $(HOST_OUT_EXECUTABLES)/mkbootfs \
   1563   $(HOST_OUT_EXECUTABLES)/mkbootimg \
   1564   $(HOST_OUT_EXECUTABLES)/fs_config \
   1565   $(HOST_OUT_EXECUTABLES)/zipalign \
   1566   $(HOST_OUT_EXECUTABLES)/bsdiff \
   1567   $(HOST_OUT_EXECUTABLES)/imgdiff \
   1568   $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar \
   1569   $(HOST_OUT_JAVA_LIBRARIES)/signapk.jar \
   1570   $(HOST_OUT_JAVA_LIBRARIES)/BootSignature.jar \
   1571   $(HOST_OUT_EXECUTABLES)/mkuserimg.sh \
   1572   $(HOST_OUT_EXECUTABLES)/make_ext4fs \
   1573   $(HOST_OUT_EXECUTABLES)/mksquashfsimage.sh \
   1574   $(HOST_OUT_EXECUTABLES)/mksquashfs \
   1575   $(HOST_OUT_EXECUTABLES)/mkf2fsuserimg.sh \
   1576   $(HOST_OUT_EXECUTABLES)/make_f2fs \
   1577   $(HOST_OUT_EXECUTABLES)/simg2img \
   1578   $(HOST_OUT_EXECUTABLES)/e2fsck \
   1579   $(HOST_OUT_EXECUTABLES)/build_verity_tree \
   1580   $(HOST_OUT_EXECUTABLES)/verity_signer \
   1581   $(HOST_OUT_EXECUTABLES)/append2simg \
   1582   $(HOST_OUT_EXECUTABLES)/img2simg \
   1583   $(HOST_OUT_EXECUTABLES)/boot_signer \
   1584   $(HOST_OUT_EXECUTABLES)/fec \
   1585   $(HOST_OUT_EXECUTABLES)/brillo_update_payload \
   1586   $(HOST_OUT_EXECUTABLES)/lib/shflags/shflags \
   1587   $(HOST_OUT_EXECUTABLES)/delta_generator \
   1588   $(BLK_ALLOC_TO_BASE_FS)
   1589 
   1590 # Shared libraries.
   1591 OTATOOLS += \
   1592   $(HOST_LIBRARY_PATH)/libc++$(HOST_SHLIB_SUFFIX) \
   1593   $(HOST_LIBRARY_PATH)/liblog$(HOST_SHLIB_SUFFIX) \
   1594   $(HOST_LIBRARY_PATH)/libcutils$(HOST_SHLIB_SUFFIX) \
   1595   $(HOST_LIBRARY_PATH)/libselinux$(HOST_SHLIB_SUFFIX) \
   1596   $(HOST_LIBRARY_PATH)/libcrypto-host$(HOST_SHLIB_SUFFIX) \
   1597   $(HOST_LIBRARY_PATH)/libdivsufsort$(HOST_SHLIB_SUFFIX) \
   1598   $(HOST_LIBRARY_PATH)/libdivsufsort64$(HOST_SHLIB_SUFFIX) \
   1599   $(HOST_LIBRARY_PATH)/libext2fs-host$(HOST_SHLIB_SUFFIX) \
   1600   $(HOST_LIBRARY_PATH)/libext2_blkid-host$(HOST_SHLIB_SUFFIX) \
   1601   $(HOST_LIBRARY_PATH)/libext2_com_err-host$(HOST_SHLIB_SUFFIX) \
   1602   $(HOST_LIBRARY_PATH)/libext2_e2p-host$(HOST_SHLIB_SUFFIX) \
   1603   $(HOST_LIBRARY_PATH)/libext2_profile-host$(HOST_SHLIB_SUFFIX) \
   1604   $(HOST_LIBRARY_PATH)/libext2_quota-host$(HOST_SHLIB_SUFFIX) \
   1605   $(HOST_LIBRARY_PATH)/libext2_uuid-host$(HOST_SHLIB_SUFFIX) \
   1606   $(HOST_LIBRARY_PATH)/libconscrypt_openjdk_jni$(HOST_SHLIB_SUFFIX) \
   1607   $(HOST_LIBRARY_PATH)/libbrillo$(HOST_SHLIB_SUFFIX) \
   1608   $(HOST_LIBRARY_PATH)/libbrillo-stream$(HOST_SHLIB_SUFFIX) \
   1609   $(HOST_LIBRARY_PATH)/libbrillo-http$(HOST_SHLIB_SUFFIX) \
   1610   $(HOST_LIBRARY_PATH)/libchrome$(HOST_SHLIB_SUFFIX) \
   1611   $(HOST_LIBRARY_PATH)/libcurl-host$(HOST_SHLIB_SUFFIX) \
   1612   $(HOST_LIBRARY_PATH)/libevent-host$(HOST_SHLIB_SUFFIX) \
   1613   $(HOST_LIBRARY_PATH)/libprotobuf-cpp-lite$(HOST_SHLIB_SUFFIX) \
   1614   $(HOST_LIBRARY_PATH)/libssl-host$(HOST_SHLIB_SUFFIX) \
   1615   $(HOST_LIBRARY_PATH)/libz-host$(HOST_SHLIB_SUFFIX) \
   1616   $(HOST_LIBRARY_PATH)/libbase$(HOST_SHLIB_SUFFIX)
   1617 
   1618 .PHONY: otatools
   1619 otatools: $(OTATOOLS)
   1620 
   1621 BUILT_OTATOOLS_PACKAGE := $(PRODUCT_OUT)/otatools.zip
   1622 $(BUILT_OTATOOLS_PACKAGE): zip_root := $(call intermediates-dir-for,PACKAGING,otatools)/otatools
   1623 
   1624 $(BUILT_OTATOOLS_PACKAGE): $(OTATOOLS) | $(ACP)
   1625 	@echo "Package OTA tools: $@"
   1626 	$(hide) rm -rf $@ $(zip_root)
   1627 	$(hide) mkdir -p $(dir $@) $(zip_root)/bin $(zip_root)/framework $(zip_root)/releasetools $(zip_root)/system/extras/verity
   1628 	$(call copy-files-with-structure,$(OTATOOLS),$(HOST_OUT)/,$(zip_root))
   1629 	$(hide) $(ACP) $(HOST_OUT_JAVA_LIBRARIES)/VeritySigner.jar $(zip_root)/framework/
   1630 	$(hide) $(ACP) -p system/extras/verity/build_verity_metadata.py $(zip_root)/system/extras/verity/
   1631 	$(hide) $(ACP) -r -d -p build/tools/releasetools/* $(zip_root)/releasetools
   1632 	$(hide) rm -rf $@ $(zip_root)/releasetools/*.pyc
   1633 	$(hide) (cd $(zip_root) && zip -qryX $(abspath $@) *)
   1634 	$(hide) zip -qryX $(abspath $@) build/target/product/security/
   1635 	$(hide) find device vendor -name \*.pk8 -o -name verifiedboot\* -o -name \*.x509.pem -o -name oem\*.prop | xargs zip -qryX $(abspath $@)>/dev/null || true
   1636 
   1637 .PHONY: otatools-package
   1638 otatools-package: $(BUILT_OTATOOLS_PACKAGE)
   1639 
   1640 endif # build_ota_package
   1641 
   1642 # -----------------------------------------------------------------
   1643 # A zip of the directories that map to the target filesystem.
   1644 # This zip can be used to create an OTA package or filesystem image
   1645 # as a post-build step.
   1646 #
   1647 name := $(TARGET_PRODUCT)
   1648 ifeq ($(TARGET_BUILD_TYPE),debug)
   1649   name := $(name)_debug
   1650 endif
   1651 name := $(name)-target_files-$(FILE_NAME_TAG)
   1652 
   1653 intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
   1654 BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
   1655 $(BUILT_TARGET_FILES_PACKAGE): intermediates := $(intermediates)
   1656 $(BUILT_TARGET_FILES_PACKAGE): \
   1657 		zip_root := $(intermediates)/$(name)
   1658 
   1659 # $(1): Directory to copy
   1660 # $(2): Location to copy it to
   1661 # The "ls -A" is to prevent "acp s/* d" from failing if s is empty.
   1662 define package_files-copy-root
   1663   if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
   1664     mkdir -p $(2) && \
   1665     $(ACP) -rd $(strip $(1))/* $(2); \
   1666   fi
   1667 endef
   1668 
   1669 built_ota_tools :=
   1670 
   1671 # We can't build static executables when SANITIZE_TARGET=address
   1672 ifeq ($(strip $(SANITIZE_TARGET)),)
   1673 built_ota_tools += \
   1674     $(call intermediates-dir-for,EXECUTABLES,updater,,,$(TARGET_PREFER_32_BIT))/updater
   1675 endif
   1676 
   1677 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_OTA_TOOLS := $(built_ota_tools)
   1678 
   1679 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_API_VERSION := $(RECOVERY_API_VERSION)
   1680 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_FSTAB_VERSION := $(RECOVERY_FSTAB_VERSION)
   1681 
   1682 ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
   1683 # default to common dir for device vendor
   1684 $(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_DEVICE_DIR)/../common
   1685 else
   1686 $(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
   1687 endif
   1688 
   1689 # Build OTA tools if not using the AB Updater.
   1690 ifneq ($(AB_OTA_UPDATER),true)
   1691 $(BUILT_TARGET_FILES_PACKAGE): $(built_ota_tools)
   1692 endif
   1693 
   1694 # If we are using recovery as boot, output recovery files to BOOT/.
   1695 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
   1696 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := BOOT
   1697 else
   1698 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := RECOVERY
   1699 endif
   1700 
   1701 # Depending on the various images guarantees that the underlying
   1702 # directories are up-to-date.
   1703 $(BUILT_TARGET_FILES_PACKAGE): \
   1704 		$(INSTALLED_BOOTIMAGE_TARGET) \
   1705 		$(INSTALLED_RADIOIMAGE_TARGET) \
   1706 		$(INSTALLED_RECOVERYIMAGE_TARGET) \
   1707 		$(INSTALLED_SYSTEMIMAGE) \
   1708 		$(INSTALLED_USERDATAIMAGE_TARGET) \
   1709 		$(INSTALLED_CACHEIMAGE_TARGET) \
   1710 		$(INSTALLED_VENDORIMAGE_TARGET) \
   1711 		$(INSTALLED_SYSTEMOTHERIMAGE_TARGET) \
   1712 		$(INSTALLED_ANDROID_INFO_TXT_TARGET) \
   1713 		$(SELINUX_FC) \
   1714 		$(APKCERTS_FILE) \
   1715 		$(HOST_OUT_EXECUTABLES)/fs_config \
   1716 		| $(ACP)
   1717 	@echo "Package target files: $@"
   1718 	$(hide) rm -rf $@ $(zip_root)
   1719 	$(hide) mkdir -p $(dir $@) $(zip_root)
   1720 ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)))
   1721 	@# Components of the recovery image
   1722 	$(hide) mkdir -p $(zip_root)/$(PRIVATE_RECOVERY_OUT)
   1723 	$(hide) $(call package_files-copy-root, \
   1724 		$(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/$(PRIVATE_RECOVERY_OUT)/RAMDISK)
   1725 ifdef INSTALLED_KERNEL_TARGET
   1726 	$(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/kernel
   1727 endif
   1728 ifdef INSTALLED_2NDBOOTLOADER_TARGET
   1729 	$(hide) $(ACP) \
   1730 		$(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/second
   1731 endif
   1732 ifdef BOARD_KERNEL_CMDLINE
   1733 	$(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/cmdline
   1734 endif
   1735 ifdef BOARD_KERNEL_BASE
   1736 	$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/base
   1737 endif
   1738 ifdef BOARD_KERNEL_PAGESIZE
   1739 	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/pagesize
   1740 endif
   1741 endif # INSTALLED_RECOVERYIMAGE_TARGET defined or BOARD_USES_RECOVERY_AS_BOOT is true
   1742 	@# Components of the boot image
   1743 	$(hide) mkdir -p $(zip_root)/BOOT
   1744 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
   1745 	$(hide) mkdir -p $(zip_root)/ROOT
   1746 	$(hide) $(call package_files-copy-root, \
   1747 		$(TARGET_ROOT_OUT),$(zip_root)/ROOT)
   1748 else
   1749 	$(hide) $(call package_files-copy-root, \
   1750 		$(TARGET_ROOT_OUT),$(zip_root)/BOOT/RAMDISK)
   1751 endif
   1752 	@# If we are using recovery as boot, this is already done when processing recovery.
   1753 ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
   1754 ifdef INSTALLED_KERNEL_TARGET
   1755 	$(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/kernel
   1756 endif
   1757 ifdef INSTALLED_2NDBOOTLOADER_TARGET
   1758 	$(hide) $(ACP) \
   1759 		$(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second
   1760 endif
   1761 ifdef BOARD_KERNEL_CMDLINE
   1762 	$(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
   1763 endif
   1764 ifdef BOARD_KERNEL_BASE
   1765 	$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base
   1766 endif
   1767 ifdef BOARD_KERNEL_PAGESIZE
   1768 	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesize
   1769 endif
   1770 endif # BOARD_USES_RECOVERY_AS_BOOT
   1771 	$(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\
   1772 	            mkdir -p $(zip_root)/RADIO; \
   1773 	            $(ACP) $(t) $(zip_root)/RADIO/$(notdir $(t));)
   1774 	@# Contents of the system image
   1775 	$(hide) $(call package_files-copy-root, \
   1776 		$(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
   1777 	@# Contents of the data image
   1778 	$(hide) $(call package_files-copy-root, \
   1779 		$(TARGET_OUT_DATA),$(zip_root)/DATA)
   1780 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1781 	@# Contents of the vendor image
   1782 	$(hide) $(call package_files-copy-root, \
   1783 		$(TARGET_OUT_VENDOR),$(zip_root)/VENDOR)
   1784 endif
   1785 ifdef INSTALLED_SYSTEMOTHERIMAGE_TARGET
   1786 	@# Contents of the system_other image
   1787 	$(hide) $(call package_files-copy-root, \
   1788 		$(TARGET_OUT_SYSTEM_OTHER),$(zip_root)/SYSTEM_OTHER)
   1789 endif
   1790 	@# Extra contents of the OTA package
   1791 	$(hide) mkdir -p $(zip_root)/OTA
   1792 	$(hide) $(ACP) $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/
   1793 ifneq ($(AB_OTA_UPDATER),true)
   1794 ifneq ($(built_ota_tools),)
   1795 	$(hide) mkdir -p $(zip_root)/OTA/bin
   1796 	$(hide) $(ACP) $(PRIVATE_OTA_TOOLS) $(zip_root)/OTA/bin/
   1797 endif
   1798 endif
   1799 	@# Files that do not end up in any images, but are necessary to
   1800 	@# build them.
   1801 	$(hide) mkdir -p $(zip_root)/META
   1802 	$(hide) $(ACP) $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
   1803 	$(hide) if test -e $(tool_extensions)/releasetools.py; then $(ACP) $(tool_extensions)/releasetools.py $(zip_root)/META/; fi
   1804 	$(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
   1805 	$(hide) $(ACP) $(SELINUX_FC) $(zip_root)/META/file_contexts.bin
   1806 	$(hide) echo "recovery_api_version=$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/misc_info.txt
   1807 	$(hide) echo "fstab_version=$(PRIVATE_RECOVERY_FSTAB_VERSION)" >> $(zip_root)/META/misc_info.txt
   1808 ifdef BOARD_FLASH_BLOCK_SIZE
   1809 	$(hide) echo "blocksize=$(BOARD_FLASH_BLOCK_SIZE)" >> $(zip_root)/META/misc_info.txt
   1810 endif
   1811 ifdef BOARD_BOOTIMAGE_PARTITION_SIZE
   1812 	$(hide) echo "boot_size=$(BOARD_BOOTIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
   1813 endif
   1814 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),)
   1815 	$(hide) echo "recovery_as_boot=$(BOARD_USES_RECOVERY_AS_BOOT)" >> $(zip_root)/META/misc_info.txt
   1816 endif
   1817 ifeq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   1818 	$(hide) echo "no_recovery=true" >> $(zip_root)/META/misc_info.txt
   1819 endif
   1820 ifdef BOARD_RECOVERYIMAGE_PARTITION_SIZE
   1821 	$(hide) echo "recovery_size=$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
   1822 endif
   1823 ifdef BOARD_HAS_EXT4_RESERVED_BLOCKS
   1824 	$(hide) echo "has_ext4_reserved_blocks=$(BOARD_HAS_EXT4_RESERVED_BLOCKS)" >> $(zip_root)/META/misc_info.txt
   1825 endif
   1826 ifdef TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS
   1827 	@# TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS can be empty to indicate that nothing but defaults should be used.
   1828 	$(hide) echo "recovery_mount_options=$(TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $(zip_root)/META/misc_info.txt
   1829 else
   1830 	$(hide) echo "recovery_mount_options=$(DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $(zip_root)/META/misc_info.txt
   1831 endif
   1832 	$(hide) echo "tool_extensions=$(tool_extensions)" >> $(zip_root)/META/misc_info.txt
   1833 	$(hide) echo "default_system_dev_certificate=$(DEFAULT_SYSTEM_DEV_CERTIFICATE)" >> $(zip_root)/META/misc_info.txt
   1834 ifdef PRODUCT_EXTRA_RECOVERY_KEYS
   1835 	$(hide) echo "extra_recovery_keys=$(PRODUCT_EXTRA_RECOVERY_KEYS)" >> $(zip_root)/META/misc_info.txt
   1836 endif
   1837 	$(hide) echo 'mkbootimg_args=$(BOARD_MKBOOTIMG_ARGS)' >> $(zip_root)/META/misc_info.txt
   1838 	$(hide) echo 'mkbootimg_version_args=$(INTERNAL_MKBOOTIMG_VERSION_ARGS)' >> $(zip_root)/META/misc_info.txt
   1839 	$(hide) echo "use_set_metadata=1" >> $(zip_root)/META/misc_info.txt
   1840 	$(hide) echo "multistage_support=1" >> $(zip_root)/META/misc_info.txt
   1841 	$(hide) echo "update_rename_support=1" >> $(zip_root)/META/misc_info.txt
   1842 	$(hide) echo "blockimgdiff_versions=1,2,3,4" >> $(zip_root)/META/misc_info.txt
   1843 ifneq ($(OEM_THUMBPRINT_PROPERTIES),)
   1844 	# OTA scripts are only interested in fingerprint related properties
   1845 	$(hide) echo "oem_fingerprint_properties=$(OEM_THUMBPRINT_PROPERTIES)" >> $(zip_root)/META/misc_info.txt
   1846 endif
   1847 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH),)
   1848 	$(hide) $(ACP) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH) \
   1849 	  $(zip_root)/META/$(notdir $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH))
   1850 endif
   1851 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH),)
   1852 	$(hide) $(ACP) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH) \
   1853 	  $(zip_root)/META/$(notdir $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH))
   1854 endif
   1855 ifneq ($(strip $(SANITIZE_TARGET)),)
   1856 	# We need to create userdata.img with real data because the instrumented libraries are in userdata.img.
   1857 	$(hide) echo "userdata_img_with_data=true" >> $(zip_root)/META/misc_info.txt
   1858 endif
   1859 ifeq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
   1860 	$(hide) echo "full_recovery_image=true" >> $(zip_root)/META/misc_info.txt
   1861 endif
   1862 	$(call generate-userimage-prop-dictionary, $(zip_root)/META/misc_info.txt)
   1863 ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   1864 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   1865 	    ./build/tools/releasetools/make_recovery_patch $(zip_root) $(zip_root)
   1866 endif
   1867 ifeq ($(AB_OTA_UPDATER),true)
   1868 	@# When using the A/B updater, include the updater config files in the zip.
   1869 	$(hide) $(ACP) $(TOPDIR)system/update_engine/update_engine.conf $(zip_root)/META/update_engine_config.txt
   1870 	$(hide) for part in $(AB_OTA_PARTITIONS); do \
   1871 	  echo "$${part}" >> $(zip_root)/META/ab_partitions.txt; \
   1872 	done
   1873 	$(hide) for conf in $(AB_OTA_POSTINSTALL_CONFIG); do \
   1874 	  echo "$${conf}" >> $(zip_root)/META/postinstall_config.txt; \
   1875 	done
   1876 	@# Include the build type in META/misc_info.txt so the server can easily differentiate production builds.
   1877 	$(hide) echo "build_type=$(TARGET_BUILD_VARIANT)" >> $(zip_root)/META/misc_info.txt
   1878 	$(hide) echo "ab_update=true" >> $(zip_root)/META/misc_info.txt
   1879 ifdef OSRELEASED_DIRECTORY
   1880 	$(hide) $(ACP) $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/product_id $(zip_root)/META/product_id.txt
   1881 	$(hide) $(ACP) $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/product_version $(zip_root)/META/product_version.txt
   1882 endif
   1883 endif
   1884 ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
   1885 	@# If breakpad symbols have been generated, add them to the zip.
   1886 	$(hide) $(ACP) -r $(TARGET_OUT_BREAKPAD) $(zip_root)/BREAKPAD
   1887 endif
   1888 	@# Zip everything up, preserving symlinks and placing META/ files first to
   1889 	@# help early validation of the .zip file while uploading it.
   1890 	$(hide) (cd $(zip_root) && \
   1891 	        zip -qryX ../$(notdir $@) ./META && \
   1892 	        zip -qryXu ../$(notdir $@) .)
   1893 	@# Run fs_config on all the system, vendor, boot ramdisk,
   1894 	@# and recovery ramdisk files in the zip, and save the output
   1895 	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="SYSTEM/" } /^SYSTEM\// {print "system/" $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/filesystem_config.txt
   1896 	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="VENDOR/" } /^VENDOR\// {print "vendor/" $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/vendor_filesystem_config.txt
   1897 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
   1898 	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="ROOT/" } /^ROOT\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/root_filesystem_config.txt
   1899 endif
   1900 	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="BOOT/RAMDISK/" } /^BOOT\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/boot_filesystem_config.txt
   1901 ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   1902 	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="RECOVERY/RAMDISK/" } /^RECOVERY\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/recovery_filesystem_config.txt
   1903 endif
   1904 ifdef INSTALLED_SYSTEMOTHERIMAGE_TARGET
   1905 	$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="SYSTEM_OTHER/" } /^SYSTEM_OTHER\// { print "system/" $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) > $(zip_root)/META/system_other_filesystem_config.txt
   1906 endif
   1907 	$(hide) (cd $(zip_root) && zip -qX ../$(notdir $@) META/*filesystem_config.txt)
   1908 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   1909 	    ./build/tools/releasetools/add_img_to_target_files -v -p $(HOST_OUT) $@
   1910 
   1911 .PHONY: target-files-package
   1912 target-files-package: $(BUILT_TARGET_FILES_PACKAGE)
   1913 
   1914 ifneq ($(filter $(MAKECMDGOALS),target-files-package),)
   1915 $(call dist-for-goals, target-files-package, $(BUILT_TARGET_FILES_PACKAGE))
   1916 endif
   1917 
   1918 ifeq ($(build_ota_package),true)
   1919 # -----------------------------------------------------------------
   1920 # OTA update package
   1921 
   1922 name := $(TARGET_PRODUCT)
   1923 ifeq ($(TARGET_BUILD_TYPE),debug)
   1924   name := $(name)_debug
   1925 endif
   1926 name := $(name)-ota-$(FILE_NAME_TAG)
   1927 
   1928 INTERNAL_OTA_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   1929 
   1930 $(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
   1931 
   1932 $(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE)
   1933 	@echo "Package OTA: $@"
   1934 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   1935 	   ./build/tools/releasetools/ota_from_target_files -v \
   1936 	   --block \
   1937 	   -p $(HOST_OUT) \
   1938 	   -k $(KEY_CERT_PAIR) \
   1939 	   $(if $(OEM_OTA_CONFIG), -o $(OEM_OTA_CONFIG)) \
   1940 	   $(BUILT_TARGET_FILES_PACKAGE) $@
   1941 
   1942 .PHONY: otapackage
   1943 otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)
   1944 
   1945 endif    # build_ota_package
   1946 
   1947 # -----------------------------------------------------------------
   1948 # The update package
   1949 
   1950 name := $(TARGET_PRODUCT)
   1951 ifeq ($(TARGET_BUILD_TYPE),debug)
   1952   name := $(name)_debug
   1953 endif
   1954 name := $(name)-img-$(FILE_NAME_TAG)
   1955 
   1956 INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   1957 
   1958 $(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE)
   1959 	@echo "Package: $@"
   1960 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   1961 	   ./build/tools/releasetools/img_from_target_files -v \
   1962 	   -p $(HOST_OUT) \
   1963 	   $(BUILT_TARGET_FILES_PACKAGE) $@
   1964 
   1965 .PHONY: updatepackage
   1966 updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
   1967 
   1968 # -----------------------------------------------------------------
   1969 # A zip of the symbols directory.  Keep the full paths to make it
   1970 # more obvious where these files came from.
   1971 #
   1972 name := $(TARGET_PRODUCT)
   1973 ifeq ($(TARGET_BUILD_TYPE),debug)
   1974   name := $(name)_debug
   1975 endif
   1976 name := $(name)-symbols-$(FILE_NAME_TAG)
   1977 
   1978 SYMBOLS_ZIP := $(PRODUCT_OUT)/$(name).zip
   1979 # For apps_only build we'll establish the dependency later in build/core/main.mk.
   1980 ifndef TARGET_BUILD_APPS
   1981 $(SYMBOLS_ZIP): $(INSTALLED_SYSTEMIMAGE) $(INSTALLED_BOOTIMAGE_TARGET)
   1982 endif
   1983 $(SYMBOLS_ZIP):
   1984 	@echo "Package symbols: $@"
   1985 	$(hide) rm -rf $@
   1986 	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_UNSTRIPPED)
   1987 	$(hide) zip -qrX $@ $(TARGET_OUT_UNSTRIPPED)
   1988 
   1989 # -----------------------------------------------------------------
   1990 # A zip of the Android Apps. Not keeping full path so that we don't
   1991 # include product names when distributing
   1992 #
   1993 name := $(TARGET_PRODUCT)
   1994 ifeq ($(TARGET_BUILD_TYPE),debug)
   1995   name := $(name)_debug
   1996 endif
   1997 name := $(name)-apps-$(FILE_NAME_TAG)
   1998 
   1999 APPS_ZIP := $(PRODUCT_OUT)/$(name).zip
   2000 $(APPS_ZIP): $(INSTALLED_SYSTEMIMAGE)
   2001 	@echo "Package apps: $@"
   2002 	$(hide) rm -rf $@
   2003 	$(hide) mkdir -p $(dir $@)
   2004 	$(hide) apps_to_zip=`find $(TARGET_OUT_APPS) $(TARGET_OUT_APPS_PRIVILEGED) -mindepth 2 -maxdepth 3 -name "*.apk"`; \
   2005 	if [ -z "$$apps_to_zip" ]; then \
   2006 		echo "No apps to zip up. Generating empty apps archive." ; \
   2007 		a=$$(mktemp /tmp/XXXXXXX) && touch $$a && zip $@ $$a && zip -d $@ $$a; \
   2008 	else \
   2009 		zip -qjX $@ $$apps_to_zip; \
   2010 	fi
   2011 
   2012 #------------------------------------------------------------------
   2013 # A zip of emma code coverage meta files. Generated for fully emma
   2014 # instrumented build.
   2015 #
   2016 ifeq (true,$(EMMA_INSTRUMENT))
   2017 EMMA_META_ZIP := $(PRODUCT_OUT)/emma_meta.zip
   2018 # the dependency will be set up later in build/core/main.mk.
   2019 $(EMMA_META_ZIP) :
   2020 	@echo "Collecting Emma coverage meta files."
   2021 	$(hide) find $(TARGET_COMMON_OUT_ROOT) $(HOST_COMMON_OUT_ROOT) -name "coverage.em" | \
   2022 		zip -@ -qX $@
   2023 
   2024 endif # EMMA_INSTRUMENT=true
   2025 
   2026 #------------------------------------------------------------------
   2027 # A zip of Proguard obfuscation dictionary files.
   2028 # Only for apps_only build.
   2029 #
   2030 ifdef TARGET_BUILD_APPS
   2031 PROGUARD_DICT_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-$(FILE_NAME_TAG).zip
   2032 # the dependency will be set up later in build/core/main.mk.
   2033 $(PROGUARD_DICT_ZIP) :
   2034 	@echo "Packaging Proguard obfuscation dictionary files."
   2035 	$(hide) dict_files=`find $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS -name proguard_dictionary`; \
   2036 		if [ -n "$$dict_files" ]; then \
   2037 		  unobfuscated_jars=$${dict_files//proguard_dictionary/classes.jar}; \
   2038 		  zip -qX $@ $$dict_files $$unobfuscated_jars; \
   2039 		else \
   2040 		  touch $(dir $@)/zipdummy; \
   2041 		  (cd $(dir $@) && zip -q $(notdir $@) zipdummy); \
   2042 		  zip -qd $@ zipdummy; \
   2043 		  rm $(dir $@)/zipdummy; \
   2044 		fi
   2045 
   2046 endif # TARGET_BUILD_APPS
   2047 
   2048 # -----------------------------------------------------------------
   2049 # dalvik something
   2050 .PHONY: dalvikfiles
   2051 dalvikfiles: $(INTERNAL_DALVIK_MODULES)
   2052 
   2053 # -----------------------------------------------------------------
   2054 # The emulator package
   2055 ifeq ($(BUILD_EMULATOR),true)
   2056 INTERNAL_EMULATOR_PACKAGE_FILES += \
   2057         $(HOST_OUT_EXECUTABLES)/emulator$(HOST_EXECUTABLE_SUFFIX) \
   2058         prebuilts/qemu-kernel/$(TARGET_ARCH)/kernel-qemu \
   2059         $(INSTALLED_RAMDISK_TARGET) \
   2060 		$(INSTALLED_SYSTEMIMAGE) \
   2061 		$(INSTALLED_USERDATAIMAGE_TARGET)
   2062 
   2063 name := $(TARGET_PRODUCT)-emulator-$(FILE_NAME_TAG)
   2064 
   2065 INTERNAL_EMULATOR_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   2066 
   2067 $(INTERNAL_EMULATOR_PACKAGE_TARGET): $(INTERNAL_EMULATOR_PACKAGE_FILES)
   2068 	@echo "Package: $@"
   2069 	$(hide) zip -qjX $@ $(INTERNAL_EMULATOR_PACKAGE_FILES)
   2070 
   2071 endif
   2072 # -----------------------------------------------------------------
   2073 # Old PDK stuffs, retired
   2074 # The pdk package (Platform Development Kit)
   2075 
   2076 #ifneq (,$(filter pdk,$(MAKECMDGOALS)))
   2077 #  include development/pdk/Pdk.mk
   2078 #endif
   2079 
   2080 
   2081 # -----------------------------------------------------------------
   2082 # The SDK
   2083 
   2084 # The SDK includes host-specific components, so it belongs under HOST_OUT.
   2085 sdk_dir := $(HOST_OUT)/sdk/$(TARGET_PRODUCT)
   2086 
   2087 # Build a name that looks like:
   2088 #
   2089 #     linux-x86   --> android-sdk_12345_linux-x86
   2090 #     darwin-x86  --> android-sdk_12345_mac-x86
   2091 #     windows-x86 --> android-sdk_12345_windows
   2092 #
   2093 sdk_name := android-sdk_$(FILE_NAME_TAG)
   2094 ifeq ($(HOST_OS),darwin)
   2095   INTERNAL_SDK_HOST_OS_NAME := mac
   2096 else
   2097   INTERNAL_SDK_HOST_OS_NAME := $(HOST_OS)
   2098 endif
   2099 ifneq ($(HOST_OS),windows)
   2100   INTERNAL_SDK_HOST_OS_NAME := $(INTERNAL_SDK_HOST_OS_NAME)-$(SDK_HOST_ARCH)
   2101 endif
   2102 sdk_name := $(sdk_name)_$(INTERNAL_SDK_HOST_OS_NAME)
   2103 
   2104 sdk_dep_file := $(sdk_dir)/sdk_deps.mk
   2105 
   2106 ATREE_FILES :=
   2107 -include $(sdk_dep_file)
   2108 
   2109 # if we don't have a real list, then use "everything"
   2110 ifeq ($(strip $(ATREE_FILES)),)
   2111 ATREE_FILES := \
   2112 	$(ALL_PREBUILT) \
   2113 	$(ALL_DEFAULT_INSTALLED_MODULES) \
   2114 	$(INSTALLED_RAMDISK_TARGET) \
   2115 	$(ALL_DOCS) \
   2116 	$(ALL_SDK_FILES)
   2117 endif
   2118 
   2119 atree_dir := development/build
   2120 
   2121 
   2122 sdk_atree_files := \
   2123 	$(atree_dir)/sdk.exclude.atree \
   2124 	$(atree_dir)/sdk-$(HOST_OS)-$(SDK_HOST_ARCH).atree
   2125 
   2126 # development/build/sdk-android-<abi>.atree is used to differentiate
   2127 # between architecture models (e.g. ARMv5TE versus ARMv7) when copying
   2128 # files like the kernel image. We use TARGET_CPU_ABI because we don't
   2129 # have a better way to distinguish between CPU models.
   2130 ifneq (,$(strip $(wildcard $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree)))
   2131   sdk_atree_files += $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree
   2132 endif
   2133 
   2134 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ATREE_FILES),)
   2135 sdk_atree_files += $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ATREE_FILES)
   2136 else
   2137 sdk_atree_files += $(atree_dir)/sdk.atree
   2138 endif
   2139 
   2140 include $(BUILD_SYSTEM)/sdk_font.mk
   2141 
   2142 deps := \
   2143 	$(target_notice_file_txt) \
   2144 	$(tools_notice_file_txt) \
   2145 	$(OUT_DOCS)/offline-sdk-timestamp \
   2146 	$(SYMBOLS_ZIP) \
   2147 	$(INSTALLED_SYSTEMIMAGE) \
   2148 	$(INSTALLED_USERDATAIMAGE_TARGET) \
   2149 	$(INSTALLED_RAMDISK_TARGET) \
   2150 	$(INSTALLED_SDK_BUILD_PROP_TARGET) \
   2151 	$(INSTALLED_BUILD_PROP_TARGET) \
   2152 	$(ATREE_FILES) \
   2153 	$(sdk_atree_files) \
   2154 	$(HOST_OUT_EXECUTABLES)/atree \
   2155 	$(HOST_OUT_EXECUTABLES)/line_endings \
   2156 	$(SDK_FONT_DEPS)
   2157 
   2158 INTERNAL_SDK_TARGET := $(sdk_dir)/$(sdk_name).zip
   2159 $(INTERNAL_SDK_TARGET): PRIVATE_NAME := $(sdk_name)
   2160 $(INTERNAL_SDK_TARGET): PRIVATE_DIR := $(sdk_dir)/$(sdk_name)
   2161 $(INTERNAL_SDK_TARGET): PRIVATE_DEP_FILE := $(sdk_dep_file)
   2162 $(INTERNAL_SDK_TARGET): PRIVATE_INPUT_FILES := $(sdk_atree_files)
   2163 
   2164 # Set SDK_GNU_ERROR to non-empty to fail when a GNU target is built.
   2165 #
   2166 #SDK_GNU_ERROR := true
   2167 
   2168 $(INTERNAL_SDK_TARGET): $(deps)
   2169 	@echo "Package SDK: $@"
   2170 	$(hide) rm -rf $(PRIVATE_DIR) $@
   2171 	$(hide) for f in $(target_gnu_MODULES); do \
   2172 	  if [ -f $$f ]; then \
   2173 	    echo SDK: $(if $(SDK_GNU_ERROR),ERROR:,warning:) \
   2174 	        including GNU target $$f >&2; \
   2175 	    FAIL=$(SDK_GNU_ERROR); \
   2176 	  fi; \
   2177 	done; \
   2178 	if [ $$FAIL ]; then exit 1; fi
   2179 	$(hide) echo $(notdir $(SDK_FONT_DEPS)) | tr " " "\n"  > $(SDK_FONT_TEMP)/fontsInSdk.txt
   2180 	$(hide) ( \
   2181 		ATREE_STRIP="strip -x" \
   2182 		$(HOST_OUT_EXECUTABLES)/atree \
   2183 		$(addprefix -f ,$(PRIVATE_INPUT_FILES)) \
   2184 			-m $(PRIVATE_DEP_FILE) \
   2185 			-I . \
   2186 			-I $(PRODUCT_OUT) \
   2187 			-I $(HOST_OUT) \
   2188 			-I $(TARGET_COMMON_OUT_ROOT) \
   2189 			-v "PLATFORM_NAME=android-$(PLATFORM_VERSION)" \
   2190 			-v "OUT_DIR=$(OUT_DIR)" \
   2191 			-v "HOST_OUT=$(HOST_OUT)" \
   2192 			-v "TARGET_ARCH=$(TARGET_ARCH)" \
   2193 			-v "TARGET_CPU_ABI=$(TARGET_CPU_ABI)" \
   2194 			-v "DLL_EXTENSION=$(HOST_SHLIB_SUFFIX)" \
   2195 			-v "FONT_OUT=$(SDK_FONT_TEMP)" \
   2196 			-v "JACK_SDKTOOL_VERSION=$(JACK_SDKTOOL_VERSION)" \
   2197 			-o $(PRIVATE_DIR) && \
   2198 		cp -f $(target_notice_file_txt) \
   2199 				$(PRIVATE_DIR)/system-images/android-$(PLATFORM_VERSION)/$(TARGET_CPU_ABI)/NOTICE.txt && \
   2200 		cp -f $(tools_notice_file_txt) $(PRIVATE_DIR)/platform-tools/NOTICE.txt && \
   2201 		HOST_OUT_EXECUTABLES=$(HOST_OUT_EXECUTABLES) HOST_OS=$(HOST_OS) \
   2202 			development/build/tools/sdk_clean.sh $(PRIVATE_DIR) && \
   2203 		chmod -R ug+rwX $(PRIVATE_DIR) && \
   2204 		cd $(dir $@) && zip -rqX $(notdir $@) $(PRIVATE_NAME) \
   2205 	) || ( rm -rf $(PRIVATE_DIR) $@ && exit 44 )
   2206 
   2207 
   2208 # Is a Windows SDK requested? If so, we need some definitions from here
   2209 # in order to find the Linux SDK used to create the Windows one.
   2210 MAIN_SDK_NAME := $(sdk_name)
   2211 MAIN_SDK_DIR  := $(sdk_dir)
   2212 MAIN_SDK_ZIP  := $(INTERNAL_SDK_TARGET)
   2213 ifneq ($(filter win_sdk winsdk-tools,$(MAKECMDGOALS)),)
   2214 include $(TOPDIR)development/build/tools/windows_sdk.mk
   2215 endif
   2216 
   2217 # -----------------------------------------------------------------
   2218 # Findbugs
   2219 INTERNAL_FINDBUGS_XML_TARGET := $(PRODUCT_OUT)/findbugs.xml
   2220 INTERNAL_FINDBUGS_HTML_TARGET := $(PRODUCT_OUT)/findbugs.html
   2221 $(INTERNAL_FINDBUGS_XML_TARGET): $(ALL_FINDBUGS_FILES)
   2222 	@echo UnionBugs: $@
   2223 	$(hide) $(FINDBUGS_DIR)/unionBugs $(ALL_FINDBUGS_FILES) \
   2224 	> $@
   2225 $(INTERNAL_FINDBUGS_HTML_TARGET): $(INTERNAL_FINDBUGS_XML_TARGET)
   2226 	@echo ConvertXmlToText: $@
   2227 	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl \
   2228 	$(INTERNAL_FINDBUGS_XML_TARGET) > $@
   2229 
   2230 # -----------------------------------------------------------------
   2231 # Findbugs
   2232 
   2233 # -----------------------------------------------------------------
   2234 # These are some additional build tasks that need to be run.
   2235 ifneq ($(dont_bother),true)
   2236 include $(sort $(wildcard $(BUILD_SYSTEM)/tasks/*.mk))
   2237 -include $(sort $(wildcard vendor/*/build/tasks/*.mk))
   2238 -include $(sort $(wildcard device/*/build/tasks/*.mk))
   2239 -include $(sort $(wildcard product/*/build/tasks/*.mk))
   2240 # Also the project-specific tasks
   2241 -include $(sort $(wildcard vendor/*/*/build/tasks/*.mk))
   2242 -include $(sort $(wildcard device/*/*/build/tasks/*.mk))
   2243 -include $(sort $(wildcard product/*/*/build/tasks/*.mk))
   2244 endif
   2245 
   2246 include $(BUILD_SYSTEM)/product-graph.mk
   2247 
   2248 # -----------------------------------------------------------------
   2249 # Create SDK repository packages. Must be done after tasks/* since
   2250 # we need the addon rules defined.
   2251 ifneq ($(sdk_repo_goal),)
   2252 include $(TOPDIR)development/build/tools/sdk_repo.mk
   2253 endif
   2254