blob: 3604aedf46e7d87a52a255b089e50260a8828ccb [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)
144vndk_lib_dir := $(vndk_snapshot_variant)/arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT)
145vndk_lib_dir_2nd := $(vndk_snapshot_variant)/arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT)
Jae Shine6b7c842017-10-20 17:46:46 +0900146vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_ARCH).zip
Jae Shin4736dc12017-11-22 19:25:36 +0900147
Jae Shine6b7c842017-10-20 17:46:46 +0900148$(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out)
149
Jae Shin893fca62017-12-28 16:00:10 +0900150$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_lib_dir)/shared/vndk-core
Jae Shin4736dc12017-11-22 19:25:36 +0900151$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900152 $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES)
Jae Shine6b7c842017-10-20 17:46:46 +0900153
Jae Shin893fca62017-12-28 16:00:10 +0900154$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_lib_dir)/shared/vndk-sp
Jae Shin4736dc12017-11-22 19:25:36 +0900155$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900156 $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES)
Jae Shin4736dc12017-11-22 19:25:36 +0900157
Jae Shin893fca62017-12-28 16:00:10 +0900158$(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_variant)/configs
Jae Shin4736dc12017-11-22 19:25:36 +0900159$(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \
Jae Shin77c07dd2017-12-22 11:24:00 +0900160 $(call paths-of-intermediates,$(foreach txt,$(vndk_prebuilt_txts), \
161 $(txt):$(patsubst %.txt,%.$(PLATFORM_VNDK_VERSION).txt,$(txt))),ETC) \
Jae Shin4736dc12017-11-22 19:25:36 +0900162 $(vndk_snapshot_configs)
163
Jae Shin893fca62017-12-28 16:00:10 +0900164$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_variant)/NOTICE_FILES
Jae Shin410a1af2017-12-15 19:35:16 +0900165$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := \
166 $(call paths-of-notice-files,$(vndk_core_libs),vndk) \
167 $(call paths-of-notice-files,$(vndk_sp_libs),vndk-sp)
168
Jae Shin893fca62017-12-28 16:00:10 +0900169ifdef TARGET_2ND_ARCH
170$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-core
171$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \
172 $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true)
173
174$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-sp
175$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \
176 $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true)
177endif
Jae Shine6b7c842017-10-20 17:46:46 +0900178
179# Args
180# $(1): destination directory
Jae Shin4736dc12017-11-22 19:25:36 +0900181# $(2): list of files to copy
Jae Shine6b7c842017-10-20 17:46:46 +0900182$(vndk_snapshot_zip): private-copy-vndk-intermediates = \
Jae Shin4736dc12017-11-22 19:25:36 +0900183 $(if $(2),$(strip \
184 @mkdir -p $(1); \
185 $(foreach file,$(2), \
186 if [ -e $(file) ]; then \
187 cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \
188 fi; \
189 ) \
190 ))
191
192vndk_snapshot_dependencies := \
193 $(vndk_snapshot_libs) \
194 $(vndk_prebuilt_txts) \
195 $(vndk_snapshot_configs)
Jae Shine6b7c842017-10-20 17:46:46 +0900196
197$(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP)
198 @echo 'Generating VNDK snapshot: $@'
199 @rm -f $@
200 @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT)
201 @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT)
202 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900203 $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900204 $(call private-copy-vndk-intermediates, \
Jae Shinc13c0ea2017-12-04 13:16:21 +0900205 $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900206 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900207 $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES))
Jae Shin410a1af2017-12-15 19:35:16 +0900208 $(call private-copy-vndk-intermediates, \
209 $(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES))
Jae Shin893fca62017-12-28 16:00:10 +0900210ifdef 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))
215endif
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 :=
Jae Shin893fca62017-12-28 16:00:10 +0900235vndk_snapshot_variant :=
236vndk_lib_dir :=
237vndk_lib_dir_2nd :=
Jae Shin4736dc12017-11-22 19:25:36 +0900238vndk_snapshot_dependencies :=
Jae Shin4736dc12017-11-22 19:25:36 +0900239
Justin Yun4dff0c62018-01-04 10:51:16 +0900240else # BOARD_VNDK_RUNTIME_DISABLE is set to 'true'
241error_msg := "CANNOT generate VNDK snapshot. BOARD_VNDK_RUNTIME_DISABLE must not be set to 'true'."
242endif # BOARD_VNDK_RUNTIME_DISABLE
243
Jae Shin0b1792e2017-12-21 19:04:13 +0900244else # PLATFORM_VNDK_VERSION is NOT set
Justin Yun4dff0c62018-01-04 10:51:16 +0900245error_msg := "CANNOT generate VNDK snapshot. PLATFORM_VNDK_VERSION must be set."
Jae Shin0b1792e2017-12-21 19:04:13 +0900246endif # PLATFORM_VNDK_VERSION
247
Jae Shine6b7c842017-10-20 17:46:46 +0900248else # BOARD_VNDK_VERSION is NOT set to 'current'
Justin Yun4dff0c62018-01-04 10:51:16 +0900249error_msg := "CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'."
250endif # BOARD_VNDK_VERSION
251
252ifneq (,$(error_msg))
Jae Shine6b7c842017-10-20 17:46:46 +0900253
254.PHONY: vndk
255vndk:
Justin Yun4dff0c62018-01-04 10:51:16 +0900256 $(call echo-error,$(current_makefile),$(error_msg))
Jae Shine6b7c842017-10-20 17:46:46 +0900257 exit 1
258
Justin Yun4dff0c62018-01-04 10:51:16 +0900259endif