blob: e42e0bd0491ac3e93f02785e58bf73e28c7dab98 [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
78 # for TARGET_ARCH
79 vndk_core_libs += $(call clang-ubsan-vndk-core)
80
81 # TODO(b/69834489): Package additional arch variants
82 # ifdef TARGET_2ND_ARCH
83 # vndk_core_libs += $(call clang-ubsan-vndk-core,true)
84 # endif
Jae Shine6b7c842017-10-20 17:46:46 +090085endif
86
Jae Shin4736dc12017-11-22 19:25:36 +090087vndk_sp_libs := $(addsuffix .vendor,$(VNDK_SAMEPROCESS_LIBRARIES))
88vndk_private_libs := $(addsuffix .vendor,$(VNDK_PRIVATE_LIBRARIES))
Jae Shine6b7c842017-10-20 17:46:46 +090089
Jae Shin4736dc12017-11-22 19:25:36 +090090vndk_snapshot_libs := \
91 $(vndk_core_libs) \
92 $(vndk_sp_libs)
Jae Shine6b7c842017-10-20 17:46:46 +090093
Jae Shin4736dc12017-11-22 19:25:36 +090094vndk_prebuilt_txts := \
95 ld.config.txt \
96 vndksp.libraries.txt \
97 llndk.libraries.txt
98
99vndk_snapshot_top := $(call intermediates-dir-for,PACKAGING,vndk-snapshot)
100vndk_snapshot_out := $(vndk_snapshot_top)/vndk-snapshot
101vndk_snapshot_configs_out := $(vndk_snapshot_top)/configs
102
103#######################################
104# vndkcore.libraries.txt
105vndkcore.libraries.txt := $(vndk_snapshot_configs_out)/vndkcore.libraries.txt
106$(vndkcore.libraries.txt): $(vndk_core_libs)
107 @echo 'Generating: $@'
108 @rm -f $@
109 @mkdir -p $(dir $@)
110 $(hide) echo -n > $@
111 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
112
113
114#######################################
115# vndkprivate.libraries.txt
116vndkprivate.libraries.txt := $(vndk_snapshot_configs_out)/vndkprivate.libraries.txt
117$(vndkprivate.libraries.txt): $(vndk_private_libs)
118 @echo 'Generating: $@'
119 @rm -f $@
120 @mkdir -p $(dir $@)
121 $(hide) echo -n > $@
122 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
123
124
Jae Shin410a1af2017-12-15 19:35:16 +0900125#######################################
126# module_paths.txt
127module_paths.txt := $(vndk_snapshot_configs_out)/module_paths.txt
128$(module_paths.txt): $(vndk_snapshot_libs)
129 @echo 'Generating: $@'
130 @rm -f $@
131 @mkdir -p $(dir $@)
132 $(hide) echo -n > $@
133 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so $(ALL_MODULES.$(lib).PATH) >> $@;)
134
135
Jae Shin4736dc12017-11-22 19:25:36 +0900136vndk_snapshot_configs := \
137 $(vndkcore.libraries.txt) \
Jae Shin410a1af2017-12-15 19:35:16 +0900138 $(vndkprivate.libraries.txt) \
139 $(module_paths.txt)
Jae Shin4736dc12017-11-22 19:25:36 +0900140
141#######################################
142# vndk_snapshot_zip
143vndk_snapshot_arch := $(vndk_snapshot_out)/arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT)
Jae Shine6b7c842017-10-20 17:46:46 +0900144vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_ARCH).zip
Jae Shin4736dc12017-11-22 19:25:36 +0900145
Jae Shine6b7c842017-10-20 17:46:46 +0900146$(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out)
147
Jae Shin4736dc12017-11-22 19:25:36 +0900148$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_snapshot_arch)/shared/vndk-core
149$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900150 $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES)
Jae Shine6b7c842017-10-20 17:46:46 +0900151
Jae Shin4736dc12017-11-22 19:25:36 +0900152$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_snapshot_arch)/shared/vndk-sp
153$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900154 $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES)
Jae Shin4736dc12017-11-22 19:25:36 +0900155
156$(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_arch)/configs
157$(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900158 $(call paths-of-intermediates,$(foreach txt,$(vndk_prebuilt_txts), \
159 $(txt):$(patsubst %.txt,%.$(PLATFORM_VNDK_VERSION).txt,$(txt))),ETC) \
Jae Shin4736dc12017-11-22 19:25:36 +0900160 $(vndk_snapshot_configs)
161
Jae Shin410a1af2017-12-15 19:35:16 +0900162$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_arch)/NOTICE_FILES
163$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := \
164 $(call paths-of-notice-files,$(vndk_core_libs),vndk) \
165 $(call paths-of-notice-files,$(vndk_sp_libs),vndk-sp)
166
Jae Shin4736dc12017-11-22 19:25:36 +0900167# TODO(b/69834489): Package additional arch variants
168# ifdef TARGET_2ND_ARCH
169# vndk_snapshot_arch_2ND := $(vndk_snapshot_out)/arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT)
170# $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-core
171# $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900172# $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true)
Jae Shin4736dc12017-11-22 19:25:36 +0900173# $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-sp
174# $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900175# $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true)
Jae Shin4736dc12017-11-22 19:25:36 +0900176# endif
Jae Shine6b7c842017-10-20 17:46:46 +0900177
178# Args
179# $(1): destination directory
Jae Shin4736dc12017-11-22 19:25:36 +0900180# $(2): list of files to copy
Jae Shine6b7c842017-10-20 17:46:46 +0900181$(vndk_snapshot_zip): private-copy-vndk-intermediates = \
Jae Shin4736dc12017-11-22 19:25:36 +0900182 $(if $(2),$(strip \
183 @mkdir -p $(1); \
184 $(foreach file,$(2), \
185 if [ -e $(file) ]; then \
186 cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \
187 fi; \
188 ) \
189 ))
190
191vndk_snapshot_dependencies := \
192 $(vndk_snapshot_libs) \
193 $(vndk_prebuilt_txts) \
194 $(vndk_snapshot_configs)
Jae Shine6b7c842017-10-20 17:46:46 +0900195
196$(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP)
197 @echo 'Generating VNDK snapshot: $@'
198 @rm -f $@
199 @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT)
200 @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT)
201 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900202 $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900203 $(call private-copy-vndk-intermediates, \
Jae Shinc13c0ea2017-12-04 13:16:21 +0900204 $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900205 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900206 $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES))
Jae Shin410a1af2017-12-15 19:35:16 +0900207 $(call private-copy-vndk-intermediates, \
208 $(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES))
Jae Shin4736dc12017-11-22 19:25:36 +0900209# TODO(b/69834489): Package additional arch variants
210# ifdef TARGET_2ND_ARCH
211# $(call private-copy-vndk-intermediates, \
212# $(PRIVATE_VNDK_CORE_OUT_2ND),$(PRIVATE_VNDK_CORE_INTERMEDIATES_2ND))
213# $(call private-copy-vndk-intermediates, \
214# $(PRIVATE_VNDK_SP_OUT_2ND),$(PRIVATE_VNDK_SP_INTERMEDIATES_2ND))
215# endif
Jae Shinc13c0ea2017-12-04 13:16:21 +0900216 $(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_VNDK_SNAPSHOT_OUT) -D $(PRIVATE_VNDK_SNAPSHOT_OUT)
Jae Shine6b7c842017-10-20 17:46:46 +0900217
218.PHONY: vndk
219vndk: $(vndk_snapshot_zip)
220
221$(call dist-for-goals, vndk, $(vndk_snapshot_zip))
222
Jae Shin4736dc12017-11-22 19:25:36 +0900223# clear global vars
224clang-ubsan-vndk-core :=
225paths-of-intermediates :=
Jae Shin410a1af2017-12-15 19:35:16 +0900226paths-of-notice-files :=
Jae Shin4736dc12017-11-22 19:25:36 +0900227vndk_core_libs :=
228vndk_sp_libs :=
229vndk_snapshot_libs :=
230vndk_prebuilt_txts :=
231vndk_snapshot_configs :=
232vndk_snapshot_top :=
233vndk_snapshot_out :=
234vndk_snapshot_configs_out :=
235vndk_snapshot_arch :=
236vndk_snapshot_dependencies :=
237# TODO(b/69834489): Package additional arch variants
238# ifdef TARGET_2ND_ARCH
239# vndk_snapshot_arch_2ND :=
240# endif
241
Jae Shin0b1792e2017-12-21 19:04:13 +0900242else # PLATFORM_VNDK_VERSION is NOT set
243
244.PHONY: vndk
245vndk:
246 $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. PLATFORM_VNDK_VERSION must be set.)
247 exit 1
248
249endif # PLATFORM_VNDK_VERSION
250
Jae Shine6b7c842017-10-20 17:46:46 +0900251else # BOARD_VNDK_VERSION is NOT set to 'current'
252
253.PHONY: vndk
254vndk:
255 $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'.)
256 exit 1
257
258endif # BOARD_VNDK_VERSION