1# Copyright (C) 2009 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15.PHONY: sdk_addon 16 17# If they didn't define PRODUCT_SDK_ADDON_NAME, then we won't define 18# any of these rules. 19addon_name := $(PRODUCT_SDK_ADDON_NAME) 20ifneq ($(addon_name),) 21 22addon_dir_leaf := $(addon_name)-$(INTERNAL_SDK_HOST_OS_NAME) 23addon_dir_img := $(addon_dir_leaf)-img 24intermediates := $(HOST_OUT_INTERMEDIATES)/SDK_ADDON/$(addon_name)_intermediates 25full_target := $(HOST_OUT_SDK_ADDON)/$(addon_dir_leaf).zip 26full_target_dist_name := $(addon_name)-FILE_NAME_TAG_PLACEHOLDER-$(INTERNAL_SDK_HOST_OS_NAME) 27full_target_img := $(HOST_OUT_SDK_ADDON)/$(addon_dir_img).zip 28staging := $(intermediates) 29 30sdk_addon_deps := 31files_to_copy := 32 33define stub-addon-jar-file 34$(subst .jar,_stub-addon.jar,$(1)) 35endef 36 37define stub-addon-jar 38$(call stub-addon-jar-file,$(1)): $(1) | mkstubs 39 $(info Stubbing addon jar using $(PRODUCT_SDK_ADDON_STUB_DEFS)) 40 $(hide) $(JAVA) -jar $(call module-installed-files,mkstubs) $(if $(hide),,--v) \ 41 "$$<" "$$@" @$(PRODUCT_SDK_ADDON_STUB_DEFS) 42endef 43 44# Files that are built and then copied into the sdk-addon 45ifneq ($(PRODUCT_SDK_ADDON_COPY_MODULES),) 46$(foreach cf,$(PRODUCT_SDK_ADDON_COPY_MODULES), \ 47 $(eval _src := $(call module-stubs-files,$(call word-colon,1,$(cf)))) \ 48 $(eval $(call stub-addon-jar,$(_src))) \ 49 $(eval _src := $(call stub-addon-jar-file,$(_src))) \ 50 $(if $(_src),,$(eval $(error Unknown or unlinkable module: $(call word-colon,1,$(cf)). Requested by $(INTERNAL_PRODUCT)))) \ 51 $(eval _dest := $(call word-colon,2,$(cf))) \ 52 $(eval files_to_copy += $(addon_dir_leaf):$(_src):$(_dest)) \ 53 ) 54endif 55 56# Files that are copied directly into the sdk-addon 57ifneq ($(PRODUCT_SDK_ADDON_COPY_FILES),) 58$(foreach cf,$(PRODUCT_SDK_ADDON_COPY_FILES), \ 59 $(eval _src := $(call word-colon,1,$(cf))) \ 60 $(eval _dest := $(call word-colon,2,$(cf))) \ 61 $(if $(findstring images/,$(_dest)), $(eval _root := $(addon_dir_img)), $(eval _root := $(addon_dir_leaf))) \ 62 $(eval files_to_copy += $(_root):$(_src):$(_dest)) \ 63 ) 64endif 65 66# Files copied in the system-image directory 67files_to_copy += \ 68 $(addon_dir_img):$(INSTALLED_QEMU_SYSTEMIMAGE):images/$(TARGET_CPU_ABI)/system.img \ 69 $(addon_dir_img):$(INSTALLED_QEMU_VENDORIMAGE):images/$(TARGET_CPU_ABI)/vendor.img \ 70 $(addon_dir_img):$(INSTALLED_QEMU_RAMDISKIMAGE):images/$(TARGET_CPU_ABI)/ramdisk.img \ 71 $(addon_dir_img):$(PRODUCT_OUT)/system/build.prop:images/$(TARGET_CPU_ABI)/build.prop \ 72 $(addon_dir_img):device/generic/goldfish/data/etc/userdata.img:images/$(TARGET_CPU_ABI)/userdata.img \ 73 $(addon_dir_img):$(target_notice_file_txt):images/$(TARGET_CPU_ABI)/NOTICE.txt \ 74 $(addon_dir_img):$(PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP):images/source.properties 75 76 77ifeq ($(BOARD_AVB_ENABLE),true) 78files_to_copy += \ 79 $(addon_dir_img):$(QEMU_VERIFIED_BOOT_PARAMS):images/$(TARGET_CPU_ABI)/VerifiedBootParams.textproto 80endif 81 82# Generate rules to copy the requested files 83$(foreach cf,$(files_to_copy), \ 84 $(eval _root := $(call word-colon,1,$(cf))) \ 85 $(eval _src := $(call word-colon,2,$(cf))) \ 86 $(eval _dest := $(call append-path,$(call append-path,$(staging),$(_root)),$(call word-colon,3,$(cf)))) \ 87 $(eval $(call copy-one-file,$(_src),$(_dest))) \ 88 $(eval sdk_addon_deps += $(_dest)) \ 89 ) 90 91# The system-image source.properties is a template that we directly expand in-place 92addon_img_source_prop := $(call append-path,$(staging),$(addon_dir_img))/images/$(TARGET_CPU_ABI)/source.properties 93sdk_addon_deps += $(addon_img_source_prop) 94 95$(addon_img_source_prop): $(PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP) 96 @echo Generate $@ 97 $(hide) mkdir -p $(dir $@) 98 $(hide) sed \ 99 -e 's/$${PLATFORM_VERSION}/$(PLATFORM_VERSION)/' \ 100 -e 's/$${PLATFORM_SDK_VERSION}/$(PLATFORM_SDK_VERSION)/' \ 101 -e 's/$${PLATFORM_VERSION_CODENAME}/$(subst REL,,$(PLATFORM_VERSION_CODENAME))/' \ 102 -e 's/$${TARGET_ARCH}/$(TARGET_ARCH)/' \ 103 -e 's/$${TARGET_CPU_ABI}/$(TARGET_CPU_ABI)/' \ 104 $< > $@ && sed -i -e '/^AndroidVersion.CodeName=\s*$$/d' $@ 105 106 107# We don't know about all of the docs files, so depend on the timestamps for 108# them, and record the directories, and the packaging rule will just copy the 109# whole thing. 110doc_modules := $(PRODUCT_SDK_ADDON_DOC_MODULES) 111sdk_addon_deps += $(foreach dm, $(doc_modules), $(call doc-timestamp-for, $(dm))) 112$(full_target): PRIVATE_DOCS_DIRS := $(addprefix $(OUT_DOCS)/, $(doc_modules)) 113 114$(full_target): PRIVATE_STAGING_DIR := $(call append-path,$(staging),$(addon_dir_leaf)) 115 116$(full_target): $(sdk_addon_deps) | $(SOONG_ZIP) 117 @echo Packaging SDK Addon: $@ 118 $(hide) mkdir -p $(PRIVATE_STAGING_DIR)/docs 119 $(hide) for d in $(PRIVATE_DOCS_DIRS); do \ 120 cp -R $$d $(PRIVATE_STAGING_DIR)/docs ;\ 121 done 122 $(hide) mkdir -p $(dir $@) 123 $(hide) $(SOONG_ZIP) -o $@ -C $(dir $(PRIVATE_STAGING_DIR)) -D $(PRIVATE_STAGING_DIR) 124 125$(full_target_img): PRIVATE_STAGING_DIR := $(call append-path,$(staging),$(addon_dir_img))/images/$(TARGET_CPU_ABI) 126$(full_target_img): $(full_target) $(addon_img_source_prop) | $(SOONG_ZIP) 127 @echo Packaging SDK Addon System-Image: $@ 128 $(hide) mkdir -p $(dir $@) 129 cp -R $(PRODUCT_OUT)/data $(PRIVATE_STAGING_DIR) 130 $(hide) $(SOONG_ZIP) -o $@ -C $(dir $(PRIVATE_STAGING_DIR)) -D $(PRIVATE_STAGING_DIR) 131 132 133sdk_addon: $(full_target) $(full_target_img) 134 135ifneq ($(sdk_repo_goal),) 136# If we're building the sdk_repo, keep the name of the addon zip 137# around so that development/build/tools/sdk_repo.mk can dist it 138# at the appropriate location. 139ADDON_SDK_ZIP := $(full_target) 140ADDON_SDK_IMG_ZIP := $(full_target_img) 141else 142# When not building an sdk_repo, just dist the addon zip file 143# as-is. 144$(call dist-for-goals, sdk_addon, $(full_target):$(full_target_dist_name)) 145endif 146 147else # addon_name 148ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),) 149$(error Trying to build sdk_addon, but product '$(INTERNAL_PRODUCT)' does not define one) 150endif 151endif # addon_name 152