blob: fd7a69645051ac4f56158b1206f8c51c1349f3a6 [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
Jae Shin0b1792e2017-12-21 19:04:13 +090020# PLATFORM_VNDK_VERSION must be set.
21ifneq (,$(PLATFORM_VNDK_VERSION))
22
Jae Shine6b7c842017-10-20 17:46:46 +090023# Returns arch-specific libclang_rt.ubsan* library name.
24# Because VNDK_CORE_LIBRARIES includes all arch variants for libclang_rt.ubsan*
25# libs, the arch-specific libs are selected separately.
26#
27# Args:
28# $(1): if not empty, evaluates for TARGET_2ND_ARCH
29define clang-ubsan-vndk-core
Jae Shin4736dc12017-11-22 19:25:36 +090030$(strip \
31 $(eval prefix := $(if $(1),2ND_,)) \
32 $(addsuffix .vendor,$($(addprefix $(prefix),UBSAN_RUNTIME_LIBRARY))) \
33)
Jae Shine6b7c842017-10-20 17:46:46 +090034endef
35
Jae Shin4736dc12017-11-22 19:25:36 +090036# Returns list of file paths of the intermediate objs
37#
Jae Shine6b7c842017-10-20 17:46:46 +090038# Args:
Jae Shin4736dc12017-11-22 19:25:36 +090039# $(1): list of obj names (e.g., libfoo.vendor, ld.config.txt, ...)
40# $(2): target class (e.g., SHARED_LIBRARIES, STATIC_LIBRARIES, ETC)
41# $(3): if not empty, evaluates for TARGET_2ND_ARCH
Jae Shine6b7c842017-10-20 17:46:46 +090042define paths-of-intermediates
Jae Shin4736dc12017-11-22 19:25:36 +090043$(strip \
44 $(foreach obj,$(1), \
45 $(eval file_name := $(if $(filter SHARED_LIBRARIES,$(2)),$(patsubst %.so,%,$(obj)).so,$(obj))) \
46 $(eval dir := $(call intermediates-dir-for,$(2),$(obj),,,$(3))) \
47 $(call append-path,$(dir),$(file_name)) \
48 ) \
49)
Jae Shine6b7c842017-10-20 17:46:46 +090050endef
51
Jae Shin410a1af2017-12-15 19:35:16 +090052# Returns paths of notice files under $(TARGET_OUT_NOTICE_FILES)
53#
54# Args:
55# $(1): list of lib names (e.g., libfoo.vendor)
56# $(2): vndk lib type, one of 'vndk' or 'vndk-sp'
57define paths-of-notice-files
58$(strip \
59 $(eval lib_dir := lib$(if $(TARGET_IS_64BIT),64,)) \
60 $(eval vndk_dir := $(2)-$(PLATFORM_VNDK_VERSION)) \
61 $(foreach lib,$(1), \
62 $(eval notice_file_name := $(patsubst %.vendor,%.so.txt,$(lib))) \
63 $(TARGET_OUT_NOTICE_FILES)/src/system/$(lib_dir)/$(vndk_dir)/$(notice_file_name) \
64 ) \
65)
66endef
67
Jae Shine6b7c842017-10-20 17:46:46 +090068# If in the future libclang_rt.ubsan* is removed from the VNDK-core list,
69# need to update the related logic in this file.
70ifeq (,$(filter libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES)))
Jae Shin4736dc12017-11-22 19:25:36 +090071 $(warning libclang_rt.ubsan* is no longer a VNDK-core library. Please update this file.)
72 vndk_core_libs := $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES))
73else
74 vndk_core_libs := $(addsuffix .vendor,$(filter-out libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES)))
75
76 # for TARGET_ARCH
77 vndk_core_libs += $(call clang-ubsan-vndk-core)
78
79 # TODO(b/69834489): Package additional arch variants
80 # ifdef TARGET_2ND_ARCH
81 # vndk_core_libs += $(call clang-ubsan-vndk-core,true)
82 # endif
Jae Shine6b7c842017-10-20 17:46:46 +090083endif
84
Jae Shin4736dc12017-11-22 19:25:36 +090085vndk_sp_libs := $(addsuffix .vendor,$(VNDK_SAMEPROCESS_LIBRARIES))
86vndk_private_libs := $(addsuffix .vendor,$(VNDK_PRIVATE_LIBRARIES))
Jae Shine6b7c842017-10-20 17:46:46 +090087
Jae Shin4736dc12017-11-22 19:25:36 +090088vndk_snapshot_libs := \
89 $(vndk_core_libs) \
90 $(vndk_sp_libs)
Jae Shine6b7c842017-10-20 17:46:46 +090091
Jae Shin4736dc12017-11-22 19:25:36 +090092vndk_prebuilt_txts := \
93 ld.config.txt \
94 vndksp.libraries.txt \
95 llndk.libraries.txt
96
97vndk_snapshot_top := $(call intermediates-dir-for,PACKAGING,vndk-snapshot)
98vndk_snapshot_out := $(vndk_snapshot_top)/vndk-snapshot
99vndk_snapshot_configs_out := $(vndk_snapshot_top)/configs
100
101#######################################
102# vndkcore.libraries.txt
103vndkcore.libraries.txt := $(vndk_snapshot_configs_out)/vndkcore.libraries.txt
104$(vndkcore.libraries.txt): $(vndk_core_libs)
105 @echo 'Generating: $@'
106 @rm -f $@
107 @mkdir -p $(dir $@)
108 $(hide) echo -n > $@
109 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
110
111
112#######################################
113# vndkprivate.libraries.txt
114vndkprivate.libraries.txt := $(vndk_snapshot_configs_out)/vndkprivate.libraries.txt
115$(vndkprivate.libraries.txt): $(vndk_private_libs)
116 @echo 'Generating: $@'
117 @rm -f $@
118 @mkdir -p $(dir $@)
119 $(hide) echo -n > $@
120 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
121
122
Jae Shin410a1af2017-12-15 19:35:16 +0900123#######################################
124# module_paths.txt
125module_paths.txt := $(vndk_snapshot_configs_out)/module_paths.txt
126$(module_paths.txt): $(vndk_snapshot_libs)
127 @echo 'Generating: $@'
128 @rm -f $@
129 @mkdir -p $(dir $@)
130 $(hide) echo -n > $@
131 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so $(ALL_MODULES.$(lib).PATH) >> $@;)
132
133
Jae Shin4736dc12017-11-22 19:25:36 +0900134vndk_snapshot_configs := \
135 $(vndkcore.libraries.txt) \
Jae Shin410a1af2017-12-15 19:35:16 +0900136 $(vndkprivate.libraries.txt) \
137 $(module_paths.txt)
Jae Shin4736dc12017-11-22 19:25:36 +0900138
139#######################################
140# vndk_snapshot_zip
141vndk_snapshot_arch := $(vndk_snapshot_out)/arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT)
Jae Shine6b7c842017-10-20 17:46:46 +0900142vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_ARCH).zip
Jae Shin4736dc12017-11-22 19:25:36 +0900143
Jae Shine6b7c842017-10-20 17:46:46 +0900144$(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out)
145
Jae Shin4736dc12017-11-22 19:25:36 +0900146$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_snapshot_arch)/shared/vndk-core
147$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \
148 $(call paths-of-intermediates,$(vndk_core_libs),SHARED_LIBRARIES)
Jae Shine6b7c842017-10-20 17:46:46 +0900149
Jae Shin4736dc12017-11-22 19:25:36 +0900150$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_snapshot_arch)/shared/vndk-sp
151$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \
152 $(call paths-of-intermediates,$(vndk_sp_libs),SHARED_LIBRARIES)
153
154$(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_arch)/configs
155$(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \
156 $(call paths-of-intermediates,$(vndk_prebuilt_txts),ETC) \
157 $(vndk_snapshot_configs)
158
Jae Shin410a1af2017-12-15 19:35:16 +0900159$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_arch)/NOTICE_FILES
160$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := \
161 $(call paths-of-notice-files,$(vndk_core_libs),vndk) \
162 $(call paths-of-notice-files,$(vndk_sp_libs),vndk-sp)
163
Jae Shin4736dc12017-11-22 19:25:36 +0900164# TODO(b/69834489): Package additional arch variants
165# ifdef TARGET_2ND_ARCH
166# vndk_snapshot_arch_2ND := $(vndk_snapshot_out)/arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT)
167# $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-core
168# $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \
169# $(call paths-of-intermediates,$(vndk_core_libs),SHARED_LIBRARIES,true)
170# $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-sp
171# $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \
172# $(call paths-of-intermediates,$(vndk_sp_libs),SHARED_LIBRARIES,true)
173# endif
Jae Shine6b7c842017-10-20 17:46:46 +0900174
175# Args
176# $(1): destination directory
Jae Shin4736dc12017-11-22 19:25:36 +0900177# $(2): list of files to copy
Jae Shine6b7c842017-10-20 17:46:46 +0900178$(vndk_snapshot_zip): private-copy-vndk-intermediates = \
Jae Shin4736dc12017-11-22 19:25:36 +0900179 $(if $(2),$(strip \
180 @mkdir -p $(1); \
181 $(foreach file,$(2), \
182 if [ -e $(file) ]; then \
183 cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \
184 fi; \
185 ) \
186 ))
187
188vndk_snapshot_dependencies := \
189 $(vndk_snapshot_libs) \
190 $(vndk_prebuilt_txts) \
191 $(vndk_snapshot_configs)
Jae Shine6b7c842017-10-20 17:46:46 +0900192
193$(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP)
194 @echo 'Generating VNDK snapshot: $@'
195 @rm -f $@
196 @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT)
197 @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT)
198 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900199 $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900200 $(call private-copy-vndk-intermediates, \
Jae Shinc13c0ea2017-12-04 13:16:21 +0900201 $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900202 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900203 $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES))
Jae Shin410a1af2017-12-15 19:35:16 +0900204 $(call private-copy-vndk-intermediates, \
205 $(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES))
Jae Shin4736dc12017-11-22 19:25:36 +0900206# TODO(b/69834489): Package additional arch variants
207# ifdef TARGET_2ND_ARCH
208# $(call private-copy-vndk-intermediates, \
209# $(PRIVATE_VNDK_CORE_OUT_2ND),$(PRIVATE_VNDK_CORE_INTERMEDIATES_2ND))
210# $(call private-copy-vndk-intermediates, \
211# $(PRIVATE_VNDK_SP_OUT_2ND),$(PRIVATE_VNDK_SP_INTERMEDIATES_2ND))
212# endif
Jae Shinc13c0ea2017-12-04 13:16:21 +0900213 $(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_VNDK_SNAPSHOT_OUT) -D $(PRIVATE_VNDK_SNAPSHOT_OUT)
Jae Shine6b7c842017-10-20 17:46:46 +0900214
215.PHONY: vndk
216vndk: $(vndk_snapshot_zip)
217
218$(call dist-for-goals, vndk, $(vndk_snapshot_zip))
219
Jae Shin4736dc12017-11-22 19:25:36 +0900220# clear global vars
221clang-ubsan-vndk-core :=
222paths-of-intermediates :=
Jae Shin410a1af2017-12-15 19:35:16 +0900223paths-of-notice-files :=
Jae Shin4736dc12017-11-22 19:25:36 +0900224vndk_core_libs :=
225vndk_sp_libs :=
226vndk_snapshot_libs :=
227vndk_prebuilt_txts :=
228vndk_snapshot_configs :=
229vndk_snapshot_top :=
230vndk_snapshot_out :=
231vndk_snapshot_configs_out :=
232vndk_snapshot_arch :=
233vndk_snapshot_dependencies :=
234# TODO(b/69834489): Package additional arch variants
235# ifdef TARGET_2ND_ARCH
236# vndk_snapshot_arch_2ND :=
237# endif
238
Jae Shin0b1792e2017-12-21 19:04:13 +0900239else # PLATFORM_VNDK_VERSION is NOT set
240
241.PHONY: vndk
242vndk:
243 $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. PLATFORM_VNDK_VERSION must be set.)
244 exit 1
245
246endif # PLATFORM_VNDK_VERSION
247
Jae Shine6b7c842017-10-20 17:46:46 +0900248else # BOARD_VNDK_VERSION is NOT set to 'current'
249
250.PHONY: vndk
251vndk:
252 $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'.)
253 exit 1
254
255endif # BOARD_VNDK_VERSION