• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2017 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
15current_makefile := $(lastword $(MAKEFILE_LIST))
16
17# BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
18ifeq ($(BOARD_VNDK_VERSION),current)
19
20# PLATFORM_VNDK_VERSION must be set.
21ifneq (,$(PLATFORM_VNDK_VERSION))
22
23# BOARD_VNDK_RUNTIME_DISABLE must not be set to 'true'.
24ifneq ($(BOARD_VNDK_RUNTIME_DISABLE),true)
25
26# Returns list of src:dest paths of the intermediate objs
27#
28# Args:
29#   $(1): list of module and filename pairs (e.g., ld.config.txt:ld.config.27.txt ...)
30#   $(2): if not empty, evaluates for TARGET_2ND_ARCH
31define paths-of-intermediates
32$(strip \
33  $(foreach pair,$(1), \
34    $(eval module := $(call word-colon,1,$(pair))$(if $(2),$(TARGET_2ND_ARCH_MODULE_SUFFIX))) \
35    $(eval built := $(ALL_MODULES.$(module).BUILT_INSTALLED)) \
36    $(eval filename := $(call word-colon,2,$(pair))) \
37    $(if $(wordlist 2,100,$(built)), \
38      $(error Unable to handle multiple built files ($(module)): $(built))) \
39    $(if $(built),$(call word-colon,1,$(built)):$(filename)) \
40  ) \
41)
42endef
43
44# Returns src:dest list of notice files
45#
46# Args:
47#   $(1): list of lib names (e.g., libfoo.vendor)
48define paths-of-notice-files
49$(strip \
50  $(foreach lib,$(1), \
51    $(eval notice := $(sort \
52      $(ALL_MODULES.$(lib).NOTICES) \
53      $(if $(TARGET_2ND_ARCH),
54        $(ALL_MODULES.$(lib)$(TARGET_2ND_ARCH_MODULE_SUFFIX).NOTICES)))) \
55    $(if $(wordlist 2,100,$(notice)), \
56      $(error Unable to handle multiple notice files ($(lib)): $(notice))) \
57    $(if $(notice),$(notice):$(subst .vendor,,$(lib)).so.txt)))
58endef
59
60vndk_core_libs := $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES))
61vndk_sp_libs := $(addsuffix .vendor,$(VNDK_SAMEPROCESS_LIBRARIES))
62vndk_private_libs := $(addsuffix .vendor,$(VNDK_PRIVATE_LIBRARIES))
63
64vndk_snapshot_libs := \
65  $(vndk_core_libs) \
66  $(vndk_sp_libs)
67
68vndk_prebuilt_txts := \
69  ld.config.txt \
70  vndksp.libraries.txt \
71  llndk.libraries.txt
72
73vndk_snapshot_top := $(call intermediates-dir-for,PACKAGING,vndk-snapshot)
74vndk_snapshot_out := $(vndk_snapshot_top)/vndk-snapshot
75vndk_snapshot_configs_out := $(vndk_snapshot_top)/configs
76
77#######################################
78# vndkcore.libraries.txt
79vndkcore.libraries.txt := $(vndk_snapshot_configs_out)/vndkcore.libraries.txt
80$(vndkcore.libraries.txt): PRIVATE_LIBS := $(vndk_core_libs)
81$(vndkcore.libraries.txt):
82	@echo 'Generating: $@'
83	@rm -f $@
84	@mkdir -p $(dir $@)
85	$(hide) echo -n > $@
86	$(hide) $(foreach lib,$(PRIVATE_LIBS),echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
87
88
89#######################################
90# vndkprivate.libraries.txt
91vndkprivate.libraries.txt := $(vndk_snapshot_configs_out)/vndkprivate.libraries.txt
92$(vndkprivate.libraries.txt): PRIVATE_LIBS := $(vndk_private_libs)
93$(vndkprivate.libraries.txt):
94	@echo 'Generating: $@'
95	@rm -f $@
96	@mkdir -p $(dir $@)
97	$(hide) echo -n > $@
98	$(hide) $(foreach lib,$(PRIVATE_LIBS),echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
99
100
101#######################################
102# module_paths.txt
103module_paths.txt := $(vndk_snapshot_configs_out)/module_paths.txt
104$(module_paths.txt): PRIVATE_LIBS := $(vndk_snapshot_libs)
105$(module_paths.txt):
106	@echo 'Generating: $@'
107	@rm -f $@
108	@mkdir -p $(dir $@)
109	$(hide) echo -n > $@
110	$(hide) $(foreach lib,$(PRIVATE_LIBS),echo $(patsubst %.vendor,%,$(lib)).so $(ALL_MODULES.$(lib).PATH) >> $@;)
111
112
113vndk_snapshot_configs := \
114  $(vndkcore.libraries.txt) \
115  $(vndkprivate.libraries.txt) \
116  $(module_paths.txt)
117
118#######################################
119# vndk_snapshot_zip
120vndk_snapshot_variant := $(vndk_snapshot_out)/$(TARGET_ARCH)
121binder :=
122ifneq ($(TARGET_IS_64_BIT), true)
123  ifneq ($(TARGET_USES_64_BIT_BINDER), true)
124    binder := binder32
125  endif
126endif
127vndk_lib_dir := $(subst $(space),/,$(strip $(vndk_snapshot_variant) $(binder) arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT)))
128vndk_lib_dir_2nd := $(subst $(space),/,$(strip $(vndk_snapshot_variant) $(binder) arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT)))
129vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_PRODUCT).zip
130
131$(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out)
132
133deps := $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(subst .vendor,,$(lib)).so))
134$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_lib_dir)/shared/vndk-core
135$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := $(deps)
136$(vndk_snapshot_zip): $(foreach d,$(deps),$(call word-colon,1,$(d)))
137deps :=
138
139deps := $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(subst .vendor,,$(lib)).so))
140$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_lib_dir)/shared/vndk-sp
141$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := $(deps)
142$(vndk_snapshot_zip): $(foreach d,$(deps),$(call word-colon,1,$(d)))
143deps :=
144
145deps := $(call paths-of-intermediates,$(foreach txt,$(vndk_prebuilt_txts), \
146          $(txt):$(patsubst %.txt,%.$(PLATFORM_VNDK_VERSION).txt,$(txt)))) \
147        $(foreach config,$(vndk_snapshot_configs),$(config):$(notdir $(config)))
148$(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_variant)/configs
149$(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := $(deps)
150$(vndk_snapshot_zip): $(foreach d,$(deps),$(call word-colon,1,$(d)))
151deps :=
152
153notices := $(call paths-of-notice-files,$(vndk_core_libs) $(vndk_sp_libs))
154$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_variant)/NOTICE_FILES
155$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := $(notices)
156$(vndk_snapshot_zip): $(foreach n,$(notices),$(call word-colon,1,$(n)))
157notices :=
158
159ifdef TARGET_2ND_ARCH
160deps := $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(subst .vendor,,$(lib)).so),true)
161$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-core
162$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := $(deps)
163$(vndk_snapshot_zip): $(foreach d,$(deps),$(call word-colon,1,$(d)))
164deps :=
165
166deps := $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(subst .vendor,,$(lib)).so),true)
167$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-sp
168$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := $(deps)
169$(vndk_snapshot_zip): $(foreach d,$(deps),$(call word-colon,1,$(d)))
170deps :=
171endif
172
173# Args
174#   $(1): destination directory
175#   $(2): list of files (src:dest) to copy
176$(vndk_snapshot_zip): private-copy-intermediates = \
177  $(if $(2),$(strip \
178    @mkdir -p $(1) && \
179    $(foreach file,$(2), \
180      cp $(call word-colon,1,$(file)) $(call append-path,$(1),$(call word-colon,2,$(file))) && \
181    ) \
182    true \
183  ))
184
185
186$(vndk_snapshot_zip): $(SOONG_ZIP)
187	@echo 'Generating VNDK snapshot: $@'
188	@rm -f $@
189	@rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT)
190	@mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT)
191	$(call private-copy-intermediates, \
192		$(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES))
193	$(call private-copy-intermediates, \
194		$(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES))
195	$(call private-copy-intermediates, \
196		$(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES))
197	$(call private-copy-intermediates, \
198		$(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES))
199ifdef TARGET_2ND_ARCH
200	$(call private-copy-intermediates, \
201		$(PRIVATE_VNDK_CORE_OUT_2ND),$(PRIVATE_VNDK_CORE_INTERMEDIATES_2ND))
202	$(call private-copy-intermediates, \
203		$(PRIVATE_VNDK_SP_OUT_2ND),$(PRIVATE_VNDK_SP_INTERMEDIATES_2ND))
204endif
205	$(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_VNDK_SNAPSHOT_OUT) -D $(PRIVATE_VNDK_SNAPSHOT_OUT)
206
207.PHONY: vndk
208vndk: $(vndk_snapshot_zip)
209
210$(call dist-for-goals, vndk, $(vndk_snapshot_zip))
211
212# clear global vars
213clang-ubsan-vndk-core :=
214paths-of-intermediates :=
215paths-of-notice-files :=
216vndk_core_libs :=
217vndk_sp_libs :=
218vndk_snapshot_libs :=
219vndk_prebuilt_txts :=
220vndk_snapshot_configs :=
221vndk_snapshot_top :=
222vndk_snapshot_out :=
223vndk_snapshot_configs_out :=
224vndk_snapshot_variant :=
225binder :=
226vndk_lib_dir :=
227vndk_lib_dir_2nd :=
228
229else # BOARD_VNDK_RUNTIME_DISABLE is set to 'true'
230error_msg := "CANNOT generate VNDK snapshot. BOARD_VNDK_RUNTIME_DISABLE must not be set to 'true'."
231endif # BOARD_VNDK_RUNTIME_DISABLE
232
233else # PLATFORM_VNDK_VERSION is NOT set
234error_msg := "CANNOT generate VNDK snapshot. PLATFORM_VNDK_VERSION must be set."
235endif # PLATFORM_VNDK_VERSION
236
237else # BOARD_VNDK_VERSION is NOT set to 'current'
238error_msg := "CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'."
239endif # BOARD_VNDK_VERSION
240
241ifneq (,$(error_msg))
242
243.PHONY: vndk
244vndk:
245	$(call echo-error,$(current_makefile),$(error_msg))
246	exit 1
247
248endif
249