blob: e26773ce806e6b383a11c3ab75947bb1f26f0da6 [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
15
16# If they didn't define PRODUCT_SDK_ADDON_NAME, then we won't define
17# any of these rules.
18addon_name := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_NAME))
19ifneq ($(addon_name),)
20
Raphael Moll0d7d09a2014-08-21 15:22:08 -070021addon_dir_leaf := $(addon_name)-$(FILE_NAME_TAG)-$(INTERNAL_SDK_HOST_OS_NAME)
22addon_dir_img := $(addon_dir_leaf)-img
23intermediates := $(HOST_OUT_INTERMEDIATES)/SDK_ADDON/$(addon_name)_intermediates
24full_target := $(HOST_OUT_SDK_ADDON)/$(addon_dir_leaf).zip
25full_target_img := $(HOST_OUT_SDK_ADDON)/$(addon_dir_img).zip
26staging := $(intermediates)
Joe Onorato214a42b2009-04-09 20:36:06 -070027
28sdk_addon_deps :=
29files_to_copy :=
30
Raphael30e07072011-02-03 22:59:27 -080031define stub-addon-jar-file
32$(subst .jar,_stub-addon.jar,$(1))
33endef
34
35define stub-addon-jar
36$(call stub-addon-jar-file,$(1)): $(1) | mkstubs
37 $(info Stubbing addon jar using $(PRODUCT_SDK_ADDON_STUB_DEFS))
Colin Cross0851df82017-06-30 13:55:38 -070038 $(hide) $(JAVA) -jar $(call module-installed-files,mkstubs) $(if $(hide),,--v) \
Raphael30e07072011-02-03 22:59:27 -080039 "$$<" "$$@" @$(PRODUCT_SDK_ADDON_STUB_DEFS)
40endef
41
Joe Onorato214a42b2009-04-09 20:36:06 -070042# Files that are built and then copied into the sdk-addon
43ifneq ($(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_COPY_MODULES)),)
44$(foreach cf,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_COPY_MODULES), \
45 $(eval _src := $(call module-stubs-files,$(call word-colon,1,$(cf)))) \
Raphael30e07072011-02-03 22:59:27 -080046 $(eval $(call stub-addon-jar,$(_src))) \
47 $(eval _src := $(call stub-addon-jar-file,$(_src))) \
Joe Onorato214a42b2009-04-09 20:36:06 -070048 $(if $(_src),,$(eval $(error Unknown or unlinkable module: $(call word-colon,1,$(cf)). Requested by $(INTERNAL_PRODUCT)))) \
49 $(eval _dest := $(call word-colon,2,$(cf))) \
Raphael Moll0d7d09a2014-08-21 15:22:08 -070050 $(eval files_to_copy += $(addon_dir_leaf):$(_src):$(_dest)) \
Joe Onorato214a42b2009-04-09 20:36:06 -070051 )
52endif
53
54# Files that are copied directly into the sdk-addon
Raphael Moll0d7d09a2014-08-21 15:22:08 -070055ifneq ($(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_COPY_FILES)),)
56$(foreach cf,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_COPY_FILES), \
57 $(eval _src := $(call word-colon,1,$(cf))) \
58 $(eval _dest := $(call word-colon,2,$(cf))) \
59 $(if $(findstring images/,$(_dest)), $(eval _root := $(addon_dir_img)), $(eval _root := $(addon_dir_leaf))) \
60 $(eval files_to_copy += $(_root):$(_src):$(_dest)) \
61 )
62endif
Joe Onorato214a42b2009-04-09 20:36:06 -070063
Raphael Moll0d7d09a2014-08-21 15:22:08 -070064# Files copied in the system-image directory
Joe Onorato214a42b2009-04-09 20:36:06 -070065files_to_copy += \
Bo Hubc88ff62017-08-01 19:02:09 +000066 $(addon_dir_img):$(INSTALLED_QEMU_SYSTEMIMAGE):images/$(TARGET_CPU_ABI)/system.img \
bohu753e9e42017-08-10 00:20:01 -070067 $(addon_dir_img):$(INSTALLED_QEMU_VENDORIMAGE):images/$(TARGET_CPU_ABI)/vendor.img \
Raphael Moll0d7d09a2014-08-21 15:22:08 -070068 $(addon_dir_img):$(BUILT_USERDATAIMAGE_TARGET):images/$(TARGET_CPU_ABI)/userdata.img \
69 $(addon_dir_img):$(BUILT_RAMDISK_TARGET):images/$(TARGET_CPU_ABI)/ramdisk.img \
70 $(addon_dir_img):$(PRODUCT_OUT)/system/build.prop:images/$(TARGET_CPU_ABI)/build.prop \
71 $(addon_dir_img):$(target_notice_file_txt):images/$(TARGET_CPU_ABI)/NOTICE.txt \
72 $(addon_dir_img):$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP):images/source.properties
Joe Onorato214a42b2009-04-09 20:36:06 -070073
74# Generate rules to copy the requested files
75$(foreach cf,$(files_to_copy), \
Raphael Moll0d7d09a2014-08-21 15:22:08 -070076 $(eval _root := $(call word-colon,1,$(cf))) \
77 $(eval _src := $(call word-colon,2,$(cf))) \
78 $(eval _dest := $(call append-path,$(call append-path,$(staging),$(_root)),$(call word-colon,3,$(cf)))) \
Joe Onorato214a42b2009-04-09 20:36:06 -070079 $(eval $(call copy-one-file,$(_src),$(_dest))) \
80 $(eval sdk_addon_deps += $(_dest)) \
81 )
82
Raphael Moll0d7d09a2014-08-21 15:22:08 -070083# The system-image source.properties is a template that we directly expand in-place
Raphael Molla4d1f6a2014-10-09 17:48:12 -070084addon_img_source_prop := $(call append-path,$(staging),$(addon_dir_img))/images/$(TARGET_CPU_ABI)/source.properties
Raphael Moll0d7d09a2014-08-21 15:22:08 -070085sdk_addon_deps += $(addon_img_source_prop)
86
87$(addon_img_source_prop): $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP)
88 @echo Generate $@
89 $(hide) mkdir -p $(dir $@)
90 $(hide) sed \
91 -e 's/$${PLATFORM_VERSION}/$(PLATFORM_VERSION)/' \
92 -e 's/$${PLATFORM_SDK_VERSION}/$(PLATFORM_SDK_VERSION)/' \
93 -e 's/$${PLATFORM_VERSION_CODENAME}/$(subst REL,,$(PLATFORM_VERSION_CODENAME))/' \
94 -e 's/$${TARGET_ARCH}/$(TARGET_ARCH)/' \
95 -e 's/$${TARGET_CPU_ABI}/$(TARGET_CPU_ABI)/' \
96 $< > $@ && sed -i -e '/^AndroidVersion.CodeName=\s*$$/d' $@
97
98
Ying Wanga032d3d2011-11-11 10:52:12 -080099# We don't know about all of the docs files, so depend on the timestamps for
100# them, and record the directories, and the packaging rule will just copy the
Joe Onorato214a42b2009-04-09 20:36:06 -0700101# whole thing.
Ying Wanga032d3d2011-11-11 10:52:12 -0800102doc_modules := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_DOC_MODULES))
103sdk_addon_deps += $(foreach dm, $(doc_modules), $(call doc-timestamp-for, $(dm)))
104$(full_target): PRIVATE_DOCS_DIRS := $(addprefix $(OUT_DOCS)/, $(doc_modules))
Joe Onorato214a42b2009-04-09 20:36:06 -0700105
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700106$(full_target): PRIVATE_STAGING_DIR := $(call append-path,$(staging),$(addon_dir_leaf))
Joe Onorato214a42b2009-04-09 20:36:06 -0700107
Ying Wang5d887702015-11-04 10:06:25 -0800108$(full_target): $(sdk_addon_deps) | $(ACP)
Joe Onorato214a42b2009-04-09 20:36:06 -0700109 @echo Packaging SDK Addon: $@
Marius Rennb1df7012011-11-23 18:02:46 -0800110 $(hide) mkdir -p $(PRIVATE_STAGING_DIR)/docs
Ying Wanga032d3d2011-11-11 10:52:12 -0800111 $(hide) for d in $(PRIVATE_DOCS_DIRS); do \
Marius Rennb1df7012011-11-23 18:02:46 -0800112 $(ACP) -r $$d $(PRIVATE_STAGING_DIR)/docs ;\
Ying Wanga032d3d2011-11-11 10:52:12 -0800113 done
Joe Onorato214a42b2009-04-09 20:36:06 -0700114 $(hide) mkdir -p $(dir $@)
Dan Willemsen48a621c2015-10-29 16:33:05 -0700115 $(hide) ( F=$$(pwd)/$@ ; cd $(PRIVATE_STAGING_DIR)/.. && zip -rqX $$F $(notdir $(PRIVATE_STAGING_DIR)) )
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700116
Raphael Molla4d1f6a2014-10-09 17:48:12 -0700117$(full_target_img): PRIVATE_STAGING_DIR := $(call append-path,$(staging),$(addon_dir_img))/images/$(TARGET_CPU_ABI)
bohu753e9e42017-08-10 00:20:01 -0700118$(full_target_img): $(full_target) $(addon_img_source_prop) | $(ACP)
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700119 @echo Packaging SDK Addon System-Image: $@
120 $(hide) mkdir -p $(dir $@)
bohu753e9e42017-08-10 00:20:01 -0700121 $(ACP) -r $(PRODUCT_OUT)/data $(PRIVATE_STAGING_DIR)/data
Dan Willemsen48a621c2015-10-29 16:33:05 -0700122 $(hide) ( F=$$(pwd)/$@ ; cd $(PRIVATE_STAGING_DIR)/.. && zip -rqX $$F $(notdir $(PRIVATE_STAGING_DIR)) )
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700123
Joe Onorato214a42b2009-04-09 20:36:06 -0700124
125.PHONY: sdk_addon
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700126sdk_addon: $(full_target) $(full_target_img)
Joe Onorato214a42b2009-04-09 20:36:06 -0700127
Raphael3e548302011-02-23 16:45:57 -0800128ifneq ($(sdk_repo_goal),)
129# If we're building the sdk_repo, keep the name of the addon zip
130# around so that development/build/tools/sdk_repo.mk can dist it
131# at the appropriate location.
Raphael Moll0d7d09a2014-08-21 15:22:08 -0700132ADDON_SDK_ZIP := $(full_target)
133ADDON_SDK_IMG_ZIP := $(full_target_img)
Raphael3e548302011-02-23 16:45:57 -0800134else
135# When not building an sdk_repo, just dist the addon zip file
136# as-is.
Joe Onoratoeb19b3e2009-04-13 16:32:16 -0700137$(call dist-for-goals, sdk_addon, $(full_target))
Raphael3e548302011-02-23 16:45:57 -0800138endif
Joe Onoratoeb19b3e2009-04-13 16:32:16 -0700139
Joe Onorato214a42b2009-04-09 20:36:06 -0700140else # addon_name
141ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),)
142$(error Trying to build sdk_addon, but product '$(INTERNAL_PRODUCT)' does not define one)
143endif
144endif # addon_name