1# This file defines the rule to fuse the platform.zip into the current PDK build.
2PDK_PLATFORM_JAVA_ZIP_JAVA_TARGET_LIB_DIR :=
3PDK_PLATFORM_JAVA_ZIP_JAVA_HOST_LIB_DIR := \
4	host/common/obj/JAVA_LIBRARIES/bouncycastle-host_intermediates \
5	host/common/obj/JAVA_LIBRARIES/compatibility-host-util_intermediates \
6	host/common/obj/JAVA_LIBRARIES/cts-tradefed-harness_intermediates \
7	host/common/obj/JAVA_LIBRARIES/hosttestlib_intermediates
8PDK_PLATFORM_JAVA_ZIP_CONTENTS :=
9
10ifneq (,$(filter platform-java, $(MAKECMDGOALS))$(PDK_FUSION_PLATFORM_ZIP)$(PDK_FUSION_PLATFORM_DIR))
11# additional items to add to platform.zip for platform-java build
12# For these dirs, add classes.jar and javalib.jar from the dir to platform.zip
13# all paths under out dir
14PDK_PLATFORM_JAVA_ZIP_JAVA_TARGET_LIB_DIR += \
15  target/common/obj/JAVA_LIBRARIES/android.test.runner_intermediates \
16  target/common/obj/JAVA_LIBRARIES/android-common_intermediates \
17  target/common/obj/JAVA_LIBRARIES/android-ex-camera2_intermediates \
18  target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates \
19  target/common/obj/JAVA_LIBRARIES/bouncycastle_intermediates \
20  target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates \
21  target/common/obj/JAVA_LIBRARIES/core-oj_intermediates \
22  target/common/obj/JAVA_LIBRARIES/core-libart_intermediates \
23  target/common/obj/JAVA_LIBRARIES/core-icu4j_intermediates \
24  target/common/obj/JAVA_LIBRARIES/ext_intermediates \
25  target/common/obj/JAVA_LIBRARIES/framework-minus-apex_intermediates \
26  target/common/obj/JAVA_LIBRARIES/hwbinder_intermediates \
27  target/common/obj/JAVA_LIBRARIES/ims-common_intermediates \
28  target/common/obj/JAVA_LIBRARIES/okhttp_intermediates \
29  target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates \
30  target/common/obj/JAVA_LIBRARIES/voip-common_intermediates \
31
32# not java libraries
33PDK_PLATFORM_JAVA_ZIP_CONTENTS += \
34	target/common/obj/APPS/framework-res_intermediates/package-export.apk \
35	target/common/obj/APPS/framework-res_intermediates/src/R.stamp
36endif # platform-java or FUSION build
37
38PDK_PLATFORM_JAVA_ZIP_JAVA_LIB_DIR := \
39	$(PDK_PLATFORM_JAVA_ZIP_JAVA_TARGET_LIB_DIR) \
40	$(PDK_PLATFORM_JAVA_ZIP_JAVA_HOST_LIB_DIR)
41
42PDK_PLATFORM_JAVA_ZIP_CONTENTS += $(foreach lib_dir,$(PDK_PLATFORM_JAVA_ZIP_JAVA_LIB_DIR),\
43    $(lib_dir)/classes.jar $(lib_dir)/classes-header.jar \
44    $(lib_dir)/javalib.jar  $(lib_dir)/classes*.dex \
45    $(lib_dir)/classes.dex.toc )
46
47# check and override java support level
48ifneq ($(TARGET_BUILD_PDK)$(PDK_FUSION_PLATFORM_ZIP)$(PDK_FUSION_PLATFORM_DIR),)
49  ifneq ($(wildcard external/proguard),)
50    TARGET_BUILD_JAVA_SUPPORT_LEVEL := sdk
51  else # no proguard
52    TARGET_BUILD_JAVA_SUPPORT_LEVEL :=
53  endif
54  # platform support is set after checking platform.zip
55endif # PDK
56
57ifneq (,$(PDK_FUSION_PLATFORM_DIR)$(PDK_FUSION_PLATFORM_ZIP))
58
59_pdk_fusion_intermediates :=
60_pdk_fusion_stamp :=
61_pdk_fusion_file_list :=
62_pdk_fusion_java_file_list :=
63PDK_FUSION_SYMLINK_STAMP :=
64
65ifdef PDK_FUSION_PLATFORM_DIR
66  _pdk_fusion_intermediates := $(PDK_FUSION_PLATFORM_DIR)
67  _pdk_fusion_file_list := $(sort \
68    $(shell cd $(PDK_FUSION_PLATFORM_DIR); find * -type f))
69  _pdk_fusion_java_file_list := $(filter target/common/%,$(_pdk_fusion_file_list))
70  _pdk_fusion_file_list := $(filter-out target/common/%,$(_pdk_fusion_file_list))
71
72  PDK_FUSION_SYMLINK_STAMP := $(call intermediates-dir-for, PACKAGING, pdk_fusion)/pdk_symlinks.stamp
73
74  symlink_list := $(sort \
75    $(shell cd $(PDK_FUSION_PLATFORM_DIR); find * -type l))
76$(PDK_FUSION_SYMLINK_STAMP): PRIVATE_SYMLINKS := $(foreach s,$(symlink_list),\
77    $(s):$(shell readlink $(PDK_FUSION_PLATFORM_DIR)/$(s)))
78$(PDK_FUSION_SYMLINK_STAMP):
79	$(foreach s,$(PRIVATE_SYMLINKS),\
80	  mkdir -p $(PRODUCT_OUT)/$(dir $(call word-colon,1,$(s))) && \
81	  ln -sf $(call word-colon,2,$(s)) $(PRODUCT_OUT)/$(call word-colon,1,$(s)) &&) true
82	touch $@
83
84  symlink_list :=
85endif # PDK_FUSION_PLATFORM_DIR
86
87ifdef PDK_FUSION_PLATFORM_ZIP
88  _pdk_fusion_intermediates := $(call intermediates-dir-for, PACKAGING, pdk_fusion)
89  _pdk_fusion_stamp := $(_pdk_fusion_intermediates)/pdk_fusion.stamp
90
91  _pdk_fusion_file_list := $(shell unzip -Z -1 $(PDK_FUSION_PLATFORM_ZIP) \
92      '*[^/]' -x 'target/common/*' 2>/dev/null)
93  _pdk_fusion_java_file_list := \
94      $(shell unzip -Z -1 $(PDK_FUSION_PLATFORM_ZIP) 'target/common/*' 2>/dev/null)
95  _pdk_fusion_files := $(addprefix $(_pdk_fusion_intermediates)/,\
96      $(_pdk_fusion_file_list) $(_pdk_fusion_java_file_list))
97
98$(_pdk_fusion_stamp) : $(PDK_FUSION_PLATFORM_ZIP)
99	@echo "Unzip $(dir $@) <- $<"
100	$(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
101	$(hide) unzip -qo $< -d $(dir $@)
102	$(call split-long-arguments,-touch,$(_pdk_fusion_files))
103	$(hide) touch $@
104
105$(_pdk_fusion_files) : $(_pdk_fusion_stamp)
106endif # PDK_FUSION_PLATFORM_ZIP
107
108ifneq ($(_pdk_fusion_java_file_list),)
109  # This represents whether java build can use platform API or not
110  # This should not be used in Android.mk
111  TARGET_BUILD_PDK_JAVA_PLATFORM := true
112  ifneq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),)
113    TARGET_BUILD_JAVA_SUPPORT_LEVEL := platform
114  endif
115endif
116
117# Implicit pattern rules to copy the fusion files to the system image directory.
118# Note that if there is already explicit rule in the build system to generate a file,
119# the pattern rule will be just ignored by make.
120# That's desired by us: we want only absent files from the platform zip package.
121# Copy with the last-modified time preserved, never follow symbolic links.
122$(PRODUCT_OUT)/% : $(_pdk_fusion_intermediates)/% $(_pdk_fusion_stamp)
123	@mkdir -p $(dir $@)
124	$(hide) rm -rf $@
125	$(hide) cp -fpPR $< $@
126
127# implicit rules for host java files
128$(HOST_COMMON_OUT_ROOT)/% : $(_pdk_fusion_intermediates)/host/common/% $(_pdk_fusion_stamp)
129	@mkdir -p $(dir $@)
130	$(hide) cp -fpPR $< $@
131
132ifeq (true,$(TARGET_BUILD_PDK_JAVA_PLATFORM))
133  PDK_FUSION_OUT_DIR := $(OUT_DIR)
134
135  define JAVA_dependency_template
136  $(call add-dependency,$(PDK_FUSION_OUT_DIR)/$(strip $(1)),\
137    $(foreach d,$(filter $(2),$(_pdk_fusion_java_file_list)),$(PDK_FUSION_OUT_DIR)/$(d)))
138  endef
139
140  # needs explicit dependency as package-export.apk is not explicitly pulled
141  $(eval $(call JAVA_dependency_template,\
142  target/common/obj/APPS/framework-res_intermediates/src/R.stamp,\
143  target/common/obj/APPS/framework-res_intermediates/package-export.apk))
144
145  # javalib.jar should pull classes.jar as classes.jar is not explicitly pulled.
146  $(foreach lib_dir,$(PDK_PLATFORM_JAVA_ZIP_JAVA_TARGET_LIB_DIR),\
147  $(eval $(call JAVA_dependency_template,$(lib_dir)/javalib.jar,\
148  $(lib_dir)/classes.jar)))
149
150# implicit rules for all other target files
151$(TARGET_COMMON_OUT_ROOT)/% : $(_pdk_fusion_intermediates)/target/common/% $(_pdk_fusion_stamp)
152	@mkdir -p $(dir $@)
153	$(hide) cp -fpPR $< $@
154endif # TARGET_BUILD_PDK_JAVA_PLATFORM
155
156ALL_PDK_FUSION_FILES := $(addprefix $(PRODUCT_OUT)/, $(_pdk_fusion_file_list))
157
158endif # PDK_FUSION_PLATFORM_ZIP || PDK_FUSION_PLATFORM_DIR
159
160ifeq ($(TARGET_BUILD_PDK),true)
161  $(info PDK TARGET_BUILD_JAVA_SUPPORT_LEVEL $(TARGET_BUILD_JAVA_SUPPORT_LEVEL))
162  ifeq ($(TARGET_BUILD_PDK_JAVA_PLATFORM),)
163    # SDK used for Java build under PDK
164    PDK_BUILD_SDK_VERSION := $(lastword $(TARGET_AVAILABLE_SDK_VERSIONS))
165    $(info PDK Build uses SDK $(PDK_BUILD_SDK_VERSION))
166  else # PDK_JAVA
167    $(info PDK Build uses the current platform API)
168  endif # PDK_JAVA
169endif # BUILD_PDK
170
171ifneq (,$(filter platform platform-java, $(MAKECMDGOALS))$(filter true,$(TARGET_BUILD_PDK)))
172  # files under $(PRODUCT_OUT)/symbols to help debugging.
173  # Source not included to PDK due to dependency issue, so provide symbols instead.
174
175  PDK_SYMBOL_FILES_LIST :=
176  ifeq ($(TARGET_IS_64_BIT),true)
177    PDK_SYMBOL_FILES_LIST += system/bin/app_process64
178    ifdef TARGET_2ND_ARCH
179      PDK_SYMBOL_FILES_LIST += system/bin/app_process32
180    endif
181  else
182    PDK_SYMBOL_FILES_LIST += system/bin/app_process32
183  endif
184
185  ifneq (,$(PDK_FUSION_PLATFORM_ZIP)$(PDK_FUSION_PLATFORM_DIR))
186    # symbols should be explicitly pulled for fusion build
187    $(foreach f,$(filter $(PDK_SYMBOL_FILES_LIST), $(_pdk_fusion_file_list)),\
188      $(eval $(call add-dependency,$(PRODUCT_OUT)/$(f),$(PRODUCT_OUT)/symbols/$(f))))
189  endif # PLATFORM_ZIP || PLATFORM_DIR
190endif # platform.zip/dir build or PDK
191