1# 2# Copyright (C) 2015 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17 18# Define rule to build one custom image. 19# Input variables: my_custom_imag_makefile 20 21$(call clear-var-list, $(custom_image_parameter_variables)) 22 23include $(my_custom_imag_makefile) 24 25my_custom_image_name := $(basename $(notdir $(my_custom_imag_makefile))) 26 27intermediates := $(call intermediates-dir-for,PACKAGING,$(my_custom_image_name)) 28my_built_custom_image := $(intermediates)/$(my_custom_image_name).img 29my_staging_dir := $(intermediates)/$(CUSTOM_IMAGE_MOUNT_POINT) 30 31# Collect CUSTOM_IMAGE_MODULES's installd files and their PICKUP_FILES. 32my_built_modules := 33my_copy_pairs := 34my_pickup_files := 35 36$(foreach m,$(CUSTOM_IMAGE_MODULES),\ 37 $(eval _pickup_files := $(strip $(ALL_MODULES.$(m).PICKUP_FILES)\ 38 $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PICKUP_FILES)))\ 39 $(eval _built_files := $(strip $(ALL_MODULES.$(m).BUILT_INSTALLED)\ 40 $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).BUILT_INSTALLED)))\ 41 $(if $(_pickup_files)$(_built_files),,\ 42 $(warning Unknown installed file for module '$(m)'))\ 43 $(eval my_pickup_files += $(_pickup_files))\ 44 $(foreach i, $(_built_files),\ 45 $(eval bui_ins := $(subst :,$(space),$(i)))\ 46 $(eval ins := $(word 2,$(bui_ins)))\ 47 $(if $(filter $(TARGET_OUT_ROOT)/%,$(ins)),\ 48 $(eval bui := $(word 1,$(bui_ins)))\ 49 $(eval my_built_modules += $(bui))\ 50 $(eval my_copy_dest := $(patsubst $(PRODUCT_OUT)/%,%,$(ins)))\ 51 $(eval my_copy_dest := $(subst /,$(space),$(my_copy_dest)))\ 52 $(eval my_copy_dest := $(wordlist 2,999,$(my_copy_dest)))\ 53 $(eval my_copy_dest := $(subst $(space),/,$(my_copy_dest)))\ 54 $(eval my_copy_pairs += $(bui):$(my_staging_dir)/$(my_copy_dest)))\ 55 )) 56 57# Collect CUSTOM_IMAGE_COPY_FILES. 58my_image_copy_files := 59$(foreach f,$(CUSTOM_IMAGE_COPY_FILES),\ 60 $(eval pair := $(subst :,$(space),$(f)))\ 61 $(eval src := $(word 1,$(pair)))\ 62 $(eval my_image_copy_files += $(src))\ 63 $(eval my_copy_pairs += $(src):$(my_staging_dir)/$(word 2,$(pair)))) 64 65$(my_built_custom_image): PRIVATE_INTERMEDIATES := $(intermediates) 66$(my_built_custom_image): PRIVATE_MOUNT_POINT := $(CUSTOM_IMAGE_MOUNT_POINT) 67$(my_built_custom_image): PRIVATE_PARTITION_SIZE := $(CUSTOM_IMAGE_PARTITION_SIZE) 68$(my_built_custom_image): PRIVATE_FILE_SYSTEM_TYPE := $(CUSTOM_IMAGE_FILE_SYSTEM_TYPE) 69$(my_built_custom_image): PRIVATE_STAGING_DIR := $(my_staging_dir) 70$(my_built_custom_image): PRIVATE_COPY_PAIRS := $(my_copy_pairs) 71$(my_built_custom_image): PRIVATE_PICKUP_FILES := $(my_pickup_files) 72$(my_built_custom_image): PRIVATE_SELINUX := $(CUSTOM_IMAGE_SELINUX) 73$(my_built_custom_image): PRIVATE_SUPPORT_VERITY := $(CUSTOM_IMAGE_SUPPORT_VERITY) 74$(my_built_custom_image): PRIVATE_VERITY_KEY := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY) 75$(my_built_custom_image): PRIVATE_VERITY_BLOCK_DEVICE := $(CUSTOM_IMAGE_VERITY_BLOCK_DEVICE) 76$(my_built_custom_image): PRIVATE_DICT_FILE := $(CUSTOM_IMAGE_DICT_FILE) 77$(my_built_custom_image): $(INTERNAL_USERIMAGES_DEPS) $(my_built_modules) $(my_image_copy_files) \ 78 $(CUSTOM_IMAGE_DICT_FILE) 79 @echo "Build image $@" 80 $(hide) rm -rf $(PRIVATE_INTERMEDIATES) && mkdir -p $(PRIVATE_INTERMEDIATES) 81 $(hide) rm -rf $(PRIVATE_STAGING_DIR) && mkdir -p $(PRIVATE_STAGING_DIR) 82 # Copy all the files. 83 $(hide) $(foreach p,$(PRIVATE_COPY_PAIRS),\ 84 $(eval pair := $(subst :,$(space),$(p)))\ 85 mkdir -p $(dir $(word 2,$(pair)));\ 86 cp -Rf $(word 1,$(pair)) $(word 2,$(pair));) 87 $(if $($(PRIVATE_PICKUP_FILES)),$(hide) cp -Rf $(PRIVATE_PICKUP_FILES) $(PRIVATE_STAGING_DIR)) 88 # Generate the dict. 89 $(hide) echo "# For all accepted properties, see BuildImage() in tools/releasetools/build_image.py" > $(PRIVATE_INTERMEDIATES)/image_info.txt 90 $(hide) echo "mount_point=$(PRIVATE_MOUNT_POINT)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 91 $(hide) echo "fs_type=$(PRIVATE_FILE_SYSTEM_TYPE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 92 $(hide) echo "partition_size=$(PRIVATE_PARTITION_SIZE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 93 $(if $(PRIVATE_SELINUX),$(hide) echo "selinux_fc=$(SELINUX_FC)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 94 $(if $(PRIVATE_SUPPORT_VERITY),\ 95 $(hide) echo "verity=$(PRIVATE_SUPPORT_VERITY)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 96 echo "verity_key=$(PRIVATE_VERITY_KEY)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 97 echo "verity_signer_cmd=$(VERITY_SIGNER)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 98 echo "verity_block_device=$(PRIVATE_VERITY_BLOCK_DEVICE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 99 $(if $(PRIVATE_DICT_FILE),\ 100 $(hide) echo "# Properties from $(PRIVATE_DICT_FILE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 101 cat $(PRIVATE_DICT_FILE) >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 102 # Generate the image. 103 $(if $(filter oem,$(PRIVATE_MOUNT_POINT)), \ 104 $(hide) echo "oem.buildnumber=$(BUILD_NUMBER)" >> $(PRIVATE_STAGING_DIR)/oem.prop) 105 $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \ 106 ./build/tools/releasetools/build_image.py \ 107 $(PRIVATE_STAGING_DIR) $(PRIVATE_INTERMEDIATES)/image_info.txt $@ $(TARGET_OUT) 108 109my_installed_custom_image := $(PRODUCT_OUT)/$(notdir $(my_built_custom_image)) 110$(my_installed_custom_image) : $(my_built_custom_image) 111 $(call copy-file-to-new-target-with-cp) 112 113.PHONY: $(my_custom_image_name) 114custom_images $(my_custom_image_name) : $(my_installed_custom_image) 115 116# Archive the built image. 117$(call dist-for-goals, $(my_custom_image_name) custom_images,$(my_installed_custom_image)) 118