blob: ba48df7a31b528fc9b07be257ab9e006541cbbd7 [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
Dan Willemsen64931182018-06-17 21:47:18 -070039# Returns list of src:dest paths of the intermediate objs
Jae Shin4736dc12017-11-22 19:25:36 +090040#
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 ...)
Dan Willemsen64931182018-06-17 21:47:18 -070043# $(2): if not empty, evaluates for TARGET_2ND_ARCH
Jae Shine6b7c842017-10-20 17:46:46 +090044define paths-of-intermediates
Jae Shin4736dc12017-11-22 19:25:36 +090045$(strip \
Jae Shin77c07dd2017-12-22 11:24:00 +090046 $(foreach pair,$(1), \
Dan Willemsen64931182018-06-17 21:47:18 -070047 $(eval module := $(call word-colon,1,$(pair))$(if $(2),$(TARGET_2ND_ARCH_MODULE_SUFFIX))) \
48 $(eval built := $(ALL_MODULES.$(module).BUILT_INSTALLED)) \
49 $(eval filename := $(call word-colon,2,$(pair))) \
50 $(if $(wordlist 2,100,$(built)), \
51 $(error Unable to handle multiple built files ($(module)): $(built))) \
52 $(if $(built),$(call word-colon,1,$(built)):$(filename)) \
Jae Shin4736dc12017-11-22 19:25:36 +090053 ) \
54)
Jae Shine6b7c842017-10-20 17:46:46 +090055endef
56
Dan Willemsen64931182018-06-17 21:47:18 -070057# Returns src:dest list of notice files
Jae Shin410a1af2017-12-15 19:35:16 +090058#
59# Args:
60# $(1): list of lib names (e.g., libfoo.vendor)
Jae Shin410a1af2017-12-15 19:35:16 +090061define paths-of-notice-files
62$(strip \
Jae Shin410a1af2017-12-15 19:35:16 +090063 $(foreach lib,$(1), \
Dan Willemsen64931182018-06-17 21:47:18 -070064 $(eval notice := $(sort \
65 $(ALL_MODULES.$(lib).NOTICES) \
66 $(if $(TARGET_2ND_ARCH),
67 $(ALL_MODULES.$(lib)$(TARGET_2ND_ARCH_MODULE_SUFFIX).NOTICES)))) \
68 $(if $(wordlist 2,100,$(notice)), \
69 $(error Unable to handle multiple notice files ($(lib)): $(notice))) \
70 $(if $(notice),$(notice):$(subst .vendor,,$(lib)).so.txt)))
Jae Shin410a1af2017-12-15 19:35:16 +090071endef
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
Dan Willemsen64931182018-06-17 21:47:18 -0700106$(vndkcore.libraries.txt): PRIVATE_LIBS := $(vndk_core_libs)
107$(vndkcore.libraries.txt):
Jae Shin4736dc12017-11-22 19:25:36 +0900108 @echo 'Generating: $@'
109 @rm -f $@
110 @mkdir -p $(dir $@)
111 $(hide) echo -n > $@
Dan Willemsen64931182018-06-17 21:47:18 -0700112 $(hide) $(foreach lib,$(PRIVATE_LIBS),echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
Jae Shin4736dc12017-11-22 19:25:36 +0900113
114
115#######################################
116# vndkprivate.libraries.txt
117vndkprivate.libraries.txt := $(vndk_snapshot_configs_out)/vndkprivate.libraries.txt
Dan Willemsen64931182018-06-17 21:47:18 -0700118$(vndkprivate.libraries.txt): PRIVATE_LIBS := $(vndk_private_libs)
119$(vndkprivate.libraries.txt):
Jae Shin4736dc12017-11-22 19:25:36 +0900120 @echo 'Generating: $@'
121 @rm -f $@
122 @mkdir -p $(dir $@)
123 $(hide) echo -n > $@
Dan Willemsen64931182018-06-17 21:47:18 -0700124 $(hide) $(foreach lib,$(PRIVATE_LIBS),echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
Jae Shin4736dc12017-11-22 19:25:36 +0900125
126
Jae Shin410a1af2017-12-15 19:35:16 +0900127#######################################
128# module_paths.txt
129module_paths.txt := $(vndk_snapshot_configs_out)/module_paths.txt
Dan Willemsen64931182018-06-17 21:47:18 -0700130$(module_paths.txt): PRIVATE_LIBS := $(vndk_snapshot_libs)
131$(module_paths.txt):
Jae Shin410a1af2017-12-15 19:35:16 +0900132 @echo 'Generating: $@'
133 @rm -f $@
134 @mkdir -p $(dir $@)
135 $(hide) echo -n > $@
Dan Willemsen64931182018-06-17 21:47:18 -0700136 $(hide) $(foreach lib,$(PRIVATE_LIBS),echo $(patsubst %.vendor,%,$(lib)).so $(ALL_MODULES.$(lib).PATH) >> $@;)
Jae Shin410a1af2017-12-15 19:35:16 +0900137
138
Jae Shin4736dc12017-11-22 19:25:36 +0900139vndk_snapshot_configs := \
140 $(vndkcore.libraries.txt) \
Jae Shin410a1af2017-12-15 19:35:16 +0900141 $(vndkprivate.libraries.txt) \
142 $(module_paths.txt)
Jae Shin4736dc12017-11-22 19:25:36 +0900143
144#######################################
145# vndk_snapshot_zip
Jae Shin893fca62017-12-28 16:00:10 +0900146vndk_snapshot_variant := $(vndk_snapshot_out)/$(TARGET_ARCH)
Jae Shinf20605c2018-05-30 21:01:29 +0900147binder :=
148ifneq ($(TARGET_USES_64_BIT_BINDER), true)
149 binder := binder32
150endif
151vndk_lib_dir := $(subst $(space),/,$(strip $(vndk_snapshot_variant) $(binder) arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT)))
152vndk_lib_dir_2nd := $(subst $(space),/,$(strip $(vndk_snapshot_variant) $(binder) arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT)))
153vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_PRODUCT).zip
Jae Shin4736dc12017-11-22 19:25:36 +0900154
Jae Shine6b7c842017-10-20 17:46:46 +0900155$(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out)
156
Dan Willemsen64931182018-06-17 21:47:18 -0700157deps := $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(subst .vendor,,$(lib)).so))
Jae Shin893fca62017-12-28 16:00:10 +0900158$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_lib_dir)/shared/vndk-core
Dan Willemsen64931182018-06-17 21:47:18 -0700159$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := $(deps)
160$(vndk_snapshot_zip): $(foreach d,$(deps),$(call word-colon,1,$(d)))
161deps :=
Jae Shine6b7c842017-10-20 17:46:46 +0900162
Dan Willemsen64931182018-06-17 21:47:18 -0700163deps := $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(subst .vendor,,$(lib)).so))
Jae Shin893fca62017-12-28 16:00:10 +0900164$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_lib_dir)/shared/vndk-sp
Dan Willemsen64931182018-06-17 21:47:18 -0700165$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := $(deps)
166$(vndk_snapshot_zip): $(foreach d,$(deps),$(call word-colon,1,$(d)))
167deps :=
Jae Shin4736dc12017-11-22 19:25:36 +0900168
Dan Willemsen64931182018-06-17 21:47:18 -0700169deps := $(call paths-of-intermediates,$(foreach txt,$(vndk_prebuilt_txts), \
170 $(txt):$(patsubst %.txt,%.$(PLATFORM_VNDK_VERSION).txt,$(txt)))) \
171 $(foreach config,$(vndk_snapshot_configs),$(config):$(notdir $(config)))
Jae Shin893fca62017-12-28 16:00:10 +0900172$(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_variant)/configs
Dan Willemsen64931182018-06-17 21:47:18 -0700173$(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := $(deps)
174$(vndk_snapshot_zip): $(foreach d,$(deps),$(call word-colon,1,$(d)))
175deps :=
Jae Shin4736dc12017-11-22 19:25:36 +0900176
Dan Willemsen64931182018-06-17 21:47:18 -0700177notices := $(call paths-of-notice-files,$(vndk_core_libs) $(vndk_sp_libs))
Jae Shin893fca62017-12-28 16:00:10 +0900178$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_variant)/NOTICE_FILES
Dan Willemsen64931182018-06-17 21:47:18 -0700179$(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := $(notices)
180$(vndk_snapshot_zip): $(foreach n,$(notices),$(call word-colon,1,$(n)))
181notices :=
Jae Shin410a1af2017-12-15 19:35:16 +0900182
Jae Shin893fca62017-12-28 16:00:10 +0900183ifdef TARGET_2ND_ARCH
Dan Willemsen64931182018-06-17 21:47:18 -0700184deps := $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(subst .vendor,,$(lib)).so),true)
Jae Shin893fca62017-12-28 16:00:10 +0900185$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-core
Dan Willemsen64931182018-06-17 21:47:18 -0700186$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := $(deps)
187$(vndk_snapshot_zip): $(foreach d,$(deps),$(call word-colon,1,$(d)))
188deps :=
Jae Shin893fca62017-12-28 16:00:10 +0900189
Dan Willemsen64931182018-06-17 21:47:18 -0700190deps := $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(subst .vendor,,$(lib)).so),true)
Jae Shin893fca62017-12-28 16:00:10 +0900191$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-sp
Dan Willemsen64931182018-06-17 21:47:18 -0700192$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := $(deps)
193$(vndk_snapshot_zip): $(foreach d,$(deps),$(call word-colon,1,$(d)))
194deps :=
Jae Shin893fca62017-12-28 16:00:10 +0900195endif
Jae Shine6b7c842017-10-20 17:46:46 +0900196
197# Args
198# $(1): destination directory
Dan Willemsen64931182018-06-17 21:47:18 -0700199# $(2): list of files (src:dest) to copy
200$(vndk_snapshot_zip): private-copy-intermediates = \
Jae Shin4736dc12017-11-22 19:25:36 +0900201 $(if $(2),$(strip \
Dan Willemsen64931182018-06-17 21:47:18 -0700202 @mkdir -p $(1) && \
Jae Shin4736dc12017-11-22 19:25:36 +0900203 $(foreach file,$(2), \
Dan Willemsen64931182018-06-17 21:47:18 -0700204 cp $(call word-colon,1,$(file)) $(call append-path,$(1),$(call word-colon,2,$(file))) && \
Jae Shin4736dc12017-11-22 19:25:36 +0900205 ) \
Dan Willemsen64931182018-06-17 21:47:18 -0700206 true \
Jae Shin4736dc12017-11-22 19:25:36 +0900207 ))
208
Jae Shine6b7c842017-10-20 17:46:46 +0900209
Dan Willemsen64931182018-06-17 21:47:18 -0700210$(vndk_snapshot_zip): $(SOONG_ZIP)
Jae Shine6b7c842017-10-20 17:46:46 +0900211 @echo 'Generating VNDK snapshot: $@'
212 @rm -f $@
213 @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT)
214 @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT)
Dan Willemsen64931182018-06-17 21:47:18 -0700215 $(call private-copy-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900216 $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES))
Dan Willemsen64931182018-06-17 21:47:18 -0700217 $(call private-copy-intermediates, \
Jae Shinc13c0ea2017-12-04 13:16:21 +0900218 $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES))
Dan Willemsen64931182018-06-17 21:47:18 -0700219 $(call private-copy-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900220 $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES))
Dan Willemsen64931182018-06-17 21:47:18 -0700221 $(call private-copy-intermediates, \
Jae Shin410a1af2017-12-15 19:35:16 +0900222 $(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES))
Jae Shin893fca62017-12-28 16:00:10 +0900223ifdef TARGET_2ND_ARCH
Dan Willemsen64931182018-06-17 21:47:18 -0700224 $(call private-copy-intermediates, \
Jae Shin893fca62017-12-28 16:00:10 +0900225 $(PRIVATE_VNDK_CORE_OUT_2ND),$(PRIVATE_VNDK_CORE_INTERMEDIATES_2ND))
Dan Willemsen64931182018-06-17 21:47:18 -0700226 $(call private-copy-intermediates, \
Jae Shin893fca62017-12-28 16:00:10 +0900227 $(PRIVATE_VNDK_SP_OUT_2ND),$(PRIVATE_VNDK_SP_INTERMEDIATES_2ND))
228endif
Jae Shinc13c0ea2017-12-04 13:16:21 +0900229 $(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_VNDK_SNAPSHOT_OUT) -D $(PRIVATE_VNDK_SNAPSHOT_OUT)
Jae Shine6b7c842017-10-20 17:46:46 +0900230
231.PHONY: vndk
232vndk: $(vndk_snapshot_zip)
233
234$(call dist-for-goals, vndk, $(vndk_snapshot_zip))
235
Jae Shin4736dc12017-11-22 19:25:36 +0900236# clear global vars
237clang-ubsan-vndk-core :=
238paths-of-intermediates :=
Jae Shin410a1af2017-12-15 19:35:16 +0900239paths-of-notice-files :=
Jae Shin4736dc12017-11-22 19:25:36 +0900240vndk_core_libs :=
241vndk_sp_libs :=
242vndk_snapshot_libs :=
243vndk_prebuilt_txts :=
244vndk_snapshot_configs :=
245vndk_snapshot_top :=
246vndk_snapshot_out :=
247vndk_snapshot_configs_out :=
Jae Shin893fca62017-12-28 16:00:10 +0900248vndk_snapshot_variant :=
Jae Shinf20605c2018-05-30 21:01:29 +0900249binder :=
Jae Shin893fca62017-12-28 16:00:10 +0900250vndk_lib_dir :=
251vndk_lib_dir_2nd :=
Jae Shin4736dc12017-11-22 19:25:36 +0900252
Justin Yun4dff0c62018-01-04 10:51:16 +0900253else # BOARD_VNDK_RUNTIME_DISABLE is set to 'true'
254error_msg := "CANNOT generate VNDK snapshot. BOARD_VNDK_RUNTIME_DISABLE must not be set to 'true'."
255endif # BOARD_VNDK_RUNTIME_DISABLE
256
Jae Shin0b1792e2017-12-21 19:04:13 +0900257else # PLATFORM_VNDK_VERSION is NOT set
Justin Yun4dff0c62018-01-04 10:51:16 +0900258error_msg := "CANNOT generate VNDK snapshot. PLATFORM_VNDK_VERSION must be set."
Jae Shin0b1792e2017-12-21 19:04:13 +0900259endif # PLATFORM_VNDK_VERSION
260
Jae Shine6b7c842017-10-20 17:46:46 +0900261else # BOARD_VNDK_VERSION is NOT set to 'current'
Justin Yun4dff0c62018-01-04 10:51:16 +0900262error_msg := "CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'."
263endif # BOARD_VNDK_VERSION
264
265ifneq (,$(error_msg))
Jae Shine6b7c842017-10-20 17:46:46 +0900266
267.PHONY: vndk
268vndk:
Justin Yun4dff0c62018-01-04 10:51:16 +0900269 $(call echo-error,$(current_makefile),$(error_msg))
Jae Shine6b7c842017-10-20 17:46:46 +0900270 exit 1
271
Justin Yun4dff0c62018-01-04 10:51:16 +0900272endif