blob: 5097f1266f0ed5347cefca66a7e9028a08dcb254 [file] [log] [blame]
Joe Onorato214a42b2009-04-09 20:36:06 -07001# 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
Dan Willemsen921f5812018-09-10 15:14:09 -070015.PHONY: sdk_addon
Joe Onorato214a42b2009-04-09 20:36:06 -070016
17# If they didn't define PRODUCT_SDK_ADDON_NAME, then we won't define
18# any of these rules.
Anton Hansson8dab0a62019-03-28 15:45:40 +000019addon_name := $(PRODUCT_SDK_ADDON_NAME)
Joe Onorato214a42b2009-04-09 20:36:06 -070020ifneq ($(addon_name),)
21
Raphael Moll0d7d09a2014-08-21 15:22:08 -070022addon_dir_leaf := $(addon_name)-$(FILE_NAME_TAG)-$(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_img := $(HOST_OUT_SDK_ADDON)/$(addon_dir_img).zip
27staging := $(intermediates)
Joe Onorato214a42b2009-04-09 20:36:06 -070028
29sdk_addon_deps :=
30files_to_copy :=
31
Raphael30e07072011-02-03 22:59:27 -080032define stub-addon-jar-file
33$(subst .jar,_stub-addon.jar,$(1))
34endef
35
36define stub-addon-jar
37$(call stub-addon-jar-file,$(1)): $(1) | mkstubs
38 $(info Stubbing addon jar using $(PRODUCT_SDK_ADDON_STUB_DEFS))
Colin Cross0851df82017-06-30 13:55:38 -070039 $(hide) $(JAVA) -jar $(call module-installed-files,mkstubs) $(if $(hide),,--v) \
Raphael30e07072011-02-03 22:59:27 -080040 "$$<" "$$@" @$(PRODUCT_SDK_ADDON_STUB_DEFS)
41endef
42
Joe Onorato214a42b2009-04-09 20:36:06 -070043# Files that are built and then copied into the sdk-addon
Anton Hansson8dab0a62019-03-28 15:45:40 +000044ifneq ($(PRODUCT_SDK_ADDON_COPY_MODULES),)
45$(foreach cf,$(PRODUCT_SDK_ADDON_COPY_MODULES), \
Joe Onorato214a42b2009-04-09 20:36:06 -070046 $(eval _src := $(call module-stubs-files,$(call word-colon,1,$(cf)))) \
Raphael30e07072011-02-03 22:59:27 -080047 $(eval $(call stub-addon-jar,$(_src))) \
48 $(eval _src := $(call stub-addon-jar-file,$(_src))) \
Joe Onorato214a42b2009-04-09 20:36:06 -070049 $(if $(_src),,$(eval $(error Unknown or unlinkable module: $(call word-colon,1,$(cf)). Requested by $(INTERNAL_PRODUCT)))) \
50 $(eval _dest := $(call word-colon,2,$(cf))) \
Raphael Moll0d7d09a2014-08-21 15:22:08 -070051 $(eval files_to_copy += $(addon_dir_leaf):$(_src):$(_dest)) \
Joe Onorato214a42b2009-04-09 20:36:06 -070052 )
53endif
54
55# Files that are copied directly into the sdk-addon
Anton Hansson8dab0a62019-03-28 15:45:40 +000056ifneq ($(PRODUCT_SDK_ADDON_COPY_FILES),)
57$(foreach cf,$(PRODUCT_SDK_ADDON_COPY_FILES), \
Raphael Moll0d7d09a2014-08-21 15:22:08 -070058 $(eval _src := $(call word-colon,1,$(cf))) \
59 $(eval _dest := $(call word-colon,2,$(cf))) \
60 $(if $(findstring images/,$(_dest)), $(eval _root := $(addon_dir_img)), $(eval _root := $(addon_dir_leaf))) \
61 $(eval files_to_copy += $(_root):$(_src):$(_dest)) \
62 )
63endif
Joe Onorato214a42b2009-04-09 20:36:06 -070064
Raphael Moll0d7d09a2014-08-21 15:22:08 -070065# Files copied in the system-image directory
Joe Onorato214a42b2009-04-09 20:36:06 -070066files_to_copy += \
Bo Hubc88ff62017-08-01 19:02:09 +000067 $(addon_dir_img):$(INSTALLED_QEMU_SYSTEMIMAGE):images/$(TARGET_CPU_ABI)/system.img \
bohu753e9e42017-08-10 00:20:01 -070068 $(addon_dir_img):$(INSTALLED_QEMU_VENDORIMAGE):images/$(TARGET_CPU_ABI)/vendor.img \
bohu8fd437c2020-03-30 20:16:13 -070069 $(addon_dir_img):$(INSTALLED_QEMU_RAMDISKIMAGE):images/$(TARGET_CPU_ABI)/ramdisk.img \
Raphael Moll0d7d09a2014-08-21 15:22:08 -070070 $(addon_dir_img):$(PRODUCT_OUT)/system/build.prop:images/$(TARGET_CPU_ABI)/build.prop \
bohua83fc0e2018-06-25 15:33:14 -070071 $(addon_dir_img):device/generic/goldfish/data/etc/userdata.img:images/$(TARGET_CPU_ABI)/userdata.img \
Raphael Moll0d7d09a2014-08-21 15:22:08 -070072 $(addon_dir_img):$(target_notice_file_txt):images/$(TARGET_CPU_ABI)/NOTICE.txt \
Anton Hansson8dab0a62019-03-28 15:45:40 +000073 $(addon_dir_img):$(PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP):images/source.properties
Joe Onorato214a42b2009-04-09 20:36:06 -070074
Matt Wachowski9e4d5152018-08-07 16:29:22 -070075
76ifeq ($(BOARD_AVB_ENABLE),true)
77files_to_copy += \
78 $(addon_dir_img):$(QEMU_VERIFIED_BOOT_PARAMS):images/$(TARGET_CPU_ABI)/VerifiedBootParams.textproto
79endif
80
Joe Onorato214a42b2009-04-09 20:36:06 -070081# Generate rules to copy the requested files
82$(foreach cf,$(files_to_copy), \
Raphael Moll0d7d09a2014-08-21 15:22:08 -070083 $(eval _root := $(call word-colon,1,$(cf))) \
84 $(eval _src := $(call word-colon,2,$(cf))) \
85 $(eval _dest := $(call append-path,$(call append-path,$(staging),$(_root)),$(call word-colon,3,$(cf)))) \
Joe Onorato214a42b2009-04-09 20:36:06 -070086 $(eval $(call copy-one-file,$(_src),$(_dest))) \
87 $(eval sdk_addon_deps += $(_dest)) \
88 )
89
Raphael Moll0d7d09a2014-08-21 15:22:08 -070090# The system-image source.properties is a template that we directly expand in-place
Raphael Molla4d1f6a2014-10-09 17:48:12 -070091addon_img_source_prop := $(call append-path,$(staging),$(addon_dir_img))/images/$(TARGET_CPU_ABI)/source.properties
Raphael Moll0d7d09a2014-08-21 15:22:08 -070092sdk_addon_deps += $(addon_img_source_prop)
93
Anton Hansson8dab0a62019-03-28 15:45:40 +000094$(addon_img_source_prop): $(PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP)
Raphael Moll0d7d09a2014-08-21 15:22:08 -070095 @echo Generate $@
96 $(hide) mkdir -p $(dir $@)
97 $(hide) sed \
98 -e 's/$${PLATFORM_VERSION}/$(PLATFORM_VERSION)/' \
99 -e 's/$${PLATFORM_SDK_VERSION}/$(PLATFORM_SDK_VERSION)/' \
100 -e 's/$${PLATFORM_VERSION_CODENAME}/$(subst REL,,$(PLATFORM_VERSION_CODENAME))/' \
101 -e 's/$${TARGET_ARCH}/$(TARGET_ARCH)/' \
102 -e 's/$${TARGET_CPU_ABI}/$(TARGET_CPU_ABI)/' \
103 $< > $@ && sed -i -e '/^AndroidVersion.CodeName=\s*$$/d' $@
104
105
Ying Wanga032d3d2011-11-11 10:52:12 -0800106# We don't know about all of the docs files, so depend on the timestamps for
107# them, and record the directories, and the packaging rule will just copy the
Joe Onorato214a42b2009-04-09 20:36:06 -0700108# whole thing.
Anton Hansson8dab0a62019-03-28 15:45:40 +0000109doc_modules := $(PRODUCT_SDK_ADDON_DOC_MODULES)
Ying Wanga032d3d2011-11-11 10:52:12 -0800110sdk_addon_deps += $(foreach dm, $(doc_modules), $(call doc-timestamp-for, $(dm)))
111$(full_target): PRIVATE_DOCS_DIRS := $(addprefix $(OUT_DOCS)/, $(doc_modules))
Joe Onorato214a42b2009-04-09 20:36:06 -0700112
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700113$(full_target): PRIVATE_STAGING_DIR := $(call append-path,$(staging),$(addon_dir_leaf))
Joe Onorato214a42b2009-04-09 20:36:06 -0700114
Dan Willemsen288bedf2019-05-28 15:36:47 -0700115$(full_target): $(sdk_addon_deps) | $(SOONG_ZIP)
Joe Onorato214a42b2009-04-09 20:36:06 -0700116 @echo Packaging SDK Addon: $@
Marius Rennb1df7012011-11-23 18:02:46 -0800117 $(hide) mkdir -p $(PRIVATE_STAGING_DIR)/docs
Ying Wanga032d3d2011-11-11 10:52:12 -0800118 $(hide) for d in $(PRIVATE_DOCS_DIRS); do \
Dan Willemsen288bedf2019-05-28 15:36:47 -0700119 cp -R $$d $(PRIVATE_STAGING_DIR)/docs ;\
Ying Wanga032d3d2011-11-11 10:52:12 -0800120 done
Joe Onorato214a42b2009-04-09 20:36:06 -0700121 $(hide) mkdir -p $(dir $@)
Jeff Gaston25210ce2017-09-15 12:34:29 -0700122 $(hide) $(SOONG_ZIP) -o $@ -C $(dir $(PRIVATE_STAGING_DIR)) -D $(PRIVATE_STAGING_DIR)
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700123
Raphael Molla4d1f6a2014-10-09 17:48:12 -0700124$(full_target_img): PRIVATE_STAGING_DIR := $(call append-path,$(staging),$(addon_dir_img))/images/$(TARGET_CPU_ABI)
Dan Willemsen288bedf2019-05-28 15:36:47 -0700125$(full_target_img): $(full_target) $(addon_img_source_prop) | $(SOONG_ZIP)
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700126 @echo Packaging SDK Addon System-Image: $@
127 $(hide) mkdir -p $(dir $@)
Dan Willemsen288bedf2019-05-28 15:36:47 -0700128 cp -R $(PRODUCT_OUT)/data $(PRIVATE_STAGING_DIR)/data
Jeff Gaston25210ce2017-09-15 12:34:29 -0700129 $(hide) $(SOONG_ZIP) -o $@ -C $(dir $(PRIVATE_STAGING_DIR)) -D $(PRIVATE_STAGING_DIR)
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700130
Joe Onorato214a42b2009-04-09 20:36:06 -0700131
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700132sdk_addon: $(full_target) $(full_target_img)
Joe Onorato214a42b2009-04-09 20:36:06 -0700133
Raphael3e548302011-02-23 16:45:57 -0800134ifneq ($(sdk_repo_goal),)
135# If we're building the sdk_repo, keep the name of the addon zip
136# around so that development/build/tools/sdk_repo.mk can dist it
137# at the appropriate location.
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700138ADDON_SDK_ZIP := $(full_target)
139ADDON_SDK_IMG_ZIP := $(full_target_img)
Raphael3e548302011-02-23 16:45:57 -0800140else
141# When not building an sdk_repo, just dist the addon zip file
142# as-is.
Joe Onoratoeb19b3e2009-04-13 16:32:16 -0700143$(call dist-for-goals, sdk_addon, $(full_target))
Raphael3e548302011-02-23 16:45:57 -0800144endif
Joe Onoratoeb19b3e2009-04-13 16:32:16 -0700145
Joe Onorato214a42b2009-04-09 20:36:06 -0700146else # addon_name
147ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),)
148$(error Trying to build sdk_addon, but product '$(INTERNAL_PRODUCT)' does not define one)
149endif
150endif # addon_name