blob: b9133df02f57375c6cd9a7cd217f340f2c765a1b [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
Justin Yun4dff0c62018-01-04 10:51:16 +090023# BOARD_VNDK_RUNTIME_DISABLE must not be set to 'true'.
24ifneq ($(BOARD_VNDK_RUNTIME_DISABLE),true)
25
Jae Shine6b7c842017-10-20 17:46:46 +090026# Returns arch-specific libclang_rt.ubsan* library name.
27# Because VNDK_CORE_LIBRARIES includes all arch variants for libclang_rt.ubsan*
28# libs, the arch-specific libs are selected separately.
29#
30# Args:
31# $(1): if not empty, evaluates for TARGET_2ND_ARCH
32define clang-ubsan-vndk-core
Jae Shin4736dc12017-11-22 19:25:36 +090033$(strip \
34 $(eval prefix := $(if $(1),2ND_,)) \
35 $(addsuffix .vendor,$($(addprefix $(prefix),UBSAN_RUNTIME_LIBRARY))) \
36)
Jae Shine6b7c842017-10-20 17:46:46 +090037endef
38
Jae Shin4736dc12017-11-22 19:25:36 +090039# Returns list of file paths of the intermediate objs
40#
Jae Shine6b7c842017-10-20 17:46:46 +090041# Args:
Jae Shin77c07dd2017-12-22 11:24:00 +090042# $(1): list of module and filename pairs (e.g., ld.config.txt:ld.config.27.txt ...)
Jae Shin4736dc12017-11-22 19:25:36 +090043# $(2): target class (e.g., SHARED_LIBRARIES, STATIC_LIBRARIES, ETC)
44# $(3): if not empty, evaluates for TARGET_2ND_ARCH
Jae Shine6b7c842017-10-20 17:46:46 +090045define paths-of-intermediates
Jae Shin4736dc12017-11-22 19:25:36 +090046$(strip \
Jae Shin77c07dd2017-12-22 11:24:00 +090047 $(foreach pair,$(1), \
48 $(eval split_pair := $(subst :,$(space),$(pair))) \
49 $(eval module := $(word 1,$(split_pair))) \
50 $(eval filename := $(word 2,$(split_pair))) \
51 $(eval dir := $(call intermediates-dir-for,$(2),$(module),,,$(3))) \
52 $(call append-path,$(dir),$(filename)) \
Jae Shin4736dc12017-11-22 19:25:36 +090053 ) \
54)
Jae Shine6b7c842017-10-20 17:46:46 +090055endef
56
Jae Shin410a1af2017-12-15 19:35:16 +090057# Returns paths of notice files under $(TARGET_OUT_NOTICE_FILES)
58#
59# Args:
60# $(1): list of lib names (e.g., libfoo.vendor)
61# $(2): vndk lib type, one of 'vndk' or 'vndk-sp'
62define paths-of-notice-files
63$(strip \
64 $(eval lib_dir := lib$(if $(TARGET_IS_64BIT),64,)) \
65 $(eval vndk_dir := $(2)-$(PLATFORM_VNDK_VERSION)) \
66 $(foreach lib,$(1), \
67 $(eval notice_file_name := $(patsubst %.vendor,%.so.txt,$(lib))) \
68 $(TARGET_OUT_NOTICE_FILES)/src/system/$(lib_dir)/$(vndk_dir)/$(notice_file_name) \
69 ) \
70)
71endef
72
Jae Shine6b7c842017-10-20 17:46:46 +090073# If in the future libclang_rt.ubsan* is removed from the VNDK-core list,
74# need to update the related logic in this file.
75ifeq (,$(filter libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES)))
Jae Shin4736dc12017-11-22 19:25:36 +090076 $(warning libclang_rt.ubsan* is no longer a VNDK-core library. Please update this file.)
77 vndk_core_libs := $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES))
78else
79 vndk_core_libs := $(addsuffix .vendor,$(filter-out libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES)))
80
Jae Shin4736dc12017-11-22 19:25:36 +090081 vndk_core_libs += $(call clang-ubsan-vndk-core)
Jae Shin893fca62017-12-28 16:00:10 +090082 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
Jae Shin893fca62017-12-28 16:00:10 +0900143vndk_snapshot_variant := $(vndk_snapshot_out)/$(TARGET_ARCH)
Jae Shinf20605c2018-05-30 21:01:29 +0900144binder :=
145ifneq ($(TARGET_USES_64_BIT_BINDER), true)
146 binder := binder32
147endif
148vndk_lib_dir := $(subst $(space),/,$(strip $(vndk_snapshot_variant) $(binder) arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT)))
149vndk_lib_dir_2nd := $(subst $(space),/,$(strip $(vndk_snapshot_variant) $(binder) arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT)))
150vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_PRODUCT).zip
Jae Shin4736dc12017-11-22 19:25:36 +0900151
Jae Shine6b7c842017-10-20 17:46:46 +0900152$(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out)
153
Jae Shin893fca62017-12-28 16:00:10 +0900154$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_lib_dir)/shared/vndk-core
Jae Shin4736dc12017-11-22 19:25:36 +0900155$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900156 $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES)
Jae Shine6b7c842017-10-20 17:46:46 +0900157
Jae Shin893fca62017-12-28 16:00:10 +0900158$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_lib_dir)/shared/vndk-sp
Jae Shin4736dc12017-11-22 19:25:36 +0900159$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900160 $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES)
Jae Shin4736dc12017-11-22 19:25:36 +0900161
Jae Shin893fca62017-12-28 16:00:10 +0900162$(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_variant)/configs
Jae Shin4736dc12017-11-22 19:25:36 +0900163$(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900164 $(call paths-of-intermediates,$(foreach txt,$(vndk_prebuilt_txts), \
165 $(txt):$(patsubst %.txt,%.$(PLATFORM_VNDK_VERSION).txt,$(txt))),ETC) \
Jae Shin4736dc12017-11-22 19:25:36 +0900166 $(vndk_snapshot_configs)
167
Jae Shin893fca62017-12-28 16:00:10 +0900168$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_variant)/NOTICE_FILES
Jae Shin410a1af2017-12-15 19:35:16 +0900169$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := \
170 $(call paths-of-notice-files,$(vndk_core_libs),vndk) \
171 $(call paths-of-notice-files,$(vndk_sp_libs),vndk-sp)
172
Jae Shin893fca62017-12-28 16:00:10 +0900173ifdef TARGET_2ND_ARCH
174$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-core
175$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \
176 $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true)
177
178$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-sp
179$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \
180 $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true)
181endif
Jae Shine6b7c842017-10-20 17:46:46 +0900182
183# Args
184# $(1): destination directory
Jae Shin4736dc12017-11-22 19:25:36 +0900185# $(2): list of files to copy
Jae Shine6b7c842017-10-20 17:46:46 +0900186$(vndk_snapshot_zip): private-copy-vndk-intermediates = \
Jae Shin4736dc12017-11-22 19:25:36 +0900187 $(if $(2),$(strip \
188 @mkdir -p $(1); \
189 $(foreach file,$(2), \
190 if [ -e $(file) ]; then \
191 cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \
192 fi; \
193 ) \
194 ))
195
196vndk_snapshot_dependencies := \
197 $(vndk_snapshot_libs) \
198 $(vndk_prebuilt_txts) \
199 $(vndk_snapshot_configs)
Jae Shine6b7c842017-10-20 17:46:46 +0900200
201$(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP)
202 @echo 'Generating VNDK snapshot: $@'
203 @rm -f $@
204 @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT)
205 @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT)
206 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900207 $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900208 $(call private-copy-vndk-intermediates, \
Jae Shinc13c0ea2017-12-04 13:16:21 +0900209 $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900210 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900211 $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES))
Jae Shin410a1af2017-12-15 19:35:16 +0900212 $(call private-copy-vndk-intermediates, \
213 $(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES))
Jae Shin893fca62017-12-28 16:00:10 +0900214ifdef TARGET_2ND_ARCH
215 $(call private-copy-vndk-intermediates, \
216 $(PRIVATE_VNDK_CORE_OUT_2ND),$(PRIVATE_VNDK_CORE_INTERMEDIATES_2ND))
217 $(call private-copy-vndk-intermediates, \
218 $(PRIVATE_VNDK_SP_OUT_2ND),$(PRIVATE_VNDK_SP_INTERMEDIATES_2ND))
219endif
Jae Shinc13c0ea2017-12-04 13:16:21 +0900220 $(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_VNDK_SNAPSHOT_OUT) -D $(PRIVATE_VNDK_SNAPSHOT_OUT)
Jae Shine6b7c842017-10-20 17:46:46 +0900221
222.PHONY: vndk
223vndk: $(vndk_snapshot_zip)
224
225$(call dist-for-goals, vndk, $(vndk_snapshot_zip))
226
Jae Shin4736dc12017-11-22 19:25:36 +0900227# clear global vars
228clang-ubsan-vndk-core :=
229paths-of-intermediates :=
Jae Shin410a1af2017-12-15 19:35:16 +0900230paths-of-notice-files :=
Jae Shin4736dc12017-11-22 19:25:36 +0900231vndk_core_libs :=
232vndk_sp_libs :=
233vndk_snapshot_libs :=
234vndk_prebuilt_txts :=
235vndk_snapshot_configs :=
236vndk_snapshot_top :=
237vndk_snapshot_out :=
238vndk_snapshot_configs_out :=
Jae Shin893fca62017-12-28 16:00:10 +0900239vndk_snapshot_variant :=
Jae Shinf20605c2018-05-30 21:01:29 +0900240binder :=
Jae Shin893fca62017-12-28 16:00:10 +0900241vndk_lib_dir :=
242vndk_lib_dir_2nd :=
Jae Shin4736dc12017-11-22 19:25:36 +0900243vndk_snapshot_dependencies :=
Jae Shin4736dc12017-11-22 19:25:36 +0900244
Justin Yun4dff0c62018-01-04 10:51:16 +0900245else # BOARD_VNDK_RUNTIME_DISABLE is set to 'true'
246error_msg := "CANNOT generate VNDK snapshot. BOARD_VNDK_RUNTIME_DISABLE must not be set to 'true'."
247endif # BOARD_VNDK_RUNTIME_DISABLE
248
Jae Shin0b1792e2017-12-21 19:04:13 +0900249else # PLATFORM_VNDK_VERSION is NOT set
Justin Yun4dff0c62018-01-04 10:51:16 +0900250error_msg := "CANNOT generate VNDK snapshot. PLATFORM_VNDK_VERSION must be set."
Jae Shin0b1792e2017-12-21 19:04:13 +0900251endif # PLATFORM_VNDK_VERSION
252
Jae Shine6b7c842017-10-20 17:46:46 +0900253else # BOARD_VNDK_VERSION is NOT set to 'current'
Justin Yun4dff0c62018-01-04 10:51:16 +0900254error_msg := "CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'."
255endif # BOARD_VNDK_VERSION
256
257ifneq (,$(error_msg))
Jae Shine6b7c842017-10-20 17:46:46 +0900258
259.PHONY: vndk
260vndk:
Justin Yun4dff0c62018-01-04 10:51:16 +0900261 $(call echo-error,$(current_makefile),$(error_msg))
Jae Shine6b7c842017-10-20 17:46:46 +0900262 exit 1
263
Justin Yun4dff0c62018-01-04 10:51:16 +0900264endif