build_custom_image.mk revision 5fcf1094f9cf4d57c2598237f99621f254130d71
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)/$(my_custom_image_name) 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_DICT_FILE := $(CUSTOM_IMAGE_DICT_FILE) 73$(my_built_custom_image): $(INTERNAL_USERIMAGES_DEPS) $(my_built_modules) $(my_image_copy_files) \ 74 $(CUSTOM_IMAGE_DICT_FILE) 75 @echo "Build image $@" 76 $(hide) rm -rf $(PRIVATE_INTERMEDIATES) && mkdir -p $(PRIVATE_INTERMEDIATES) 77 $(hide) rm -rf $(PRIVATE_STAGING_DIR) && mkdir -p $(PRIVATE_STAGING_DIR) 78 # Copy all the files. 79 $(hide) $(foreach p,$(PRIVATE_COPY_PAIRS),\ 80 $(eval pair := $(subst :,$(space),$(p)))\ 81 mkdir -p $(dir $(word 2,$(pair)));\ 82 cp -Rf $(word 1,$(pair)) $(word 2,$(pair));) 83 $(if $($(PRIVATE_PICKUP_FILES)),$(hide) cp -Rf $(PRIVATE_PICKUP_FILES) $(PRIVATE_STAGING_DIR)) 84 # Generate the dict. 85 $(hide) echo "# For all accepted properties, see BuildImage() in tools/releasetools/build_image.py" > $(PRIVATE_INTERMEDIATES)/image_info.txt 86 $(hide) echo "mount_point=$(PRIVATE_MOUNT_POINT)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 87 $(hide) echo "fs_type=$(PRIVATE_FILE_SYSTEM_TYPE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 88 $(hide) echo "partition_size=$(PRIVATE_PARTITION_SIZE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 89 $(if $(PRIVATE_DICT_FILE),\ 90 $(hide) echo "# Properties from $(PRIVATE_DICT_FILE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 91 cat $(PRIVATE_DICT_FILE) >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 92 # Generate the image. 93 $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \ 94 ./build/tools/releasetools/build_image.py \ 95 $(PRIVATE_STAGING_DIR) $(PRIVATE_INTERMEDIATES)/image_info.txt $@ 96 97my_installed_custom_image := $(PRODUCT_OUT)/$(notdir $(my_built_custom_image)) 98$(my_installed_custom_image) : $(my_built_custom_image) 99 $(call copy-file-to-new-target-with-cp) 100 101.PHONY: $(my_custom_image_name) 102custom_images $(my_custom_image_name) : $(my_installed_custom_image) 103 104# Archive the built image. 105$(call dist-for-goals, $(my_custom_image_name) custom_images,$(my_installed_custom_image)) 106