blob: 1bbd3b09c47c6bba4ca018c824733f574e53629e [file] [log] [blame]
Jae Shine6b7c842017-10-20 17:46:46 +09001# 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# Returns arch-specific libclang_rt.ubsan* library name.
21# Because VNDK_CORE_LIBRARIES includes all arch variants for libclang_rt.ubsan*
22# libs, the arch-specific libs are selected separately.
23#
24# Args:
25# $(1): if not empty, evaluates for TARGET_2ND_ARCH
26define clang-ubsan-vndk-core
Jae Shin4736dc12017-11-22 19:25:36 +090027$(strip \
28 $(eval prefix := $(if $(1),2ND_,)) \
29 $(addsuffix .vendor,$($(addprefix $(prefix),UBSAN_RUNTIME_LIBRARY))) \
30)
Jae Shine6b7c842017-10-20 17:46:46 +090031endef
32
Jae Shin4736dc12017-11-22 19:25:36 +090033# Returns list of file paths of the intermediate objs
34#
Jae Shine6b7c842017-10-20 17:46:46 +090035# Args:
Jae Shin4736dc12017-11-22 19:25:36 +090036# $(1): list of obj names (e.g., libfoo.vendor, ld.config.txt, ...)
37# $(2): target class (e.g., SHARED_LIBRARIES, STATIC_LIBRARIES, ETC)
38# $(3): if not empty, evaluates for TARGET_2ND_ARCH
Jae Shine6b7c842017-10-20 17:46:46 +090039define paths-of-intermediates
Jae Shin4736dc12017-11-22 19:25:36 +090040$(strip \
41 $(foreach obj,$(1), \
42 $(eval file_name := $(if $(filter SHARED_LIBRARIES,$(2)),$(patsubst %.so,%,$(obj)).so,$(obj))) \
43 $(eval dir := $(call intermediates-dir-for,$(2),$(obj),,,$(3))) \
44 $(call append-path,$(dir),$(file_name)) \
45 ) \
46)
Jae Shine6b7c842017-10-20 17:46:46 +090047endef
48
Jae Shin410a1af2017-12-15 19:35:16 +090049# Returns paths of notice files under $(TARGET_OUT_NOTICE_FILES)
50#
51# Args:
52# $(1): list of lib names (e.g., libfoo.vendor)
53# $(2): vndk lib type, one of 'vndk' or 'vndk-sp'
54define paths-of-notice-files
55$(strip \
56 $(eval lib_dir := lib$(if $(TARGET_IS_64BIT),64,)) \
57 $(eval vndk_dir := $(2)-$(PLATFORM_VNDK_VERSION)) \
58 $(foreach lib,$(1), \
59 $(eval notice_file_name := $(patsubst %.vendor,%.so.txt,$(lib))) \
60 $(TARGET_OUT_NOTICE_FILES)/src/system/$(lib_dir)/$(vndk_dir)/$(notice_file_name) \
61 ) \
62)
63endef
64
Jae Shine6b7c842017-10-20 17:46:46 +090065# If in the future libclang_rt.ubsan* is removed from the VNDK-core list,
66# need to update the related logic in this file.
67ifeq (,$(filter libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES)))
Jae Shin4736dc12017-11-22 19:25:36 +090068 $(warning libclang_rt.ubsan* is no longer a VNDK-core library. Please update this file.)
69 vndk_core_libs := $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES))
70else
71 vndk_core_libs := $(addsuffix .vendor,$(filter-out libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES)))
72
73 # for TARGET_ARCH
74 vndk_core_libs += $(call clang-ubsan-vndk-core)
75
76 # TODO(b/69834489): Package additional arch variants
77 # ifdef TARGET_2ND_ARCH
78 # vndk_core_libs += $(call clang-ubsan-vndk-core,true)
79 # endif
Jae Shine6b7c842017-10-20 17:46:46 +090080endif
81
Jae Shin4736dc12017-11-22 19:25:36 +090082vndk_sp_libs := $(addsuffix .vendor,$(VNDK_SAMEPROCESS_LIBRARIES))
83vndk_private_libs := $(addsuffix .vendor,$(VNDK_PRIVATE_LIBRARIES))
Jae Shine6b7c842017-10-20 17:46:46 +090084
Jae Shin4736dc12017-11-22 19:25:36 +090085vndk_snapshot_libs := \
86 $(vndk_core_libs) \
87 $(vndk_sp_libs)
Jae Shine6b7c842017-10-20 17:46:46 +090088
Jae Shin4736dc12017-11-22 19:25:36 +090089vndk_prebuilt_txts := \
90 ld.config.txt \
91 vndksp.libraries.txt \
92 llndk.libraries.txt
93
94vndk_snapshot_top := $(call intermediates-dir-for,PACKAGING,vndk-snapshot)
95vndk_snapshot_out := $(vndk_snapshot_top)/vndk-snapshot
96vndk_snapshot_configs_out := $(vndk_snapshot_top)/configs
97
98#######################################
99# vndkcore.libraries.txt
100vndkcore.libraries.txt := $(vndk_snapshot_configs_out)/vndkcore.libraries.txt
101$(vndkcore.libraries.txt): $(vndk_core_libs)
102 @echo 'Generating: $@'
103 @rm -f $@
104 @mkdir -p $(dir $@)
105 $(hide) echo -n > $@
106 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
107
108
109#######################################
110# vndkprivate.libraries.txt
111vndkprivate.libraries.txt := $(vndk_snapshot_configs_out)/vndkprivate.libraries.txt
112$(vndkprivate.libraries.txt): $(vndk_private_libs)
113 @echo 'Generating: $@'
114 @rm -f $@
115 @mkdir -p $(dir $@)
116 $(hide) echo -n > $@
117 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
118
119
Jae Shin410a1af2017-12-15 19:35:16 +0900120#######################################
121# module_paths.txt
122module_paths.txt := $(vndk_snapshot_configs_out)/module_paths.txt
123$(module_paths.txt): $(vndk_snapshot_libs)
124 @echo 'Generating: $@'
125 @rm -f $@
126 @mkdir -p $(dir $@)
127 $(hide) echo -n > $@
128 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so $(ALL_MODULES.$(lib).PATH) >> $@;)
129
130
Jae Shin4736dc12017-11-22 19:25:36 +0900131vndk_snapshot_configs := \
132 $(vndkcore.libraries.txt) \
Jae Shin410a1af2017-12-15 19:35:16 +0900133 $(vndkprivate.libraries.txt) \
134 $(module_paths.txt)
Jae Shin4736dc12017-11-22 19:25:36 +0900135
136#######################################
137# vndk_snapshot_zip
138vndk_snapshot_arch := $(vndk_snapshot_out)/arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT)
Jae Shine6b7c842017-10-20 17:46:46 +0900139vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_ARCH).zip
Jae Shin4736dc12017-11-22 19:25:36 +0900140
Jae Shine6b7c842017-10-20 17:46:46 +0900141$(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out)
142
Jae Shin4736dc12017-11-22 19:25:36 +0900143$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_snapshot_arch)/shared/vndk-core
144$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \
145 $(call paths-of-intermediates,$(vndk_core_libs),SHARED_LIBRARIES)
Jae Shine6b7c842017-10-20 17:46:46 +0900146
Jae Shin4736dc12017-11-22 19:25:36 +0900147$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_snapshot_arch)/shared/vndk-sp
148$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \
149 $(call paths-of-intermediates,$(vndk_sp_libs),SHARED_LIBRARIES)
150
151$(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_arch)/configs
152$(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \
153 $(call paths-of-intermediates,$(vndk_prebuilt_txts),ETC) \
154 $(vndk_snapshot_configs)
155
Jae Shin410a1af2017-12-15 19:35:16 +0900156$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_arch)/NOTICE_FILES
157$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := \
158 $(call paths-of-notice-files,$(vndk_core_libs),vndk) \
159 $(call paths-of-notice-files,$(vndk_sp_libs),vndk-sp)
160
Jae Shin4736dc12017-11-22 19:25:36 +0900161# TODO(b/69834489): Package additional arch variants
162# ifdef TARGET_2ND_ARCH
163# vndk_snapshot_arch_2ND := $(vndk_snapshot_out)/arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT)
164# $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-core
165# $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \
166# $(call paths-of-intermediates,$(vndk_core_libs),SHARED_LIBRARIES,true)
167# $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-sp
168# $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \
169# $(call paths-of-intermediates,$(vndk_sp_libs),SHARED_LIBRARIES,true)
170# endif
Jae Shine6b7c842017-10-20 17:46:46 +0900171
172# Args
173# $(1): destination directory
Jae Shin4736dc12017-11-22 19:25:36 +0900174# $(2): list of files to copy
Jae Shine6b7c842017-10-20 17:46:46 +0900175$(vndk_snapshot_zip): private-copy-vndk-intermediates = \
Jae Shin4736dc12017-11-22 19:25:36 +0900176 $(if $(2),$(strip \
177 @mkdir -p $(1); \
178 $(foreach file,$(2), \
179 if [ -e $(file) ]; then \
180 cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \
181 fi; \
182 ) \
183 ))
184
185vndk_snapshot_dependencies := \
186 $(vndk_snapshot_libs) \
187 $(vndk_prebuilt_txts) \
188 $(vndk_snapshot_configs)
Jae Shine6b7c842017-10-20 17:46:46 +0900189
190$(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP)
191 @echo 'Generating VNDK snapshot: $@'
192 @rm -f $@
193 @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT)
194 @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT)
195 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900196 $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900197 $(call private-copy-vndk-intermediates, \
Jae Shinc13c0ea2017-12-04 13:16:21 +0900198 $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900199 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900200 $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES))
Jae Shin410a1af2017-12-15 19:35:16 +0900201 $(call private-copy-vndk-intermediates, \
202 $(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES))
Jae Shin4736dc12017-11-22 19:25:36 +0900203# TODO(b/69834489): Package additional arch variants
204# ifdef TARGET_2ND_ARCH
205# $(call private-copy-vndk-intermediates, \
206# $(PRIVATE_VNDK_CORE_OUT_2ND),$(PRIVATE_VNDK_CORE_INTERMEDIATES_2ND))
207# $(call private-copy-vndk-intermediates, \
208# $(PRIVATE_VNDK_SP_OUT_2ND),$(PRIVATE_VNDK_SP_INTERMEDIATES_2ND))
209# endif
Jae Shinc13c0ea2017-12-04 13:16:21 +0900210 $(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_VNDK_SNAPSHOT_OUT) -D $(PRIVATE_VNDK_SNAPSHOT_OUT)
Jae Shine6b7c842017-10-20 17:46:46 +0900211
212.PHONY: vndk
213vndk: $(vndk_snapshot_zip)
214
215$(call dist-for-goals, vndk, $(vndk_snapshot_zip))
216
Jae Shin4736dc12017-11-22 19:25:36 +0900217# clear global vars
218clang-ubsan-vndk-core :=
219paths-of-intermediates :=
Jae Shin410a1af2017-12-15 19:35:16 +0900220paths-of-notice-files :=
Jae Shin4736dc12017-11-22 19:25:36 +0900221vndk_core_libs :=
222vndk_sp_libs :=
223vndk_snapshot_libs :=
224vndk_prebuilt_txts :=
225vndk_snapshot_configs :=
226vndk_snapshot_top :=
227vndk_snapshot_out :=
228vndk_snapshot_configs_out :=
229vndk_snapshot_arch :=
230vndk_snapshot_dependencies :=
231# TODO(b/69834489): Package additional arch variants
232# ifdef TARGET_2ND_ARCH
233# vndk_snapshot_arch_2ND :=
234# endif
235
Jae Shine6b7c842017-10-20 17:46:46 +0900236else # BOARD_VNDK_VERSION is NOT set to 'current'
237
238.PHONY: vndk
239vndk:
240 $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'.)
241 exit 1
242
243endif # BOARD_VNDK_VERSION