blob: 125ef7ea848c4f0b12300e760a5eb2c1729250b5 [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 Shin77c07dd2017-12-22 11:24:00 +090039# $(1): list of module and filename pairs (e.g., ld.config.txt:ld.config.27.txt ...)
Jae Shin4736dc12017-11-22 19:25:36 +090040# $(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 \
Jae Shin77c07dd2017-12-22 11:24:00 +090044 $(foreach pair,$(1), \
45 $(eval split_pair := $(subst :,$(space),$(pair))) \
46 $(eval module := $(word 1,$(split_pair))) \
47 $(eval filename := $(word 2,$(split_pair))) \
48 $(eval dir := $(call intermediates-dir-for,$(2),$(module),,,$(3))) \
49 $(call append-path,$(dir),$(filename)) \
Jae Shin4736dc12017-11-22 19:25:36 +090050 ) \
51)
Jae Shine6b7c842017-10-20 17:46:46 +090052endef
53
Jae Shin410a1af2017-12-15 19:35:16 +090054# Returns paths of notice files under $(TARGET_OUT_NOTICE_FILES)
55#
56# Args:
57# $(1): list of lib names (e.g., libfoo.vendor)
58# $(2): vndk lib type, one of 'vndk' or 'vndk-sp'
59define paths-of-notice-files
60$(strip \
61 $(eval lib_dir := lib$(if $(TARGET_IS_64BIT),64,)) \
62 $(eval vndk_dir := $(2)-$(PLATFORM_VNDK_VERSION)) \
63 $(foreach lib,$(1), \
64 $(eval notice_file_name := $(patsubst %.vendor,%.so.txt,$(lib))) \
65 $(TARGET_OUT_NOTICE_FILES)/src/system/$(lib_dir)/$(vndk_dir)/$(notice_file_name) \
66 ) \
67)
68endef
69
Jae Shine6b7c842017-10-20 17:46:46 +090070# If in the future libclang_rt.ubsan* is removed from the VNDK-core list,
71# need to update the related logic in this file.
72ifeq (,$(filter libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES)))
Jae Shin4736dc12017-11-22 19:25:36 +090073 $(warning libclang_rt.ubsan* is no longer a VNDK-core library. Please update this file.)
74 vndk_core_libs := $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES))
75else
76 vndk_core_libs := $(addsuffix .vendor,$(filter-out libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES)))
77
Jae Shin4736dc12017-11-22 19:25:36 +090078 vndk_core_libs += $(call clang-ubsan-vndk-core)
Jae Shin893fca62017-12-28 16:00:10 +090079 ifdef TARGET_2ND_ARCH
80 vndk_core_libs += $(call clang-ubsan-vndk-core,true)
81 endif
Jae Shine6b7c842017-10-20 17:46:46 +090082endif
83
Jae Shin4736dc12017-11-22 19:25:36 +090084vndk_sp_libs := $(addsuffix .vendor,$(VNDK_SAMEPROCESS_LIBRARIES))
85vndk_private_libs := $(addsuffix .vendor,$(VNDK_PRIVATE_LIBRARIES))
Jae Shine6b7c842017-10-20 17:46:46 +090086
Jae Shin4736dc12017-11-22 19:25:36 +090087vndk_snapshot_libs := \
88 $(vndk_core_libs) \
89 $(vndk_sp_libs)
Jae Shine6b7c842017-10-20 17:46:46 +090090
Jae Shin4736dc12017-11-22 19:25:36 +090091vndk_prebuilt_txts := \
92 ld.config.txt \
93 vndksp.libraries.txt \
94 llndk.libraries.txt
95
96vndk_snapshot_top := $(call intermediates-dir-for,PACKAGING,vndk-snapshot)
97vndk_snapshot_out := $(vndk_snapshot_top)/vndk-snapshot
98vndk_snapshot_configs_out := $(vndk_snapshot_top)/configs
99
100#######################################
101# vndkcore.libraries.txt
102vndkcore.libraries.txt := $(vndk_snapshot_configs_out)/vndkcore.libraries.txt
103$(vndkcore.libraries.txt): $(vndk_core_libs)
104 @echo 'Generating: $@'
105 @rm -f $@
106 @mkdir -p $(dir $@)
107 $(hide) echo -n > $@
108 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
109
110
111#######################################
112# vndkprivate.libraries.txt
113vndkprivate.libraries.txt := $(vndk_snapshot_configs_out)/vndkprivate.libraries.txt
114$(vndkprivate.libraries.txt): $(vndk_private_libs)
115 @echo 'Generating: $@'
116 @rm -f $@
117 @mkdir -p $(dir $@)
118 $(hide) echo -n > $@
119 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
120
121
Jae Shin410a1af2017-12-15 19:35:16 +0900122#######################################
123# module_paths.txt
124module_paths.txt := $(vndk_snapshot_configs_out)/module_paths.txt
125$(module_paths.txt): $(vndk_snapshot_libs)
126 @echo 'Generating: $@'
127 @rm -f $@
128 @mkdir -p $(dir $@)
129 $(hide) echo -n > $@
130 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so $(ALL_MODULES.$(lib).PATH) >> $@;)
131
132
Jae Shin4736dc12017-11-22 19:25:36 +0900133vndk_snapshot_configs := \
134 $(vndkcore.libraries.txt) \
Jae Shin410a1af2017-12-15 19:35:16 +0900135 $(vndkprivate.libraries.txt) \
136 $(module_paths.txt)
Jae Shin4736dc12017-11-22 19:25:36 +0900137
138#######################################
139# vndk_snapshot_zip
Jae Shin893fca62017-12-28 16:00:10 +0900140vndk_snapshot_variant := $(vndk_snapshot_out)/$(TARGET_ARCH)
141vndk_lib_dir := $(vndk_snapshot_variant)/arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT)
142vndk_lib_dir_2nd := $(vndk_snapshot_variant)/arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT)
Jae Shine6b7c842017-10-20 17:46:46 +0900143vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_ARCH).zip
Jae Shin4736dc12017-11-22 19:25:36 +0900144
Jae Shine6b7c842017-10-20 17:46:46 +0900145$(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out)
146
Jae Shin893fca62017-12-28 16:00:10 +0900147$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_lib_dir)/shared/vndk-core
Jae Shin4736dc12017-11-22 19:25:36 +0900148$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900149 $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES)
Jae Shine6b7c842017-10-20 17:46:46 +0900150
Jae Shin893fca62017-12-28 16:00:10 +0900151$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_lib_dir)/shared/vndk-sp
Jae Shin4736dc12017-11-22 19:25:36 +0900152$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900153 $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES)
Jae Shin4736dc12017-11-22 19:25:36 +0900154
Jae Shin893fca62017-12-28 16:00:10 +0900155$(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_variant)/configs
Jae Shin4736dc12017-11-22 19:25:36 +0900156$(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900157 $(call paths-of-intermediates,$(foreach txt,$(vndk_prebuilt_txts), \
158 $(txt):$(patsubst %.txt,%.$(PLATFORM_VNDK_VERSION).txt,$(txt))),ETC) \
Jae Shin4736dc12017-11-22 19:25:36 +0900159 $(vndk_snapshot_configs)
160
Jae Shin893fca62017-12-28 16:00:10 +0900161$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_variant)/NOTICE_FILES
Jae Shin410a1af2017-12-15 19:35:16 +0900162$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := \
163 $(call paths-of-notice-files,$(vndk_core_libs),vndk) \
164 $(call paths-of-notice-files,$(vndk_sp_libs),vndk-sp)
165
Jae Shin893fca62017-12-28 16:00:10 +0900166ifdef TARGET_2ND_ARCH
167$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-core
168$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \
169 $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true)
170
171$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-sp
172$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \
173 $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true)
174endif
Jae Shine6b7c842017-10-20 17:46:46 +0900175
176# Args
177# $(1): destination directory
Jae Shin4736dc12017-11-22 19:25:36 +0900178# $(2): list of files to copy
Jae Shine6b7c842017-10-20 17:46:46 +0900179$(vndk_snapshot_zip): private-copy-vndk-intermediates = \
Jae Shin4736dc12017-11-22 19:25:36 +0900180 $(if $(2),$(strip \
181 @mkdir -p $(1); \
182 $(foreach file,$(2), \
183 if [ -e $(file) ]; then \
184 cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \
185 fi; \
186 ) \
187 ))
188
189vndk_snapshot_dependencies := \
190 $(vndk_snapshot_libs) \
191 $(vndk_prebuilt_txts) \
192 $(vndk_snapshot_configs)
Jae Shine6b7c842017-10-20 17:46:46 +0900193
194$(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP)
195 @echo 'Generating VNDK snapshot: $@'
196 @rm -f $@
197 @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT)
198 @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT)
199 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900200 $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900201 $(call private-copy-vndk-intermediates, \
Jae Shinc13c0ea2017-12-04 13:16:21 +0900202 $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900203 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900204 $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES))
Jae Shin410a1af2017-12-15 19:35:16 +0900205 $(call private-copy-vndk-intermediates, \
206 $(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES))
Jae Shin893fca62017-12-28 16:00:10 +0900207ifdef 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))
212endif
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 :=
Jae Shin893fca62017-12-28 16:00:10 +0900232vndk_snapshot_variant :=
233vndk_lib_dir :=
234vndk_lib_dir_2nd :=
Jae Shin4736dc12017-11-22 19:25:36 +0900235vndk_snapshot_dependencies :=
Jae Shin4736dc12017-11-22 19:25:36 +0900236
Jae Shin0b1792e2017-12-21 19:04:13 +0900237else # PLATFORM_VNDK_VERSION is NOT set
238
239.PHONY: vndk
240vndk:
241 $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. PLATFORM_VNDK_VERSION must be set.)
242 exit 1
243
244endif # PLATFORM_VNDK_VERSION
245
Jae Shine6b7c842017-10-20 17:46:46 +0900246else # BOARD_VNDK_VERSION is NOT set to 'current'
247
248.PHONY: vndk
249vndk:
250 $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'.)
251 exit 1
252
253endif # BOARD_VNDK_VERSION