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_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE))
    503 ifdef BOARD_KERNEL_CMDLINE
    504   INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)"
    505 endif
    506 
    507 BOARD_KERNEL_BASE := $(strip $(BOARD_KERNEL_BASE))
    508 ifdef BOARD_KERNEL_BASE
    509   INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
    510 endif
    511 
    512 BOARD_KERNEL_PAGESIZE := $(strip $(BOARD_KERNEL_PAGESIZE))
    513 ifdef BOARD_KERNEL_PAGESIZE
    514   INTERNAL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
    515 endif
    516 
    517 INTERNAL_MKBOOTIMG_VERSION_ARGS := \
    518     --os_version $(PLATFORM_VERSION) \
    519     --os_patch_level $(PLATFORM_SECURITY_PATCH)
    520 
    521 INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
    522 
    523 # BOARD_USES_RECOVERY_AS_BOOT = true must have BOARD_BUILD_SYSTEM_ROOT_IMAGE = true.
    524 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
    525 ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
    526   $(error BOARD_BUILD_SYSTEM_ROOT_IMAGE must be enabled for BOARD_USES_RECOVERY_AS_BOOT.)
    527 endif
    528 endif
    529 
    530 # We build recovery as boot image if BOARD_USES_RECOVERY_AS_BOOT is true.
    531 ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
    532 ifeq ($(TARGET_BOOTIMAGE_USE_EXT2),true)
    533 $(error TARGET_BOOTIMAGE_USE_EXT2 is not supported anymore)
    534 else ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER)) # TARGET_BOOTIMAGE_USE_EXT2 != true
    535 
    536 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(BOOT_SIGNER)
    537 	$(call pretty,"Target boot image: $@")
    538 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
    539 	$(BOOT_SIGNER) /boot $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $@
    540 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    541 
    542 .PHONY: bootimage-nodeps
    543 bootimage-nodeps: $(MKBOOTIMG) $(BOOT_SIGNER)
    544 	@echo "make $@: ignoring dependencies"
    545 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
    546 	$(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)
    547 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    548 
    549 else ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)) # PRODUCT_SUPPORTS_BOOT_SIGNER != true
    550 
    551 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(VBOOT_SIGNER)
    552 	$(call pretty,"Target boot image: $@")
    553 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@.unsigned
    554 	$(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 $@
    555 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    556 
    557 .PHONY: bootimage-nodeps
    558 bootimage-nodeps: $(MKBOOTIMG) $(VBOOT_SIGNER)
    559 	@echo "make $@: ignoring dependencies"
    560 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET).unsigned
    561 	$(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)
    562 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    563 
    564 else # PRODUCT_SUPPORTS_VBOOT != true
    565 
    566 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES)
    567 	$(call pretty,"Target boot image: $@")
    568 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
    569 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    570 
    571 .PHONY: bootimage-nodeps
    572 bootimage-nodeps: $(MKBOOTIMG)
    573 	@echo "make $@: ignoring dependencies"
    574 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
    575 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    576 
    577 endif # TARGET_BOOTIMAGE_USE_EXT2
    578 endif # BOARD_USES_RECOVERY_AS_BOOT
    579 
    580 else	# TARGET_NO_KERNEL
    581 # HACK: The top-level targets depend on the bootimage.  Not all targets
    582 # can produce a bootimage, though, and emulator targets need the ramdisk
    583 # instead.  Fake it out by calling the ramdisk the bootimage.
    584 # TODO: make the emulator use bootimages, and make mkbootimg accept
    585 #       kernel-less inputs.
    586 INSTALLED_BOOTIMAGE_TARGET := $(INSTALLED_RAMDISK_TARGET)
    587 endif
    588 
    589 # -----------------------------------------------------------------
    590 # NOTICE files
    591 #
    592 # We are required to publish the licenses for all code under BSD, GPL and
    593 # Apache licenses (and possibly other more exotic ones as well). We err on the
    594 # side of caution, so the licenses for other third-party code are included here
    595 # too.
    596 #
    597 # This needs to be before the systemimage rules, because it adds to
    598 # ALL_DEFAULT_INSTALLED_MODULES, which those use to pick which files
    599 # go into the systemimage.
    600 
    601 .PHONY: notice_files
    602 
    603 # Create the rule to combine the files into text and html forms
    604 # $(1) - Plain text output file
    605 # $(2) - HTML output file
    606 # $(3) - File title
    607 # $(4) - Directory to use.  Notice files are all $(4)/src.  Other
    608 #		 directories in there will be used for scratch
    609 # $(5) - Dependencies for the output files
    610 #
    611 # The algorithm here is that we go collect a hash for each of the notice
    612 # files and write the names of the files that match that hash.  Then
    613 # to generate the real files, we go print out all of the files and their
    614 # hashes.
    615 #
    616 # These rules are fairly complex, so they depend on this makefile so if
    617 # it changes, they'll run again.
    618 #
    619 # TODO: We could clean this up so that we just record the locations of the
    620 # original notice files instead of making rules to copy them somwehere.
    621 # Then we could traverse that without quite as much bash drama.
    622 define combine-notice-files
    623 $(1) $(2): PRIVATE_MESSAGE := $(3)
    624 $(1) $(2): PRIVATE_DIR := $(4)
    625 $(1) : $(2)
    626 $(2) : $(5) $(BUILD_SYSTEM)/Makefile build/tools/generate-notice-files.py
    627 	build/tools/generate-notice-files.py $(1) $(2) $$(PRIVATE_MESSAGE) $$(PRIVATE_DIR)/src
    628 notice_files: $(1) $(2)
    629 endef
    630 
    631 # TODO These intermediate NOTICE.txt/NOTICE.html files should go into
    632 # TARGET_OUT_NOTICE_FILES now that the notice files are gathered from
    633 # the src subdirectory.
    634 
    635 target_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE.txt
    636 target_notice_file_html := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html
    637 target_notice_file_html_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html.gz
    638 tools_notice_file_txt := $(HOST_OUT_INTERMEDIATES)/NOTICE.txt
    639 tools_notice_file_html := $(HOST_OUT_INTERMEDIATES)/NOTICE.html
    640 
    641 ifndef TARGET_BUILD_APPS
    642 kernel_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/kernel.txt
    643 pdk_fusion_notice_files := $(filter $(TARGET_OUT_NOTICE_FILES)/%, $(ALL_PDK_FUSION_FILES))
    644 
    645 $(eval $(call combine-notice-files, \
    646 			$(target_notice_file_txt), \
    647 			$(target_notice_file_html), \
    648 			"Notices for files contained in the filesystem images in this directory:", \
    649 			$(TARGET_OUT_NOTICE_FILES), \
    650 			$(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file) $(pdk_fusion_notice_files)))
    651 
    652 $(eval $(call combine-notice-files, \
    653 			$(tools_notice_file_txt), \
    654 			$(tools_notice_file_html), \
    655 			"Notices for files contained in the tools directory:", \
    656 			$(HOST_OUT_NOTICE_FILES), \
    657 			$(ALL_DEFAULT_INSTALLED_MODULES)))
    658 
    659 # Install the html file at /system/etc/NOTICE.html.gz.
    660 # This is not ideal, but this is very late in the game, after a lot of
    661 # the module processing has already been done -- in fact, we used the
    662 # fact that all that has been done to get the list of modules that we
    663 # need notice files for.
    664 $(target_notice_file_html_gz): $(target_notice_file_html) | $(MINIGZIP)
    665 	$(hide) $(MINIGZIP) -9 < $< > $@
    666 installed_notice_html_gz := $(TARGET_OUT)/etc/NOTICE.html.gz
    667 $(installed_notice_html_gz): $(target_notice_file_html_gz) | $(ACP)
    668 	$(copy-file-to-target)
    669 
    670 # if we've been run my mm, mmm, etc, don't reinstall this every time
    671 ifeq ($(ONE_SHOT_MAKEFILE),)
    672 ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_gz)
    673 endif
    674 endif  # TARGET_BUILD_APPS
    675 
    676 # The kernel isn't really a module, so to get its module file in there, we
    677 # make the target NOTICE files depend on this particular file too, which will
    678 # then be in the right directory for the find in combine-notice-files to work.
    679 $(kernel_notice_file): \
    680 	    $(BUILD_SYSTEM)/LINUX_KERNEL_COPYING \
    681 	    | $(ACP)
    682 	@echo Copying: $@
    683 	$(hide) mkdir -p $(dir $@)
    684 	$(hide) $(ACP) $< $@
    685 
    686 
    687 # -----------------------------------------------------------------
    688 # Build a keystore with the authorized keys in it, used to verify the
    689 # authenticity of downloaded OTA packages.
    690 #
    691 # This rule adds to ALL_DEFAULT_INSTALLED_MODULES, so it needs to come
    692 # before the rules that use that variable to build the image.
    693 ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_ETC)/security/otacerts.zip
    694 $(TARGET_OUT_ETC)/security/otacerts.zip: KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
    695 $(TARGET_OUT_ETC)/security/otacerts.zip: $(addsuffix .x509.pem,$(DEFAULT_KEY_CERT_PAIR)) | $(ZIPTIME)
    696 	$(hide) rm -f $@
    697 	$(hide) mkdir -p $(dir $@)
    698 	$(hide) zip -qjX $@ $<
    699 	$(remove-timestamps-from-package)
    700 
    701 # Carry the public key for update_engine if it's a non-Brillo target that
    702 # uses the AB updater. We use the same key as otacerts but in RSA public key
    703 # format.
    704 ifeq ($(AB_OTA_UPDATER),true)
    705 ifeq ($(BRILLO),)
    706 ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem
    707 $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem: $(addsuffix .x509.pem,$(DEFAULT_KEY_CERT_PAIR))
    708 	$(hide) rm -f $@
    709 	$(hide) mkdir -p $(dir $@)
    710 	$(hide) openssl x509 -pubkey -noout -in $< > $@
    711 endif
    712 endif
    713 
    714 .PHONY: otacerts
    715 otacerts: $(TARGET_OUT_ETC)/security/otacerts.zip
    716 
    717 
    718 # #################################################################
    719 # Targets for user images
    720 # #################################################################
    721 
    722 INTERNAL_USERIMAGES_EXT_VARIANT :=
    723 ifeq ($(TARGET_USERIMAGES_USE_EXT2),true)
    724 INTERNAL_USERIMAGES_USE_EXT := true
    725 INTERNAL_USERIMAGES_EXT_VARIANT := ext2
    726 else
    727 ifeq ($(TARGET_USERIMAGES_USE_EXT3),true)
    728 INTERNAL_USERIMAGES_USE_EXT := true
    729 INTERNAL_USERIMAGES_EXT_VARIANT := ext3
    730 else
    731 ifeq ($(TARGET_USERIMAGES_USE_EXT4),true)
    732 INTERNAL_USERIMAGES_USE_EXT := true
    733 INTERNAL_USERIMAGES_EXT_VARIANT := ext4
    734 endif
    735 endif
    736 endif
    737 
    738 # These options tell the recovery updater/installer how to mount the partitions writebale.
    739 # <fstype>=<fstype_opts>[|<fstype_opts>]...
    740 # fstype_opts := <opt>[,<opt>]...
    741 #         opt := <name>[=<value>]
    742 # The following worked on Nexus devices with Kernel 3.1, 3.4, 3.10
    743 DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS := ext4=max_batch_time=0,commit=1,data=ordered,barrier=1,errors=panic,nodelalloc
    744 
    745 ifneq (true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED))
    746   INTERNAL_USERIMAGES_SPARSE_EXT_FLAG := -s
    747 endif
    748 
    749 ifeq ($(INTERNAL_USERIMAGES_USE_EXT),true)
    750 INTERNAL_USERIMAGES_DEPS := $(SIMG2IMG)
    751 INTERNAL_USERIMAGES_DEPS += $(MKEXTUSERIMG) $(MAKE_EXT4FS) $(E2FSCK)
    752 ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
    753 INTERNAL_USERIMAGES_DEPS += $(MKF2FSUSERIMG) $(MAKE_F2FS)
    754 endif
    755 endif
    756 
    757 ifneq (true,$(TARGET_USERIMAGES_SPARSE_SQUASHFS_DISABLED))
    758   INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG := -s
    759 endif
    760 ifneq ($(filter $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE) $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE),squashfs),)
    761 INTERNAL_USERIMAGES_DEPS += $(MAKE_SQUASHFS) $(MKSQUASHFSUSERIMG) $(IMG2SIMG)
    762 endif
    763 
    764 INTERNAL_USERIMAGES_BINARY_PATHS := $(sort $(dir $(INTERNAL_USERIMAGES_DEPS)))
    765 
    766 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY))
    767 INTERNAL_USERIMAGES_DEPS += $(BUILD_VERITY_TREE) $(APPEND2SIMG) $(VERITY_SIGNER)
    768 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC))
    769 INTERNAL_USERIMAGES_DEPS += $(FEC)
    770 endif
    771 endif
    772 
    773 SELINUX_FC := $(TARGET_ROOT_OUT)/file_contexts.bin
    774 INTERNAL_USERIMAGES_DEPS += $(SELINUX_FC)
    775 
    776 INTERNAL_USERIMAGES_DEPS += $(BLK_ALLOC_TO_BASE_FS)
    777 
    778 # $(1): the path of the output dictionary file
    779 # $(2): additional "key=value" pairs to append to the dictionary file.
    780 define generate-userimage-prop-dictionary
    781 $(if $(INTERNAL_USERIMAGES_EXT_VARIANT),$(hide) echo "fs_type=$(INTERNAL_USERIMAGES_EXT_VARIANT)" >> $(1))
    782 $(if $(BOARD_SYSTEMIMAGE_PARTITION_SIZE),$(hide) echo "system_size=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE)" >> $(1))
    783 $(if $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "system_fs_type=$(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    784 $(if $(BOARD_SYSTEMIMAGE_JOURNAL_SIZE),$(hide) echo "system_journal_size=$(BOARD_SYSTEMIMAGE_JOURNAL_SIZE)" >> $(1))
    785 $(if $(BOARD_HAS_EXT4_RESERVED_BLOCKS),$(hide) echo "has_ext4_reserved_blocks=$(BOARD_HAS_EXT4_RESERVED_BLOCKS)" >> $(1))
    786 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "system_squashfs_compressor=$(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
    787 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "system_squashfs_compressor_opt=$(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
    788 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "system_squashfs_disable_4k_align=$(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
    789 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH),$(hide) echo "system_base_fs_file=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH)" >> $(1))
    790 $(if $(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "userdata_fs_type=$(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    791 $(if $(BOARD_USERDATAIMAGE_PARTITION_SIZE),$(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(1))
    792 $(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    793 $(if $(BOARD_CACHEIMAGE_PARTITION_SIZE),$(hide) echo "cache_size=$(BOARD_CACHEIMAGE_PARTITION_SIZE)" >> $(1))
    794 $(if $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "vendor_fs_type=$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    795 $(if $(BOARD_VENDORIMAGE_PARTITION_SIZE),$(hide) echo "vendor_size=$(BOARD_VENDORIMAGE_PARTITION_SIZE)" >> $(1))
    796 $(if $(BOARD_VENDORIMAGE_JOURNAL_SIZE),$(hide) echo "vendor_journal_size=$(BOARD_VENDORIMAGE_JOURNAL_SIZE)" >> $(1))
    797 $(if $(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "vendor_squashfs_compressor=$(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
    798 $(if $(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "vendor_squashfs_compressor_opt=$(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
    799 $(if $(BOARD_VENDORIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "vendor_squashfs_disable_4k_align=$(BOARD_VENDORIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
    800 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH),$(hide) echo "vendor_base_fs_file=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH)" >> $(1))
    801 $(if $(BOARD_OEMIMAGE_PARTITION_SIZE),$(hide) echo "oem_size=$(BOARD_OEMIMAGE_PARTITION_SIZE)" >> $(1))
    802 $(if $(BOARD_OEMIMAGE_JOURNAL_SIZE),$(hide) echo "oem_journal_size=$(BOARD_OEMIMAGE_JOURNAL_SIZE)" >> $(1))
    803 $(if $(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG),$(hide) echo "extfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG)" >> $(1))
    804 $(if $(INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG),$(hide) echo "squashfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG)" >> $(1))
    805 $(hide) echo "selinux_fc=$(SELINUX_FC)" >> $(1)
    806 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER),$(hide) echo "boot_signer=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER)" >> $(1))
    807 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY)" >> $(1))
    808 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_key=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY)" >> $(1))
    809 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_signer_cmd=$(notdir $(VERITY_SIGNER))" >> $(1))
    810 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC),$(hide) echo "verity_fec=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC)" >> $(1))
    811 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION),$(hide) echo "system_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION)" >> $(1))
    812 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION),$(hide) echo "vendor_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION)" >> $(1))
    813 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)" >> $(1))
    814 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_key=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY)" >> $(1))
    815 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_subkey=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY)" >> $(1))
    816 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "futility=$(FUTILITY)" >> $(1))
    817 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_signer_cmd=$(VBOOT_SIGNER)" >> $(1))
    818 $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
    819     $(hide) echo "recovery_as_boot=true" >> $(1))
    820 $(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)),\
    821     $(hide) echo "system_root_image=true" >> $(1);\
    822     echo "ramdisk_dir=$(TARGET_ROOT_OUT)" >> $(1))
    823 $(if $(2),$(hide) $(foreach kv,$(2),echo "$(kv)" >> $(1);))
    824 endef
    825 
    826 # -----------------------------------------------------------------
    827 # Recovery image
    828 
    829 # Recovery image exists if we are building recovery, or building recovery as boot.
    830 ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)))
    831 
    832 INTERNAL_RECOVERYIMAGE_FILES := $(filter $(TARGET_RECOVERY_OUT)/%, \
    833     $(ALL_DEFAULT_INSTALLED_MODULES))
    834 
    835 recovery_initrc := $(call include-path-for, recovery)/etc/init.rc
    836 recovery_sepolicy := $(call intermediates-dir-for,ETC,sepolicy.recovery)/sepolicy.recovery
    837 recovery_kernel := $(INSTALLED_KERNEL_TARGET) # same as a non-recovery system
    838 recovery_ramdisk := $(PRODUCT_OUT)/ramdisk-recovery.img
    839 recovery_build_prop := $(intermediate_system_build_prop)
    840 recovery_resources_common := $(call include-path-for, recovery)/res
    841 
    842 # Set recovery_density to the density bucket of the device.
    843 recovery_density := unknown
    844 ifneq (,$(PRODUCT_AAPT_PREF_CONFIG))
    845 # If PRODUCT_AAPT_PREF_CONFIG includes a dpi bucket, then use that value.
    846 recovery_density := $(filter %dpi,$(PRODUCT_AAPT_PREF_CONFIG))
    847 else
    848 # Otherwise, use the default medium density.
    849 recovery_densities := mdpi
    850 endif
    851 
    852 ifneq (,$(wildcard $(recovery_resources_common)-$(recovery_density)))
    853 recovery_resources_common := $(recovery_resources_common)-$(recovery_density)
    854 else
    855 recovery_resources_common := $(recovery_resources_common)-xhdpi
    856 endif
    857 
    858 # Select the 18x32 font on high-density devices (xhdpi and up); and
    859 # the 12x22 font on other devices.  Note that the font selected here
    860 # can be overridden for a particular device by putting a font.png in
    861 # its private recovery resources.
    862 
    863 ifneq (,$(filter xxxhdpi 560dpi xxhdpi 400dpi xhdpi,$(recovery_density)))
    864 recovery_font := $(call include-path-for, recovery)/fonts/18x32.png
    865 else
    866 recovery_font := $(call include-path-for, recovery)/fonts/12x22.png
    867 endif
    868 
    869 ifndef TARGET_PRIVATE_RES_DIRS
    870 TARGET_PRIVATE_RES_DIRS := $(wildcard $(TARGET_DEVICE_DIR)/recovery/res)
    871 endif
    872 recovery_resource_deps := $(shell find $(recovery_resources_common) \
    873   $(TARGET_PRIVATE_RES_DIRS) -type f)
    874 ifdef TARGET_RECOVERY_FSTAB
    875 recovery_fstab := $(TARGET_RECOVERY_FSTAB)
    876 else
    877 recovery_fstab := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery.fstab))
    878 endif
    879 
    880 # Prior to A/B update, we used to have:
    881 #   boot.img + recovery-from-boot.p + recovery-resource.dat = recovery.img.
    882 # recovery-resource.dat is needed only if we carry a patch of the boot and
    883 # recovery images and invoke install-recovery.sh on the first boot post an
    884 # OTA update.
    885 #
    886 # We no longer need that if one of the following conditions holds:
    887 #   a) We carry a full copy of the recovery image
    888 #      (BOARD_USES_FULL_RECOVERY_IMAGE = true);
    889 #   b) We build a single image that contains boot and recovery both
    890 #      (BOARD_USES_RECOVERY_AS_BOOT = true).
    891 
    892 ifeq (,$(filter true, $(BOARD_USES_FULL_RECOVERY_IMAGE) $(BOARD_USES_RECOVERY_AS_BOOT)))
    893 # Named '.dat' so we don't attempt to use imgdiff for patching it.
    894 RECOVERY_RESOURCE_ZIP := $(TARGET_OUT)/etc/recovery-resource.dat
    895 else
    896 RECOVERY_RESOURCE_ZIP :=
    897 endif
    898 
    899 ifeq ($(TARGET_PRIVATE_RES_DIRS),)
    900   $(info No private recovery resources for TARGET_DEVICE $(TARGET_DEVICE))
    901 endif
    902 
    903 ifeq ($(recovery_fstab),)
    904   $(info No recovery.fstab for TARGET_DEVICE $(TARGET_DEVICE))
    905 endif
    906 
    907 INTERNAL_RECOVERYIMAGE_ARGS := \
    908 	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
    909 	--kernel $(recovery_kernel) \
    910 	--ramdisk $(recovery_ramdisk)
    911 
    912 # Assumes this has already been stripped
    913 ifdef BOARD_KERNEL_CMDLINE
    914   INTERNAL_RECOVERYIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)"
    915 endif
    916 ifdef BOARD_KERNEL_BASE
    917   INTERNAL_RECOVERYIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
    918 endif
    919 BOARD_KERNEL_PAGESIZE := $(strip $(BOARD_KERNEL_PAGESIZE))
    920 ifdef BOARD_KERNEL_PAGESIZE
    921   INTERNAL_RECOVERYIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
    922 endif
    923 
    924 # Keys authorized to sign OTA packages this build will accept.  The
    925 # build always uses dev-keys for this; release packaging tools will
    926 # substitute other keys for this one.
    927 OTA_PUBLIC_KEYS := $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem
    928 
    929 # Generate a file containing the keys that will be read by the
    930 # recovery binary.
    931 RECOVERY_INSTALL_OTA_KEYS := \
    932 	$(call intermediates-dir-for,PACKAGING,ota_keys)/keys
    933 DUMPKEY_JAR := $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar
    934 $(RECOVERY_INSTALL_OTA_KEYS): PRIVATE_OTA_PUBLIC_KEYS := $(OTA_PUBLIC_KEYS)
    935 $(RECOVERY_INSTALL_OTA_KEYS): extra_keys := $(patsubst %,%.x509.pem,$(PRODUCT_EXTRA_RECOVERY_KEYS))
    936 $(RECOVERY_INSTALL_OTA_KEYS): $(OTA_PUBLIC_KEYS) $(DUMPKEY_JAR) $(extra_keys)
    937 	@echo "DumpPublicKey: $@ <= $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys)"
    938 	@rm -rf $@
    939 	@mkdir -p $(dir $@)
    940 	java -jar $(DUMPKEY_JAR) $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys) > $@
    941 
    942 RECOVERYIMAGE_ID_FILE := $(PRODUCT_OUT)/recovery.id
    943 # $(1): output file
    944 define build-recoveryimage-target
    945   @echo ----- Making recovery image ------
    946   $(hide) mkdir -p $(TARGET_RECOVERY_OUT)
    947   $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/etc $(TARGET_RECOVERY_ROOT_OUT)/sdcard $(TARGET_RECOVERY_ROOT_OUT)/tmp
    948   @echo Copying baseline ramdisk...
    949   $(hide) rsync -a --exclude=etc --exclude=sdcard $(TARGET_ROOT_OUT) $(TARGET_RECOVERY_OUT) # "cp -Rf" fails to overwrite broken symlinks on Mac.
    950   @echo Modifying ramdisk contents...
    951   $(hide) rm -f $(TARGET_RECOVERY_ROOT_OUT)/init*.rc
    952   $(hide) cp -f $(recovery_initrc) $(TARGET_RECOVERY_ROOT_OUT)/
    953   $(hide) rm -f $(TARGET_RECOVERY_ROOT_OUT)/sepolicy
    954   $(hide) cp -f $(recovery_sepolicy) $(TARGET_RECOVERY_ROOT_OUT)/sepolicy
    955   $(hide) cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/ || true # Ignore error when the src file doesn't exist.
    956   $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/res
    957   $(hide) rm -rf $(TARGET_RECOVERY_ROOT_OUT)/res/*
    958   $(hide) cp -rf $(recovery_resources_common)/* $(TARGET_RECOVERY_ROOT_OUT)/res
    959   $(hide) cp -f $(recovery_font) $(TARGET_RECOVERY_ROOT_OUT)/res/images/font.png
    960   $(hide) $(foreach item,$(TARGET_PRIVATE_RES_DIRS), \
    961     cp -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/$(newline))
    962   $(hide) $(foreach item,$(recovery_fstab), \
    963     cp -f $(item) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.fstab)
    964   $(hide) cp $(RECOVERY_INSTALL_OTA_KEYS) $(TARGET_RECOVERY_ROOT_OUT)/res/keys
    965   $(hide) cat $(INSTALLED_DEFAULT_PROP_TARGET) $(recovery_build_prop) \
    966           > $(TARGET_RECOVERY_ROOT_OUT)/default.prop
    967   $(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)), \
    968     $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/system_root; \
    969             rm -rf $(TARGET_RECOVERY_ROOT_OUT)/system; \
    970             ln -sf /system_root/system $(TARGET_RECOVERY_ROOT_OUT)/system) # Mount the system_root_image to /system_root and symlink /system.
    971   $(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RECOVERY_ROOT_OUT) | $(MINIGZIP) > $(recovery_ramdisk)
    972   $(if $(filter true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)), \
    973     $(hide) $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1).unsigned, \
    974     $(hide) $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1) --id > $(RECOVERYIMAGE_ID_FILE))
    975   $(if $(filter true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER)),\
    976     $(BOOT_SIGNER) /recovery $(1) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1))
    977   $(if $(filter true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)), \
    978     $(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))
    979   $(if $(filter true,BOARD_USES_RECOVERY_AS_BOOT), \
    980     $(hide) $(call assert-max-image-size,$(1),$(BOARD_BOOTIMAGE_PARTITION_SIZE)), \
    981     $(hide) $(call assert-max-image-size,$(1),$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)))
    982   @echo ----- Made recovery image: $(1) --------
    983 endef
    984 
    985 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
    986 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER))
    987 $(INSTALLED_BOOTIMAGE_TARGET) : $(BOOT_SIGNER)
    988 endif
    989 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT))
    990 $(INSTALLED_BOOTIMAGE_TARGET) : $(VBOOT_SIGNER)
    991 endif
    992 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
    993 		$(INSTALLED_RAMDISK_TARGET) \
    994 		$(INTERNAL_RECOVERYIMAGE_FILES) \
    995 		$(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
    996 		$(INSTALLED_2NDBOOTLOADER_TARGET) \
    997 		$(recovery_build_prop) $(recovery_resource_deps) \
    998 		$(recovery_fstab) \
    999 		$(RECOVERY_INSTALL_OTA_KEYS)
   1000 		$(call pretty,"Target boot image from recovery: $@")
   1001 		$(call build-recoveryimage-target, $@)
   1002 endif
   1003 
   1004 $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
   1005 		$(INSTALLED_RAMDISK_TARGET) \
   1006 		$(INSTALLED_BOOTIMAGE_TARGET) \
   1007 		$(INTERNAL_RECOVERYIMAGE_FILES) \
   1008 		$(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
   1009 		$(INSTALLED_2NDBOOTLOADER_TARGET) \
   1010 		$(recovery_build_prop) $(recovery_resource_deps) \
   1011 		$(recovery_fstab) \
   1012 		$(RECOVERY_INSTALL_OTA_KEYS)
   1013 		$(call build-recoveryimage-target, $@)
   1014 
   1015 ifdef RECOVERY_RESOURCE_ZIP
   1016 $(RECOVERY_RESOURCE_ZIP): $(INSTALLED_RECOVERYIMAGE_TARGET) | $(ZIPTIME)
   1017 	$(hide) mkdir -p $(dir $@)
   1018 	$(hide) find $(TARGET_RECOVERY_ROOT_OUT)/res -type f | sort | zip -0qrjX $@ -@
   1019 	$(remove-timestamps-from-package)
   1020 endif
   1021 
   1022 .PHONY: recoveryimage-nodeps
   1023 recoveryimage-nodeps:
   1024 	@echo "make $@: ignoring dependencies"
   1025 	$(call build-recoveryimage-target, $(INSTALLED_RECOVERYIMAGE_TARGET))
   1026 
   1027 else # INSTALLED_RECOVERYIMAGE_TARGET not defined
   1028 RECOVERY_RESOURCE_ZIP :=
   1029 endif
   1030 
   1031 .PHONY: recoveryimage
   1032 recoveryimage: $(INSTALLED_RECOVERYIMAGE_TARGET) $(RECOVERY_RESOURCE_ZIP)
   1033 
   1034 ifeq ($(BOARD_NAND_PAGE_SIZE),)
   1035 BOARD_NAND_PAGE_SIZE := 2048
   1036 endif
   1037 
   1038 ifeq ($(BOARD_NAND_SPARE_SIZE),)
   1039 BOARD_NAND_SPARE_SIZE := 64
   1040 endif
   1041 
   1042 # -----------------------------------------------------------------
   1043 # system image
   1044 #
   1045 # Remove overridden packages from $(ALL_PDK_FUSION_FILES)
   1046 PDK_FUSION_SYSIMG_FILES := \
   1047     $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
   1048         $(ALL_PDK_FUSION_FILES))
   1049 
   1050 INTERNAL_SYSTEMIMAGE_FILES := $(filter $(TARGET_OUT)/%, \
   1051     $(ALL_PREBUILT) \
   1052     $(ALL_GENERATED_SOURCES) \
   1053     $(ALL_DEFAULT_INSTALLED_MODULES) \
   1054     $(PDK_FUSION_SYSIMG_FILES) \
   1055     $(RECOVERY_RESOURCE_ZIP))
   1056 
   1057 
   1058 FULL_SYSTEMIMAGE_DEPS := $(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_USERIMAGES_DEPS)
   1059 # -----------------------------------------------------------------
   1060 # installed file list
   1061 # Depending on anything that $(BUILT_SYSTEMIMAGE) depends on.
   1062 # We put installed-files.txt ahead of image itself in the dependency graph
   1063 # so that we can get the size stat even if the build fails due to too large
   1064 # system image.
   1065 INSTALLED_FILES_FILE := $(PRODUCT_OUT)/installed-files.txt
   1066 $(INSTALLED_FILES_FILE): $(FULL_SYSTEMIMAGE_DEPS)
   1067 	@echo Installed file list: $@
   1068 	@mkdir -p $(dir $@)
   1069 	@rm -f $@
   1070 	$(hide) build/tools/fileslist.py $(TARGET_OUT) > $@
   1071 
   1072 .PHONY: installed-file-list
   1073 installed-file-list: $(INSTALLED_FILES_FILE)
   1074 
   1075 $(call dist-for-goals, sdk win_sdk sdk_addon, $(INSTALLED_FILES_FILE))
   1076 
   1077 systemimage_intermediates := \
   1078     $(call intermediates-dir-for,PACKAGING,systemimage)
   1079 BUILT_SYSTEMIMAGE := $(systemimage_intermediates)/system.img
   1080 
   1081 # Create symlink /system/vendor to /vendor if necessary.
   1082 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1083 define create-system-vendor-symlink
   1084 $(hide) if [ -d $(TARGET_OUT)/vendor ] && [ ! -h $(TARGET_OUT)/vendor ]; then \
   1085   echo 'Non-symlink $(TARGET_OUT)/vendor detected!' 1>&2; \
   1086   echo 'You cannot install files to $(TARGET_OUT)/vendor while building a separate vendor.img!' 1>&2; \
   1087   exit 1; \
   1088 fi
   1089 $(hide) ln -sf /vendor $(TARGET_OUT)/vendor
   1090 endef
   1091 else
   1092 define create-system-vendor-symlink
   1093 endef
   1094 endif
   1095 
   1096 # $(1): output file
   1097 define build-systemimage-target
   1098   @echo "Target system fs image: $(1)"
   1099   $(call create-system-vendor-symlink)
   1100   @mkdir -p $(dir $(1)) $(systemimage_intermediates) && rm -rf $(systemimage_intermediates)/system_image_info.txt
   1101   $(call generate-userimage-prop-dictionary, $(systemimage_intermediates)/system_image_info.txt, \
   1102       skip_fsck=true)
   1103   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1104       ./build/tools/releasetools/build_image.py \
   1105       $(TARGET_OUT) $(systemimage_intermediates)/system_image_info.txt $(1) $(TARGET_OUT) \
   1106       || ( echo "Out of space? the tree size of $(TARGET_OUT) is (MB): " 1>&2 ;\
   1107            du -sm $(TARGET_OUT) 1>&2;\
   1108            if [ "$(INTERNAL_USERIMAGES_EXT_VARIANT)" == "ext4" ]; then \
   1109                maxsize=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE); \
   1110                if [ "$(BOARD_HAS_EXT4_RESERVED_BLOCKS)" == "true" ]; then \
   1111                    maxsize=$$((maxsize - 4096 * 4096)); \
   1112                fi; \
   1113                echo "The max is $$(( maxsize / 1048576 )) MB." 1>&2 ;\
   1114            else \
   1115                echo "The max is $$(( $(BOARD_SYSTEMIMAGE_PARTITION_SIZE) / 1048576 )) MB." 1>&2 ;\
   1116            fi; \
   1117            mkdir -p $(DIST_DIR); cp $(INSTALLED_FILES_FILE) $(DIST_DIR)/installed-files-rescued.txt; \
   1118            exit 1 )
   1119 endef
   1120 
   1121 $(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE)
   1122 	$(call build-systemimage-target,$@)
   1123 
   1124 INSTALLED_SYSTEMIMAGE := $(PRODUCT_OUT)/system.img
   1125 SYSTEMIMAGE_SOURCE_DIR := $(TARGET_OUT)
   1126 
   1127 # The system partition needs room for the recovery image as well.  We
   1128 # now store the recovery image as a binary patch using the boot image
   1129 # as the source (since they are very similar).  Generate the patch so
   1130 # we can see how big it's going to be, and include that in the system
   1131 # image size check calculation.
   1132 ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   1133 ifneq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
   1134 intermediates := $(call intermediates-dir-for,PACKAGING,recovery_patch)
   1135 RECOVERY_FROM_BOOT_PATCH := $(intermediates)/recovery_from_boot.p
   1136 $(RECOVERY_FROM_BOOT_PATCH): $(INSTALLED_RECOVERYIMAGE_TARGET) \
   1137                              $(INSTALLED_BOOTIMAGE_TARGET) \
   1138 			     $(HOST_OUT_EXECUTABLES)/imgdiff \
   1139 	                     $(HOST_OUT_EXECUTABLES)/bsdiff
   1140 	@echo "Construct recovery from boot"
   1141 	mkdir -p $(dir $@)
   1142 	PATH=$(HOST_OUT_EXECUTABLES):$$PATH $(HOST_OUT_EXECUTABLES)/imgdiff $(INSTALLED_BOOTIMAGE_TARGET) $(INSTALLED_RECOVERYIMAGE_TARGET) $@
   1143 else # $(BOARD_USES_FULL_RECOVERY_IMAGE) == true
   1144 RECOVERY_FROM_BOOT_PATCH := $(INSTALLED_RECOVERYIMAGE_TARGET)
   1145 endif
   1146 endif
   1147 
   1148 
   1149 $(INSTALLED_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE) $(RECOVERY_FROM_BOOT_PATCH) | $(ACP)
   1150 	@echo "Install system fs image: $@"
   1151 	$(copy-file-to-target)
   1152 	$(hide) $(call assert-max-image-size,$@ $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
   1153 
   1154 systemimage: $(INSTALLED_SYSTEMIMAGE)
   1155 
   1156 .PHONY: systemimage-nodeps snod
   1157 systemimage-nodeps snod: $(filter-out systemimage-nodeps snod,$(MAKECMDGOALS)) \
   1158 	            | $(INTERNAL_USERIMAGES_DEPS)
   1159 	@echo "make $@: ignoring dependencies"
   1160 	$(call build-systemimage-target,$(INSTALLED_SYSTEMIMAGE))
   1161 	$(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMIMAGE),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
   1162 
   1163 ifneq (,$(filter systemimage-nodeps snod, $(MAKECMDGOALS)))
   1164 ifeq (true,$(WITH_DEXPREOPT))
   1165 $(warning Warning: with dexpreopt enabled, you may need a full rebuild.)
   1166 endif
   1167 endif
   1168 
   1169 #######
   1170 ## system tarball
   1171 define build-systemtarball-target
   1172   $(call pretty,"Target system fs tarball: $(INSTALLED_SYSTEMTARBALL_TARGET)")
   1173   $(call create-system-vendor-symlink)
   1174   $(MKTARBALL) $(FS_GET_STATS) \
   1175     $(PRODUCT_OUT) system $(PRIVATE_SYSTEM_TAR) \
   1176     $(INSTALLED_SYSTEMTARBALL_TARGET) $(TARGET_OUT)
   1177 endef
   1178 
   1179 ifndef SYSTEM_TARBALL_FORMAT
   1180     SYSTEM_TARBALL_FORMAT := bz2
   1181 endif
   1182 
   1183 system_tar := $(PRODUCT_OUT)/system.tar
   1184 INSTALLED_SYSTEMTARBALL_TARGET := $(system_tar).$(SYSTEM_TARBALL_FORMAT)
   1185 $(INSTALLED_SYSTEMTARBALL_TARGET): PRIVATE_SYSTEM_TAR := $(system_tar)
   1186 $(INSTALLED_SYSTEMTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_SYSTEMIMAGE_FILES)
   1187 	$(build-systemtarball-target)
   1188 
   1189 .PHONY: systemtarball-nodeps
   1190 systemtarball-nodeps: $(FS_GET_STATS) \
   1191                       $(filter-out systemtarball-nodeps stnod,$(MAKECMDGOALS))
   1192 	$(build-systemtarball-target)
   1193 
   1194 .PHONY: stnod
   1195 stnod: systemtarball-nodeps
   1196 
   1197 # -----------------------------------------------------------------
   1198 ## platform.zip: system, plus other files to be used in PDK fusion build,
   1199 ## in a zip file
   1200 ##
   1201 ## PDK_PLATFORM_ZIP_PRODUCT_BINARIES is used to store specified files to platform.zip.
   1202 ## The variable will be typically set from BoardConfig.mk.
   1203 ## Files under out dir will be rejected to prevent possible conflicts with other rules.
   1204 pdk_odex_javalibs := $(strip $(foreach m,$(DEXPREOPT.MODULES.JAVA_LIBRARIES),\
   1205   $(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m))))
   1206 pdk_odex_apps := $(strip $(foreach m,$(DEXPREOPT.MODULES.APPS),\
   1207   $(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m))))
   1208 pdk_classes_dex := $(strip \
   1209   $(foreach m,$(pdk_odex_javalibs),$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar) \
   1210   $(foreach m,$(pdk_odex_apps),$(call intermediates-dir-for,APPS,$(m))/package.dex.apk))
   1211 
   1212 pdk_odex_config_mk := $(PRODUCT_OUT)/pdk_dexpreopt_config.mk
   1213 $(pdk_odex_config_mk): PRIVATE_JAVA_LIBRARIES := $(pdk_odex_javalibs)
   1214 $(pdk_odex_config_mk): PRIVATE_APPS := $(pdk_odex_apps)
   1215 $(pdk_odex_config_mk) :
   1216 	@echo "PDK odex config makefile: $@"
   1217 	$(hide) mkdir -p $(dir $@)
   1218 	$(hide) echo "# Auto-generated. Do not modify." > $@
   1219 	$(hide) echo "PDK.DEXPREOPT.JAVA_LIBRARIES:=$(PRIVATE_JAVA_LIBRARIES)" >> $@
   1220 	$(hide) echo "PDK.DEXPREOPT.APPS:=$(PRIVATE_APPS)" >> $@
   1221 	$(foreach m,$(PRIVATE_JAVA_LIBRARIES),\
   1222 	  $(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar)" >> $@$(newline)\
   1223 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\
   1224 	  $(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\
   1225 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\
   1226 	  )
   1227 	$(foreach m,$(PRIVATE_APPS),\
   1228 	  $(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,APPS,$(m))/package.dex.apk)" >> $@$(newline)\
   1229 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\
   1230 	  $(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\
   1231 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\
   1232 	  $(hide) echo "PDK.DEXPREOPT.$(m).PRIVILEGED_MODULE:=$(DEXPREOPT.$(m).PRIVILEGED_MODULE)" >> $@$(newline)\
   1233 	  $(hide) echo "PDK.DEXPREOPT.$(m).PROPRIETARY_MODULE:=$(DEXPREOPT.$(m).PROPRIETARY_MODULE)" >> $@$(newline)\
   1234 	  $(hide) echo "PDK.DEXPREOPT.$(m).TARGET_ARCH:=$(DEXPREOPT.$(m).TARGET_ARCH)" >> $@$(newline)\
   1235 	  $(hide) echo "PDK.DEXPREOPT.$(m).STRIPPED_SRC:=$(patsubst $(PRODUCT_OUT)/%,%,$(DEXPREOPT.$(m).INSTALLED_STRIPPED))" >> $@$(newline)\
   1236 	  )
   1237 
   1238 PDK_PLATFORM_ZIP_PRODUCT_BINARIES := $(filter-out $(OUT_DIR)/%,$(PDK_PLATFORM_ZIP_PRODUCT_BINARIES))
   1239 INSTALLED_PLATFORM_ZIP := $(PRODUCT_OUT)/platform.zip
   1240 
   1241 $(INSTALLED_PLATFORM_ZIP): PRIVATE_DEX_FILES := $(pdk_classes_dex)
   1242 $(INSTALLED_PLATFORM_ZIP): PRIVATE_ODEX_CONFIG := $(pdk_odex_config_mk)
   1243 $(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES) $(pdk_odex_config_mk)
   1244 	$(call pretty,"Platform zip package: $(INSTALLED_PLATFORM_ZIP)")
   1245 	$(hide) rm -f $@
   1246 	$(hide) cd $(dir $@) && zip -qryX $(notdir $@) \
   1247 		$(TARGET_COPY_OUT_SYSTEM) \
   1248 		$(patsubst $(PRODUCT_OUT)/%, %, $(TARGET_OUT_NOTICE_FILES)) \
   1249 		$(addprefix symbols/,$(PDK_SYMBOL_FILES_LIST))
   1250 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1251 	$(hide) cd $(dir $@) && zip -qryX $(notdir $@) \
   1252 		$(TARGET_COPY_OUT_VENDOR)
   1253 endif
   1254 ifneq ($(PDK_PLATFORM_JAVA_ZIP_CONTENTS),)
   1255 	$(hide) cd $(OUT_DIR) && zip -qryX $(patsubst $(OUT_DIR)/%,%,$@) $(PDK_PLATFORM_JAVA_ZIP_CONTENTS)
   1256 endif
   1257 ifneq ($(PDK_PLATFORM_ZIP_PRODUCT_BINARIES),)
   1258 	$(hide) zip -qryX $@ $(PDK_PLATFORM_ZIP_PRODUCT_BINARIES)
   1259 endif
   1260 	@# Add dex-preopt files and config.
   1261 	$(if $(PRIVATE_DEX_FILES),$(hide) cd $(OUT_DIR) && zip -qryX $(patsubst $(OUT_DIR)/%,%,$@ $(PRIVATE_DEX_FILES)))
   1262 	$(hide) zip -qryXj $@ $(PRIVATE_ODEX_CONFIG)
   1263 
   1264 .PHONY: platform
   1265 platform: $(INSTALLED_PLATFORM_ZIP)
   1266 
   1267 .PHONY: platform-java
   1268 platform-java: platform
   1269 
   1270 # Dist the platform.zip
   1271 ifneq (,$(filter platform platform-java, $(MAKECMDGOALS)))
   1272 $(call dist-for-goals, platform platform-java, $(INSTALLED_PLATFORM_ZIP))
   1273 endif
   1274 
   1275 # -----------------------------------------------------------------
   1276 ## boot tarball
   1277 define build-boottarball-target
   1278     $(hide) echo "Target boot fs tarball: $(INSTALLED_BOOTTARBALL_TARGET)"
   1279     $(hide) mkdir -p $(PRODUCT_OUT)/boot
   1280     $(hide) cp -f $(INTERNAL_BOOTIMAGE_FILES) $(PRODUCT_OUT)/boot/.
   1281     $(hide) echo $(BOARD_KERNEL_CMDLINE) > $(PRODUCT_OUT)/boot/cmdline
   1282     $(hide) $(MKTARBALL) $(FS_GET_STATS) \
   1283                  $(PRODUCT_OUT) boot $(PRIVATE_BOOT_TAR) \
   1284                  $(INSTALLED_BOOTTARBALL_TARGET) $(TARGET_OUT)
   1285 endef
   1286 
   1287 ifndef BOOT_TARBALL_FORMAT
   1288     BOOT_TARBALL_FORMAT := bz2
   1289 endif
   1290 
   1291 boot_tar := $(PRODUCT_OUT)/boot.tar
   1292 INSTALLED_BOOTTARBALL_TARGET := $(boot_tar).$(BOOT_TARBALL_FORMAT)
   1293 $(INSTALLED_BOOTTARBALL_TARGET): PRIVATE_BOOT_TAR := $(boot_tar)
   1294 $(INSTALLED_BOOTTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_BOOTIMAGE_FILES)
   1295 	$(build-boottarball-target)
   1296 
   1297 .PHONY: boottarball-nodeps btnod
   1298 boottarball-nodeps btnod: $(FS_GET_STATS) \
   1299                       $(filter-out boottarball-nodeps btnod,$(MAKECMDGOALS))
   1300 	$(build-boottarball-target)
   1301 
   1302 
   1303 # -----------------------------------------------------------------
   1304 # data partition image
   1305 INTERNAL_USERDATAIMAGE_FILES := \
   1306     $(filter $(TARGET_OUT_DATA)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
   1307 
   1308 # Don't build userdata.img if it's extfs but no partition size
   1309 skip_userdata.img :=
   1310 ifdef INTERNAL_USERIMAGES_EXT_VARIANT
   1311 ifndef BOARD_USERDATAIMAGE_PARTITION_SIZE
   1312 skip_userdata.img := true
   1313 endif
   1314 endif
   1315 
   1316 ifneq ($(skip_userdata.img),true)
   1317 userdataimage_intermediates := \
   1318     $(call intermediates-dir-for,PACKAGING,userdata)
   1319 BUILT_USERDATAIMAGE_TARGET := $(PRODUCT_OUT)/userdata.img
   1320 
   1321 define build-userdataimage-target
   1322   $(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
   1323   @mkdir -p $(TARGET_OUT_DATA)
   1324   @mkdir -p $(userdataimage_intermediates) && rm -rf $(userdataimage_intermediates)/userdata_image_info.txt
   1325   $(call generate-userimage-prop-dictionary, $(userdataimage_intermediates)/userdata_image_info.txt, skip_fsck=true)
   1326   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1327       ./build/tools/releasetools/build_image.py \
   1328       $(TARGET_OUT_DATA) $(userdataimage_intermediates)/userdata_image_info.txt $(INSTALLED_USERDATAIMAGE_TARGET) $(TARGET_OUT)
   1329   $(hide) $(call assert-max-image-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_PARTITION_SIZE))
   1330 endef
   1331 
   1332 # We just build this directly to the install location.
   1333 INSTALLED_USERDATAIMAGE_TARGET := $(BUILT_USERDATAIMAGE_TARGET)
   1334 $(INSTALLED_USERDATAIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) \
   1335                                    $(INTERNAL_USERDATAIMAGE_FILES)
   1336 	$(build-userdataimage-target)
   1337 
   1338 .PHONY: userdataimage-nodeps
   1339 userdataimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1340 	$(build-userdataimage-target)
   1341 
   1342 endif # not skip_userdata.img
   1343 skip_userdata.img :=
   1344 
   1345 #######
   1346 ## data partition tarball
   1347 define build-userdatatarball-target
   1348     $(call pretty,"Target userdata fs tarball: " \
   1349                   "$(INSTALLED_USERDATATARBALL_TARGET)")
   1350     $(MKTARBALL) $(FS_GET_STATS) \
   1351 		$(PRODUCT_OUT) data $(PRIVATE_USERDATA_TAR) \
   1352 		$(INSTALLED_USERDATATARBALL_TARGET) $(TARGET_OUT)
   1353 endef
   1354 
   1355 userdata_tar := $(PRODUCT_OUT)/userdata.tar
   1356 INSTALLED_USERDATATARBALL_TARGET := $(userdata_tar).bz2
   1357 $(INSTALLED_USERDATATARBALL_TARGET): PRIVATE_USERDATA_TAR := $(userdata_tar)
   1358 $(INSTALLED_USERDATATARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_USERDATAIMAGE_FILES)
   1359 	$(build-userdatatarball-target)
   1360 
   1361 .PHONY: userdatatarball-nodeps
   1362 userdatatarball-nodeps: $(FS_GET_STATS)
   1363 	$(build-userdatatarball-target)
   1364 
   1365 
   1366 # -----------------------------------------------------------------
   1367 # cache partition image
   1368 ifdef BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
   1369 INTERNAL_CACHEIMAGE_FILES := \
   1370     $(filter $(TARGET_OUT_CACHE)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
   1371 
   1372 cacheimage_intermediates := \
   1373     $(call intermediates-dir-for,PACKAGING,cache)
   1374 BUILT_CACHEIMAGE_TARGET := $(PRODUCT_OUT)/cache.img
   1375 
   1376 define build-cacheimage-target
   1377   $(call pretty,"Target cache fs image: $(INSTALLED_CACHEIMAGE_TARGET)")
   1378   @mkdir -p $(TARGET_OUT_CACHE)
   1379   @mkdir -p $(cacheimage_intermediates) && rm -rf $(cacheimage_intermediates)/cache_image_info.txt
   1380   $(call generate-userimage-prop-dictionary, $(cacheimage_intermediates)/cache_image_info.txt, skip_fsck=true)
   1381   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1382       ./build/tools/releasetools/build_image.py \
   1383       $(TARGET_OUT_CACHE) $(cacheimage_intermediates)/cache_image_info.txt $(INSTALLED_CACHEIMAGE_TARGET) $(TARGET_OUT)
   1384   $(hide) $(call assert-max-image-size,$(INSTALLED_CACHEIMAGE_TARGET),$(BOARD_CACHEIMAGE_PARTITION_SIZE))
   1385 endef
   1386 
   1387 # We just build this directly to the install location.
   1388 INSTALLED_CACHEIMAGE_TARGET := $(BUILT_CACHEIMAGE_TARGET)
   1389 $(INSTALLED_CACHEIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_CACHEIMAGE_FILES)
   1390 	$(build-cacheimage-target)
   1391 
   1392 .PHONY: cacheimage-nodeps
   1393 cacheimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1394 	$(build-cacheimage-target)
   1395 
   1396 endif # BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
   1397 
   1398 
   1399 # -----------------------------------------------------------------
   1400 # vendor partition image
   1401 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1402 INTERNAL_VENDORIMAGE_FILES := \
   1403     $(filter $(TARGET_OUT_VENDOR)/%,\
   1404       $(ALL_DEFAULT_INSTALLED_MODULES)\
   1405       $(ALL_PDK_FUSION_FILES))
   1406 
   1407 # platform.zip depends on $(INTERNAL_VENDORIMAGE_FILES).
   1408 $(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_VENDORIMAGE_FILES)
   1409 
   1410 INSTALLED_FILES_FILE_VENDOR := $(PRODUCT_OUT)/installed-files-vendor.txt
   1411 $(INSTALLED_FILES_FILE_VENDOR) : $(INTERNAL_VENDORIMAGE_FILES)
   1412 	@echo Installed file list: $@
   1413 	@mkdir -p $(dir $@)
   1414 	@rm -f $@
   1415 	$(hide) build/tools/fileslist.py $(TARGET_OUT_VENDOR) > $@
   1416 
   1417 vendorimage_intermediates := \
   1418     $(call intermediates-dir-for,PACKAGING,vendor)
   1419 BUILT_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
   1420 
   1421 define build-vendorimage-target
   1422   $(call pretty,"Target vendor fs image: $(INSTALLED_VENDORIMAGE_TARGET)")
   1423   @mkdir -p $(TARGET_OUT_VENDOR)
   1424   @mkdir -p $(vendorimage_intermediates) && rm -rf $(vendorimage_intermediates)/vendor_image_info.txt
   1425   $(call generate-userimage-prop-dictionary, $(vendorimage_intermediates)/vendor_image_info.txt, skip_fsck=true)
   1426   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1427       ./build/tools/releasetools/build_image.py \
   1428       $(TARGET_OUT_VENDOR) $(vendorimage_intermediates)/vendor_image_info.txt $(INSTALLED_VENDORIMAGE_TARGET) $(TARGET_OUT)
   1429   $(hide) $(call assert-max-image-size,$(INSTALLED_VENDORIMAGE_TARGET),$(BOARD_VENDORIMAGE_PARTITION_SIZE))
   1430 endef
   1431 
   1432 # We just build this directly to the install location.
   1433 INSTALLED_VENDORIMAGE_TARGET := $(BUILT_VENDORIMAGE_TARGET)
   1434 $(INSTALLED_VENDORIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_VENDORIMAGE_FILES) $(INSTALLED_FILES_FILE_VENDOR)
   1435 	$(build-vendorimage-target)
   1436 
   1437 .PHONY: vendorimage-nodeps
   1438 vendorimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1439 	$(build-vendorimage-target)
   1440 
   1441 endif # BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1442 
   1443 # -----------------------------------------------------------------
   1444 # bring in the installer image generation defines if necessary
   1445 ifeq ($(TARGET_USE_DISKINSTALLER),true)
   1446 include bootable/diskinstaller/config.mk
   1447 endif
   1448 
   1449 # -----------------------------------------------------------------
   1450 # host tools needed to build dist and OTA packages
   1451 
   1452 build_ota_package := true
   1453 ifeq ($(TARGET_SKIP_OTA_PACKAGE),true)
   1454 build_ota_package := false
   1455 endif
   1456 ifeq ($(BUILD_OS),darwin)
   1457 build_ota_package := false
   1458 endif
   1459 ifneq ($(strip $(SANITIZE_TARGET)),)
   1460 build_ota_package := false
   1461 endif
   1462 ifeq ($(TARGET_PRODUCT),sdk)
   1463 build_ota_package := false
   1464 endif
   1465 ifneq ($(filter generic%,$(TARGET_DEVICE)),)
   1466 build_ota_package := false
   1467 endif
   1468 ifeq ($(TARGET_NO_KERNEL),true)
   1469 build_ota_package := false
   1470 endif
   1471 ifeq ($(recovery_fstab),)
   1472 build_ota_package := false
   1473 endif
   1474 ifeq ($(TARGET_BUILD_PDK),true)
   1475 build_ota_package := false
   1476 endif
   1477 
   1478 ifeq ($(build_ota_package),true)
   1479 OTATOOLS :=  $(HOST_OUT_EXECUTABLES)/minigzip \
   1480   $(HOST_OUT_EXECUTABLES)/aapt \
   1481   $(HOST_OUT_EXECUTABLES)/mkbootfs \
   1482   $(HOST_OUT_EXECUTABLES)/mkbootimg \
   1483   $(HOST_OUT_EXECUTABLES)/fs_config \
   1484   $(HOST_OUT_EXECUTABLES)/zipalign \
   1485   $(HOST_OUT_EXECUTABLES)/bsdiff \
   1486   $(HOST_OUT_EXECUTABLES)/imgdiff \
   1487   $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar \
   1488   $(HOST_OUT_JAVA_LIBRARIES)/signapk.jar \
   1489   $(HOST_OUT_JAVA_LIBRARIES)/BootSignature.jar \
   1490   $(HOST_OUT_EXECUTABLES)/mkuserimg.sh \
   1491   $(HOST_OUT_EXECUTABLES)/make_ext4fs \
   1492   $(HOST_OUT_EXECUTABLES)/mksquashfsimage.sh \
   1493   $(HOST_OUT_EXECUTABLES)/mksquashfs \
   1494   $(HOST_OUT_EXECUTABLES)/mkf2fsuserimg.sh \
   1495   $(HOST_OUT_EXECUTABLES)/make_f2fs \
   1496   $(HOST_OUT_EXECUTABLES)/simg2img \
   1497   $(HOST_OUT_EXECUTABLES)/e2fsck \
   1498   $(HOST_OUT_EXECUTABLES)/build_verity_tree \
   1499   $(HOST_OUT_EXECUTABLES)/verity_signer \
   1500   $(HOST_OUT_EXECUTABLES)/append2simg \
   1501   $(HOST_OUT_EXECUTABLES)/img2simg \
   1502   $(HOST_OUT_EXECUTABLES)/boot_signer \
   1503   $(HOST_OUT_EXECUTABLES)/fec \
   1504   $(HOST_OUT_EXECUTABLES)/brillo_update_payload \
   1505   $(HOST_OUT_EXECUTABLES)/lib/shflags/shflags \
   1506   $(HOST_OUT_EXECUTABLES)/delta_generator \
   1507   $(BLK_ALLOC_TO_BASE_FS)
   1508 
   1509 # Shared libraries.
   1510 OTATOOLS += \
   1511   $(HOST_LIBRARY_PATH)/libc++$(HOST_SHLIB_SUFFIX) \
   1512   $(HOST_LIBRARY_PATH)/liblog$(HOST_SHLIB_SUFFIX) \
   1513   $(HOST_LIBRARY_PATH)/libcutils$(HOST_SHLIB_SUFFIX) \
   1514   $(HOST_LIBRARY_PATH)/libselinux$(HOST_SHLIB_SUFFIX) \
   1515   $(HOST_LIBRARY_PATH)/libcrypto-host$(HOST_SHLIB_SUFFIX) \
   1516   $(HOST_LIBRARY_PATH)/libdivsufsort$(HOST_SHLIB_SUFFIX) \
   1517   $(HOST_LIBRARY_PATH)/libdivsufsort64$(HOST_SHLIB_SUFFIX) \
   1518   $(HOST_LIBRARY_PATH)/libext2fs-host$(HOST_SHLIB_SUFFIX) \
   1519   $(HOST_LIBRARY_PATH)/libext2_blkid-host$(HOST_SHLIB_SUFFIX) \
   1520   $(HOST_LIBRARY_PATH)/libext2_com_err-host$(HOST_SHLIB_SUFFIX) \
   1521   $(HOST_LIBRARY_PATH)/libext2_e2p-host$(HOST_SHLIB_SUFFIX) \
   1522   $(HOST_LIBRARY_PATH)/libext2_profile-host$(HOST_SHLIB_SUFFIX) \
   1523   $(HOST_LIBRARY_PATH)/libext2_quota-host$(HOST_SHLIB_SUFFIX) \
   1524   $(HOST_LIBRARY_PATH)/libext2_uuid-host$(HOST_SHLIB_SUFFIX) \
   1525   $(HOST_LIBRARY_PATH)/libconscrypt_openjdk_jni$(HOST_SHLIB_SUFFIX) \
   1526   $(HOST_LIBRARY_PATH)/libbrillo$(HOST_SHLIB_SUFFIX) \
   1527   $(HOST_LIBRARY_PATH)/libbrillo-stream$(HOST_SHLIB_SUFFIX) \
   1528   $(HOST_LIBRARY_PATH)/libbrillo-http$(HOST_SHLIB_SUFFIX) \
   1529   $(HOST_LIBRARY_PATH)/libchrome$(HOST_SHLIB_SUFFIX) \
   1530   $(HOST_LIBRARY_PATH)/libcurl-host$(HOST_SHLIB_SUFFIX) \
   1531   $(HOST_LIBRARY_PATH)/libevent-host$(HOST_SHLIB_SUFFIX) \
   1532   $(HOST_LIBRARY_PATH)/libprotobuf-cpp-lite$(HOST_SHLIB_SUFFIX) \
   1533   $(HOST_LIBRARY_PATH)/libssl-host$(HOST_SHLIB_SUFFIX) \
   1534   $(HOST_LIBRARY_PATH)/libz-host$(HOST_SHLIB_SUFFIX) \
   1535   $(HOST_LIBRARY_PATH)/libbase$(HOST_SHLIB_SUFFIX)
   1536 
   1537 .PHONY: otatools
   1538 otatools: $(OTATOOLS)
   1539 
   1540 BUILT_OTATOOLS_PACKAGE := $(PRODUCT_OUT)/otatools.zip
   1541 $(BUILT_OTATOOLS_PACKAGE): zip_root := $(call intermediates-dir-for,PACKAGING,otatools)/otatools
   1542 
   1543 $(BUILT_OTATOOLS_PACKAGE): $(OTATOOLS) | $(ACP)
   1544 	@echo "Package OTA tools: $@"
   1545 	$(hide) rm -rf $@ $(zip_root)
   1546 	$(hide) mkdir -p $(dir $@) $(zip_root)/bin $(zip_root)/framework $(zip_root)/releasetools $(zip_root)/system/extras/verity
   1547 	$(call copy-files-with-structure,$(OTATOOLS),$(HOST_OUT)/,$(zip_root))
   1548 	$(hide) $(ACP) $(HOST_OUT_JAVA_LIBRARIES)/VeritySigner.jar $(zip_root)/framework/
   1549 	$(hide) $(ACP) -p system/extras/verity/build_verity_metadata.py $(zip_root)/system/extras/verity/
   1550 	$(hide) $(ACP) -r -d -p build/tools/releasetools/* $(zip_root)/releasetools
   1551 	$(hide) rm -rf $@ $(zip_root)/releasetools/*.pyc
   1552 	$(hide) (cd $(zip_root) && zip -qryX $(abspath $@) *)
   1553 	$(hide) zip -qryX $(abspath $@) build/target/product/security/
   1554 	$(hide) find device vendor -name \*.pk8 -o -name verifiedboot\* -o -name \*.x509.pem -o -name oem\*.prop | xargs zip -qryX $(abspath $@)>/dev/null || true
   1555 
   1556 .PHONY: otatools-package
   1557 otatools-package: $(BUILT_OTATOOLS_PACKAGE)
   1558 
   1559 endif # build_ota_package
   1560 
   1561 # -----------------------------------------------------------------
   1562 # A zip of the directories that map to the target filesystem.
   1563 # This zip can be used to create an OTA package or filesystem image
   1564 # as a post-build step.
   1565 #
   1566 name := $(TARGET_PRODUCT)
   1567 ifeq ($(TARGET_BUILD_TYPE),debug)
   1568   name := $(name)_debug
   1569 endif
   1570 name := $(name)-target_files-$(FILE_NAME_TAG)
   1571 
   1572 intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
   1573 BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
   1574 $(BUILT_TARGET_FILES_PACKAGE): intermediates := $(intermediates)
   1575 $(BUILT_TARGET_FILES_PACKAGE): \
   1576 		zip_root := $(intermediates)/$(name)
   1577 
   1578 # $(1): Directory to copy
   1579 # $(2): Location to copy it to
   1580 # The "ls -A" is to prevent "acp s/* d" from failing if s is empty.
   1581 define package_files-copy-root
   1582   if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
   1583     mkdir -p $(2) && \
   1584     $(ACP) -rd $(strip $(1))/* $(2); \
   1585   fi
   1586 endef
   1587 
   1588 built_ota_tools :=
   1589 
   1590 # We can't build static executables when SANITIZE_TARGET=address
   1591 ifeq ($(strip $(SANITIZE_TARGET)),)
   1592 built_ota_tools += \
   1593     $(call intermediates-dir-for,EXECUTABLES,updater,,,$(TARGET_PREFER_32_BIT))/updater
   1594 endif
   1595 
   1596 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_OTA_TOOLS := $(built_ota_tools)
   1597 
   1598 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_API_VERSION := $(RECOVERY_API_VERSION)
   1599 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_FSTAB_VERSION := $(RECOVERY_FSTAB_VERSION)
   1600 
   1601 ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
   1602 # default to common dir for device vendor
   1603 $(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_DEVICE_DIR)/../common
   1604 else
   1605 $(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
   1606 endif
   1607 
   1608 # Build OTA tools if not using the AB Updater.
   1609 ifneq ($(AB_OTA_UPDATER),true)
   1610 $(BUILT_TARGET_FILES_PACKAGE): $(built_ota_tools)
   1611 endif
   1612 
   1613 # If we are using recovery as boot, output recovery files to BOOT/.
   1614 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
   1615 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := BOOT
   1616 else
   1617 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := RECOVERY
   1618 endif
   1619 
   1620 # Depending on the various images guarantees that the underlying
   1621 # directories are up-to-date.
   1622 $(BUILT_TARGET_FILES_PACKAGE): \
   1623 		$(INSTALLED_BOOTIMAGE_TARGET) \
   1624 		$(INSTALLED_RADIOIMAGE_TARGET) \
   1625 		$(INSTALLED_RECOVERYIMAGE_TARGET) \
   1626 		$(INSTALLED_SYSTEMIMAGE) \
   1627 		$(INSTALLED_USERDATAIMAGE_TARGET) \
   1628 		$(INSTALLED_CACHEIMAGE_TARGET) \
   1629 		$(INSTALLED_VENDORIMAGE_TARGET) \
   1630 		$(INSTALLED_ANDROID_INFO_TXT_TARGET) \
   1631 		$(SELINUX_FC) \
   1632 		$(APKCERTS_FILE) \
   1633 		$(HOST_OUT_EXECUTABLES)/fs_config \
   1634 		| $(ACP)
   1635 	@echo "Package target files: $@"
   1636 	$(hide) rm -rf $@ $(zip_root)
   1637 	$(hide) mkdir -p $(dir $@) $(zip_root)
   1638 ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)))
   1639 	@# Components of the recovery image
   1640 	$(hide) mkdir -p $(zip_root)/$(PRIVATE_RECOVERY_OUT)
   1641 	$(hide) $(call package_files-copy-root, \
   1642 		$(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/$(PRIVATE_RECOVERY_OUT)/RAMDISK)
   1643 ifdef INSTALLED_KERNEL_TARGET
   1644 	$(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/kernel
   1645 endif
   1646 ifdef INSTALLED_2NDBOOTLOADER_TARGET
   1647 	$(hide) $(ACP) \
   1648 		$(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/second
   1649 endif
   1650 ifdef BOARD_KERNEL_CMDLINE
   1651 	$(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/cmdline
   1652 endif
   1653 ifdef BOARD_KERNEL_BASE
   1654 	$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/base
   1655 endif
   1656 ifdef BOARD_KERNEL_PAGESIZE
   1657 	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/pagesize
   1658 endif
   1659 endif # INSTALLED_RECOVERYIMAGE_TARGET defined or BOARD_USES_RECOVERY_AS_BOOT is true
   1660 	@# Components of the boot image
   1661 	$(hide) mkdir -p $(zip_root)/BOOT
   1662 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
   1663 	$(hide) mkdir -p $(zip_root)/ROOT
   1664 	$(hide) $(call package_files-copy-root, \
   1665 		$(TARGET_ROOT_OUT),$(zip_root)/ROOT)
   1666 else
   1667 	$(hide) $(call package_files-copy-root, \
   1668 		$(TARGET_ROOT_OUT),$(zip_root)/BOOT/RAMDISK)
   1669 endif
   1670 	@# If we are using recovery as boot, this is already done when processing recovery.
   1671 ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
   1672 ifdef INSTALLED_KERNEL_TARGET
   1673 	$(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/kernel
   1674 endif
   1675 ifdef INSTALLED_2NDBOOTLOADER_TARGET
   1676 	$(hide) $(ACP) \
   1677 		$(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second
   1678 endif
   1679 ifdef BOARD_KERNEL_CMDLINE
   1680 	$(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
   1681 endif
   1682 ifdef BOARD_KERNEL_BASE
   1683 	$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base
   1684 endif
   1685 ifdef BOARD_KERNEL_PAGESIZE
   1686 	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesize
   1687 endif
   1688 endif # BOARD_USES_RECOVERY_AS_BOOT
   1689 	$(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\
   1690 	            mkdir -p $(zip_root)/RADIO; \
   1691 	            $(ACP) $(t) $(zip_root)/RADIO/$(notdir $(t));)
   1692 	@# Contents of the system image
   1693 	$(hide) $(call package_files-copy-root, \
   1694 		$(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
   1695 	@# Contents of the data image
   1696 	$(hide) $(call package_files-copy-root, \
   1697 		$(TARGET_OUT_DATA),$(zip_root)/DATA)
   1698 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1699 	@# Contents of the vendor image
   1700 	$(hide) $(call package_files-copy-root, \
   1701 		$(TARGET_OUT_VENDOR),$(zip_root)/VENDOR)
   1702 endif
   1703 	@# Extra contents of the OTA package
   1704 	$(hide) mkdir -p $(zip_root)/OTA
   1705 	$(hide) $(ACP) $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/
   1706 ifneq ($(AB_OTA_UPDATER),true)
   1707 ifneq ($(built_ota_tools),)
   1708 	$(hide) mkdir -p $(zip_root)/OTA/bin
   1709 	$(hide) $(ACP) $(PRIVATE_OTA_TOOLS) $(zip_root)/OTA/bin/
   1710 endif
   1711 endif
   1712 	@# Files that do not end up in any images, but are necessary to
   1713 	@# build them.
   1714 	$(hide) mkdir -p $(zip_root)/META
   1715 	$(hide) $(ACP) $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
   1716 	$(hide) if test -e $(tool_extensions)/releasetools.py; then $(ACP) $(tool_extensions)/releasetools.py $(zip_root)/META/; fi
   1717 	$(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
   1718 	$(hide) $(ACP) $(SELINUX_FC) $(zip_root)/META/file_contexts.bin
   1719 	$(hide) echo "recovery_api_version=$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/misc_info.txt
   1720 	$(hide) echo "fstab_version=$(PRIVATE_RECOVERY_FSTAB_VERSION)" >> $(zip_root)/META/misc_info.txt
   1721 ifdef BOARD_FLASH_BLOCK_SIZE
   1722 	$(hide) echo "blocksize=$(BOARD_FLASH_BLOCK_SIZE)" >> $(zip_root)/META/misc_info.txt
   1723 endif
   1724 ifdef BOARD_BOOTIMAGE_PARTITION_SIZE
   1725 	$(hide) echo "boot_size=$(BOARD_BOOTIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
   1726 endif
   1727 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),)
   1728 	$(hide) echo "recovery_as_boot=$(BOARD_USES_RECOVERY_AS_BOOT)" >> $(zip_root)/META/misc_info.txt
   1729 endif
   1730 ifeq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   1731 	$(hide) echo "no_recovery=true" >> $(zip_root)/META/misc_info.txt
   1732 endif
   1733 ifdef BOARD_RECOVERYIMAGE_PARTITION_SIZE
   1734 	$(hide) echo "recovery_size=$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
   1735 endif
   1736 ifdef BOARD_HAS_EXT4_RESERVED_BLOCKS
   1737 	$(hide) echo "has_ext4_reserved_blocks=$(BOARD_HAS_EXT4_RESERVED_BLOCKS)" >> $(zip_root)/META/misc_info.txt
   1738 endif
   1739 ifdef TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS
   1740 	@# TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS can be empty to indicate that nothing but defaults should be used.
   1741 	$(hide) echo "recovery_mount_options=$(TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $(zip_root)/META/misc_info.txt
   1742 else
   1743 	$(hide) echo "recovery_mount_options=$(DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $(zip_root)/META/misc_info.txt
   1744 endif
   1745 	$(hide) echo "tool_extensions=$(tool_extensions)" >> $(zip_root)/META/misc_info.txt
   1746 	$(hide) echo "default_system_dev_certificate=$(DEFAULT_SYSTEM_DEV_CERTIFICATE)" >> $(zip_root)/META/misc_info.txt
   1747 ifdef PRODUCT_EXTRA_RECOVERY_KEYS
   1748 	$(hide) echo "extra_recovery_keys=$(PRODUCT_EXTRA_RECOVERY_KEYS)" >> $(zip_root)/META/misc_info.txt
   1749 endif
   1750 	$(hide) echo 'mkbootimg_args=$(BOARD_MKBOOTIMG_ARGS)' >> $(zip_root)/META/misc_info.txt
   1751 	$(hide) echo 'mkbootimg_version_args=$(INTERNAL_MKBOOTIMG_VERSION_ARGS)' >> $(zip_root)/META/misc_info.txt
   1752 	$(hide) echo "use_set_metadata=1" >> $(zip_root)/META/misc_info.txt
   1753 	$(hide) echo "multistage_support=1" >> $(zip_root)/META/misc_info.txt
   1754 	$(hide) echo "update_rename_support=1" >> $(zip_root)/META/misc_info.txt
   1755 	$(hide) echo "blockimgdiff_versions=1,2,3,4" >> $(zip_root)/META/misc_info.txt
   1756 ifneq ($(OEM_THUMBPRINT_PROPERTIES),)
   1757 	# OTA scripts are only interested in fingerprint related properties
   1758 	$(hide) echo "oem_fingerprint_properties=$(OEM_THUMBPRINT_PROPERTIES)" >> $(zip_root)/META/misc_info.txt
   1759 endif
   1760 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH),)
   1761 	$(hide) $(ACP) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH) \
   1762 	  $(zip_root)/META/$(notdir $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH))
   1763 endif
   1764 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH),)
   1765 	$(hide) $(ACP) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH) \
   1766 	  $(zip_root)/META/$(notdir $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH))
   1767 endif
   1768 ifneq ($(strip $(SANITIZE_TARGET)),)
   1769 	# We need to create userdata.img with real data because the instrumented libraries are in userdata.img.
   1770 	$(hide) echo "userdata_img_with_data=true" >> $(zip_root)/META/misc_info.txt
   1771 endif
   1772 ifeq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
   1773 	$(hide) echo "full_recovery_image=true" >> $(zip_root)/META/misc_info.txt
   1774 endif
   1775 	$(call generate-userimage-prop-dictionary, $(zip_root)/META/misc_info.txt)
   1776 ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   1777 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   1778 	    ./build/tools/releasetools/make_recovery_patch $(zip_root) $(zip_root)
   1779 endif
   1780 ifeq ($(AB_OTA_UPDATER),true)
   1781 	@# When using the A/B updater, include the updater config files in the zip.
   1782 	$(hide) $(ACP) $(TOPDIR)system/update_engine/update_engine.conf $(zip_root)/META/update_engine_config.txt
   1783 	$(hide) for part in $(AB_OTA_PARTITIONS); do \
   1784 	  echo "$${part}" >> $(zip_root)/META/ab_partitions.txt; \
   1785 	done
   1786 	$(hide) for conf in $(AB_OTA_POSTINSTALL_CONFIG); do \
   1787 	  echo "$${conf}" >> $(zip_root)/META/postinstall_config.txt; \
   1788 	done
   1789 	@# Include the build type in META/misc_info.txt so the server can easily differentiate production builds.
   1790 	$(hide) echo "build_type=$(TARGET_BUILD_VARIANT)" >> $(zip_root)/META/misc_info.txt
   1791 	$(hide) echo "ab_update=true" >> $(zip_root)/META/misc_info.txt
   1792 ifdef OSRELEASED_DIRECTORY
   1793 	$(hide) $(ACP) $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/product_id $(zip_root)/META/product_id.txt
   1794 	$(hide) $(ACP) $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/product_version $(zip_root)/META/product_version.txt
   1795 endif
   1796 endif
   1797 ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
   1798 	@# If breakpad symbols have been generated, add them to the zip.
   1799 	$(hide) $(ACP) -r $(TARGET_OUT_BREAKPAD) $(zip_root)/BREAKPAD
   1800 endif
   1801 	@# Zip everything up, preserving symlinks and placing META/ files first to
   1802 	@# help early validation of the .zip file while uploading it.
   1803 	$(hide) (cd $(zip_root) && \
   1804 	        zip -qryX ../$(notdir $@) ./META && \
   1805 	        zip -qryXu ../$(notdir $@) .)
   1806 	@# Run fs_config on all the system, vendor, boot ramdisk,
   1807 	@# and recovery ramdisk files in the zip, and save the output
   1808 	$(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
   1809 	$(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
   1810 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
   1811 	$(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
   1812 endif
   1813 	$(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
   1814 ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   1815 	$(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
   1816 endif
   1817 	$(hide) (cd $(zip_root) && zip -qX ../$(notdir $@) META/*filesystem_config.txt)
   1818 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   1819 	    ./build/tools/releasetools/add_img_to_target_files -v -p $(HOST_OUT) $@
   1820 
   1821 .PHONY: target-files-package
   1822 target-files-package: $(BUILT_TARGET_FILES_PACKAGE)
   1823 
   1824 ifneq ($(filter $(MAKECMDGOALS),target-files-package),)
   1825 $(call dist-for-goals, target-files-package, $(BUILT_TARGET_FILES_PACKAGE))
   1826 endif
   1827 
   1828 ifeq ($(build_ota_package),true)
   1829 # -----------------------------------------------------------------
   1830 # OTA update package
   1831 
   1832 name := $(TARGET_PRODUCT)
   1833 ifeq ($(TARGET_BUILD_TYPE),debug)
   1834   name := $(name)_debug
   1835 endif
   1836 name := $(name)-ota-$(FILE_NAME_TAG)
   1837 
   1838 INTERNAL_OTA_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   1839 
   1840 $(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
   1841 
   1842 $(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE)
   1843 	@echo "Package OTA: $@"
   1844 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   1845 	   ./build/tools/releasetools/ota_from_target_files -v \
   1846 	   --block \
   1847 	   -p $(HOST_OUT) \
   1848 	   -k $(KEY_CERT_PAIR) \
   1849 	   $(if $(OEM_OTA_CONFIG), -o $(OEM_OTA_CONFIG)) \
   1850 	   $(BUILT_TARGET_FILES_PACKAGE) $@
   1851 
   1852 .PHONY: otapackage
   1853 otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)
   1854 
   1855 endif    # build_ota_package
   1856 
   1857 # -----------------------------------------------------------------
   1858 # The update package
   1859 
   1860 name := $(TARGET_PRODUCT)
   1861 ifeq ($(TARGET_BUILD_TYPE),debug)
   1862   name := $(name)_debug
   1863 endif
   1864 name := $(name)-img-$(FILE_NAME_TAG)
   1865 
   1866 INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   1867 
   1868 $(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE)
   1869 	@echo "Package: $@"
   1870 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   1871 	   ./build/tools/releasetools/img_from_target_files -v \
   1872 	   -p $(HOST_OUT) \
   1873 	   $(BUILT_TARGET_FILES_PACKAGE) $@
   1874 
   1875 .PHONY: updatepackage
   1876 updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
   1877 
   1878 # -----------------------------------------------------------------
   1879 # A zip of the symbols directory.  Keep the full paths to make it
   1880 # more obvious where these files came from.
   1881 #
   1882 name := $(TARGET_PRODUCT)
   1883 ifeq ($(TARGET_BUILD_TYPE),debug)
   1884   name := $(name)_debug
   1885 endif
   1886 name := $(name)-symbols-$(FILE_NAME_TAG)
   1887 
   1888 SYMBOLS_ZIP := $(PRODUCT_OUT)/$(name).zip
   1889 # For apps_only build we'll establish the dependency later in build/core/main.mk.
   1890 ifndef TARGET_BUILD_APPS
   1891 $(SYMBOLS_ZIP): $(INSTALLED_SYSTEMIMAGE) $(INSTALLED_BOOTIMAGE_TARGET)
   1892 endif
   1893 $(SYMBOLS_ZIP):
   1894 	@echo "Package symbols: $@"
   1895 	$(hide) rm -rf $@
   1896 	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_UNSTRIPPED)
   1897 	$(hide) zip -qrX $@ $(TARGET_OUT_UNSTRIPPED)
   1898 
   1899 # -----------------------------------------------------------------
   1900 # A zip of the Android Apps. Not keeping full path so that we don't
   1901 # include product names when distributing
   1902 #
   1903 name := $(TARGET_PRODUCT)
   1904 ifeq ($(TARGET_BUILD_TYPE),debug)
   1905   name := $(name)_debug
   1906 endif
   1907 name := $(name)-apps-$(FILE_NAME_TAG)
   1908 
   1909 APPS_ZIP := $(PRODUCT_OUT)/$(name).zip
   1910 $(APPS_ZIP): $(INSTALLED_SYSTEMIMAGE)
   1911 	@echo "Package apps: $@"
   1912 	$(hide) rm -rf $@
   1913 	$(hide) mkdir -p $(dir $@)
   1914 	$(hide) apps_to_zip=`find $(TARGET_OUT_APPS) $(TARGET_OUT_APPS_PRIVILEGED) -mindepth 2 -maxdepth 3 -name "*.apk"`; \
   1915 	if [ -z "$$apps_to_zip" ]; then \
   1916 		echo "No apps to zip up. Generating empty apps archive." ; \
   1917 		a=$$(mktemp /tmp/XXXXXXX) && touch $$a && zip $@ $$a && zip -d $@ $$a; \
   1918 	else \
   1919 		zip -qjX $@ $$apps_to_zip; \
   1920 	fi
   1921 
   1922 #------------------------------------------------------------------
   1923 # A zip of emma code coverage meta files. Generated for fully emma
   1924 # instrumented build.
   1925 #
   1926 ifeq (true,$(EMMA_INSTRUMENT))
   1927 EMMA_META_ZIP := $(PRODUCT_OUT)/emma_meta.zip
   1928 # the dependency will be set up later in build/core/main.mk.
   1929 $(EMMA_META_ZIP) :
   1930 	@echo "Collecting Emma coverage meta files."
   1931 	$(hide) find $(TARGET_COMMON_OUT_ROOT) $(HOST_COMMON_OUT_ROOT) -name "coverage.em" | \
   1932 		zip -@ -qX $@
   1933 
   1934 endif # EMMA_INSTRUMENT=true
   1935 
   1936 #------------------------------------------------------------------
   1937 # A zip of Proguard obfuscation dictionary files.
   1938 # Only for apps_only build.
   1939 #
   1940 ifdef TARGET_BUILD_APPS
   1941 PROGUARD_DICT_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-$(FILE_NAME_TAG).zip
   1942 # the dependency will be set up later in build/core/main.mk.
   1943 $(PROGUARD_DICT_ZIP) :
   1944 	@echo "Packaging Proguard obfuscation dictionary files."
   1945 	$(hide) dict_files=`find $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS -name proguard_dictionary`; \
   1946 		if [ -n "$$dict_files" ]; then \
   1947 		  unobfuscated_jars=$${dict_files//proguard_dictionary/classes.jar}; \
   1948 		  zip -qX $@ $$dict_files $$unobfuscated_jars; \
   1949 		else \
   1950 		  touch $(dir $@)/zipdummy; \
   1951 		  (cd $(dir $@) && zip -q $(notdir $@) zipdummy); \
   1952 		  zip -qd $@ zipdummy; \
   1953 		  rm $(dir $@)/zipdummy; \
   1954 		fi
   1955 
   1956 endif # TARGET_BUILD_APPS
   1957 
   1958 # -----------------------------------------------------------------
   1959 # dalvik something
   1960 .PHONY: dalvikfiles
   1961 dalvikfiles: $(INTERNAL_DALVIK_MODULES)
   1962 
   1963 # -----------------------------------------------------------------
   1964 # The emulator package
   1965 ifeq ($(BUILD_EMULATOR),true)
   1966 INTERNAL_EMULATOR_PACKAGE_FILES += \
   1967         $(HOST_OUT_EXECUTABLES)/emulator$(HOST_EXECUTABLE_SUFFIX) \
   1968         prebuilts/qemu-kernel/$(TARGET_ARCH)/kernel-qemu \
   1969         $(INSTALLED_RAMDISK_TARGET) \
   1970 		$(INSTALLED_SYSTEMIMAGE) \
   1971 		$(INSTALLED_USERDATAIMAGE_TARGET)
   1972 
   1973 name := $(TARGET_PRODUCT)-emulator-$(FILE_NAME_TAG)
   1974 
   1975 INTERNAL_EMULATOR_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   1976 
   1977 $(INTERNAL_EMULATOR_PACKAGE_TARGET): $(INTERNAL_EMULATOR_PACKAGE_FILES)
   1978 	@echo "Package: $@"
   1979 	$(hide) zip -qjX $@ $(INTERNAL_EMULATOR_PACKAGE_FILES)
   1980 
   1981 endif
   1982 # -----------------------------------------------------------------
   1983 # Old PDK stuffs, retired
   1984 # The pdk package (Platform Development Kit)
   1985 
   1986 #ifneq (,$(filter pdk,$(MAKECMDGOALS)))
   1987 #  include development/pdk/Pdk.mk
   1988 #endif
   1989 
   1990 
   1991 # -----------------------------------------------------------------
   1992 # The SDK
   1993 
   1994 # The SDK includes host-specific components, so it belongs under HOST_OUT.
   1995 sdk_dir := $(HOST_OUT)/sdk/$(TARGET_PRODUCT)
   1996 
   1997 # Build a name that looks like:
   1998 #
   1999 #     linux-x86   --> android-sdk_12345_linux-x86
   2000 #     darwin-x86  --> android-sdk_12345_mac-x86
   2001 #     windows-x86 --> android-sdk_12345_windows
   2002 #
   2003 sdk_name := android-sdk_$(FILE_NAME_TAG)
   2004 ifeq ($(HOST_OS),darwin)
   2005   INTERNAL_SDK_HOST_OS_NAME := mac
   2006 else
   2007   INTERNAL_SDK_HOST_OS_NAME := $(HOST_OS)
   2008 endif
   2009 ifneq ($(HOST_OS),windows)
   2010   INTERNAL_SDK_HOST_OS_NAME := $(INTERNAL_SDK_HOST_OS_NAME)-$(SDK_HOST_ARCH)
   2011 endif
   2012 sdk_name := $(sdk_name)_$(INTERNAL_SDK_HOST_OS_NAME)
   2013 
   2014 sdk_dep_file := $(sdk_dir)/sdk_deps.mk
   2015 
   2016 ATREE_FILES :=
   2017 -include $(sdk_dep_file)
   2018 
   2019 # if we don't have a real list, then use "everything"
   2020 ifeq ($(strip $(ATREE_FILES)),)
   2021 ATREE_FILES := \
   2022 	$(ALL_PREBUILT) \
   2023 	$(ALL_DEFAULT_INSTALLED_MODULES) \
   2024 	$(INSTALLED_RAMDISK_TARGET) \
   2025 	$(ALL_DOCS) \
   2026 	$(ALL_SDK_FILES)
   2027 endif
   2028 
   2029 atree_dir := development/build
   2030 
   2031 
   2032 sdk_atree_files := \
   2033 	$(atree_dir)/sdk.exclude.atree \
   2034 	$(atree_dir)/sdk-$(HOST_OS)-$(SDK_HOST_ARCH).atree
   2035 
   2036 # development/build/sdk-android-<abi>.atree is used to differentiate
   2037 # between architecture models (e.g. ARMv5TE versus ARMv7) when copying
   2038 # files like the kernel image. We use TARGET_CPU_ABI because we don't
   2039 # have a better way to distinguish between CPU models.
   2040 ifneq (,$(strip $(wildcard $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree)))
   2041   sdk_atree_files += $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree
   2042 endif
   2043 
   2044 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ATREE_FILES),)
   2045 sdk_atree_files += $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ATREE_FILES)
   2046 else
   2047 sdk_atree_files += $(atree_dir)/sdk.atree
   2048 endif
   2049 
   2050 include $(BUILD_SYSTEM)/sdk_font.mk
   2051 
   2052 deps := \
   2053 	$(target_notice_file_txt) \
   2054 	$(tools_notice_file_txt) \
   2055 	$(OUT_DOCS)/offline-sdk-timestamp \
   2056 	$(SYMBOLS_ZIP) \
   2057 	$(INSTALLED_SYSTEMIMAGE) \
   2058 	$(INSTALLED_USERDATAIMAGE_TARGET) \
   2059 	$(INSTALLED_RAMDISK_TARGET) \
   2060 	$(INSTALLED_SDK_BUILD_PROP_TARGET) \
   2061 	$(INSTALLED_BUILD_PROP_TARGET) \
   2062 	$(ATREE_FILES) \
   2063 	$(sdk_atree_files) \
   2064 	$(HOST_OUT_EXECUTABLES)/atree \
   2065 	$(HOST_OUT_EXECUTABLES)/line_endings \
   2066 	$(SDK_FONT_DEPS)
   2067 
   2068 INTERNAL_SDK_TARGET := $(sdk_dir)/$(sdk_name).zip
   2069 $(INTERNAL_SDK_TARGET): PRIVATE_NAME := $(sdk_name)
   2070 $(INTERNAL_SDK_TARGET): PRIVATE_DIR := $(sdk_dir)/$(sdk_name)
   2071 $(INTERNAL_SDK_TARGET): PRIVATE_DEP_FILE := $(sdk_dep_file)
   2072 $(INTERNAL_SDK_TARGET): PRIVATE_INPUT_FILES := $(sdk_atree_files)
   2073 
   2074 # Set SDK_GNU_ERROR to non-empty to fail when a GNU target is built.
   2075 #
   2076 #SDK_GNU_ERROR := true
   2077 
   2078 $(INTERNAL_SDK_TARGET): $(deps)
   2079 	@echo "Package SDK: $@"
   2080 	$(hide) rm -rf $(PRIVATE_DIR) $@
   2081 	$(hide) for f in $(target_gnu_MODULES); do \
   2082 	  if [ -f $$f ]; then \
   2083 	    echo SDK: $(if $(SDK_GNU_ERROR),ERROR:,warning:) \
   2084 	        including GNU target $$f >&2; \
   2085 	    FAIL=$(SDK_GNU_ERROR); \
   2086 	  fi; \
   2087 	done; \
   2088 	if [ $$FAIL ]; then exit 1; fi
   2089 	$(hide) echo $(notdir $(SDK_FONT_DEPS)) | tr " " "\n"  > $(SDK_FONT_TEMP)/fontsInSdk.txt
   2090 	$(hide) ( \
   2091 		ATREE_STRIP="strip -x" \
   2092 		$(HOST_OUT_EXECUTABLES)/atree \
   2093 		$(addprefix -f ,$(PRIVATE_INPUT_FILES)) \
   2094 			-m $(PRIVATE_DEP_FILE) \
   2095 			-I . \
   2096 			-I $(PRODUCT_OUT) \
   2097 			-I $(HOST_OUT) \
   2098 			-I $(TARGET_COMMON_OUT_ROOT) \
   2099 			-v "PLATFORM_NAME=android-$(PLATFORM_VERSION)" \
   2100 			-v "OUT_DIR=$(OUT_DIR)" \
   2101 			-v "HOST_OUT=$(HOST_OUT)" \
   2102 			-v "TARGET_ARCH=$(TARGET_ARCH)" \
   2103 			-v "TARGET_CPU_ABI=$(TARGET_CPU_ABI)" \
   2104 			-v "DLL_EXTENSION=$(HOST_SHLIB_SUFFIX)" \
   2105 			-v "FONT_OUT=$(SDK_FONT_TEMP)" \
   2106 			-v "JACK_SDKTOOL_VERSION=$(JACK_SDKTOOL_VERSION)" \
   2107 			-o $(PRIVATE_DIR) && \
   2108 		cp -f $(target_notice_file_txt) \
   2109 				$(PRIVATE_DIR)/system-images/android-$(PLATFORM_VERSION)/$(TARGET_CPU_ABI)/NOTICE.txt && \
   2110 		cp -f $(tools_notice_file_txt) $(PRIVATE_DIR)/platform-tools/NOTICE.txt && \
   2111 		HOST_OUT_EXECUTABLES=$(HOST_OUT_EXECUTABLES) HOST_OS=$(HOST_OS) \
   2112 			development/build/tools/sdk_clean.sh $(PRIVATE_DIR) && \
   2113 		chmod -R ug+rwX $(PRIVATE_DIR) && \
   2114 		cd $(dir $@) && zip -rqX $(notdir $@) $(PRIVATE_NAME) \
   2115 	) || ( rm -rf $(PRIVATE_DIR) $@ && exit 44 )
   2116 
   2117 
   2118 # Is a Windows SDK requested? If so, we need some definitions from here
   2119 # in order to find the Linux SDK used to create the Windows one.
   2120 MAIN_SDK_NAME := $(sdk_name)
   2121 MAIN_SDK_DIR  := $(sdk_dir)
   2122 MAIN_SDK_ZIP  := $(INTERNAL_SDK_TARGET)
   2123 ifneq ($(filter win_sdk winsdk-tools,$(MAKECMDGOALS)),)
   2124 include $(TOPDIR)development/build/tools/windows_sdk.mk
   2125 endif
   2126 
   2127 # -----------------------------------------------------------------
   2128 # Findbugs
   2129 INTERNAL_FINDBUGS_XML_TARGET := $(PRODUCT_OUT)/findbugs.xml
   2130 INTERNAL_FINDBUGS_HTML_TARGET := $(PRODUCT_OUT)/findbugs.html
   2131 $(INTERNAL_FINDBUGS_XML_TARGET): $(ALL_FINDBUGS_FILES)
   2132 	@echo UnionBugs: $@
   2133 	$(hide) $(FINDBUGS_DIR)/unionBugs $(ALL_FINDBUGS_FILES) \
   2134 	> $@
   2135 $(INTERNAL_FINDBUGS_HTML_TARGET): $(INTERNAL_FINDBUGS_XML_TARGET)
   2136 	@echo ConvertXmlToText: $@
   2137 	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl \
   2138 	$(INTERNAL_FINDBUGS_XML_TARGET) > $@
   2139 
   2140 # -----------------------------------------------------------------
   2141 # Findbugs
   2142 
   2143 # -----------------------------------------------------------------
   2144 # These are some additional build tasks that need to be run.
   2145 ifneq ($(dont_bother),true)
   2146 include $(sort $(wildcard $(BUILD_SYSTEM)/tasks/*.mk))
   2147 -include $(sort $(wildcard vendor/*/build/tasks/*.mk))
   2148 -include $(sort $(wildcard device/*/build/tasks/*.mk))
   2149 -include $(sort $(wildcard product/*/build/tasks/*.mk))
   2150 # Also the project-specific tasks
   2151 -include $(sort $(wildcard vendor/*/*/build/tasks/*.mk))
   2152 -include $(sort $(wildcard device/*/*/build/tasks/*.mk))
   2153 -include $(sort $(wildcard product/*/*/build/tasks/*.mk))
   2154 endif
   2155 
   2156 include $(BUILD_SYSTEM)/product-graph.mk
   2157 
   2158 # -----------------------------------------------------------------
   2159 # Create SDK repository packages. Must be done after tasks/* since
   2160 # we need the addon rules defined.
   2161 ifneq ($(sdk_repo_goal),)
   2162 include $(TOPDIR)development/build/tools/sdk_repo.mk
   2163 endif
   2164