blob: 962fae1a830e68f273d0aa66bdb95a2cbf90df1f [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
20# Returns arch-specific libclang_rt.ubsan* library name.
21# Because VNDK_CORE_LIBRARIES includes all arch variants for libclang_rt.ubsan*
22# libs, the arch-specific libs are selected separately.
23#
24# Args:
25# $(1): if not empty, evaluates for TARGET_2ND_ARCH
26define clang-ubsan-vndk-core
Jae Shin4736dc12017-11-22 19:25:36 +090027$(strip \
28 $(eval prefix := $(if $(1),2ND_,)) \
29 $(addsuffix .vendor,$($(addprefix $(prefix),UBSAN_RUNTIME_LIBRARY))) \
30)
Jae Shine6b7c842017-10-20 17:46:46 +090031endef
32
Jae Shin4736dc12017-11-22 19:25:36 +090033# Returns list of file paths of the intermediate objs
34#
Jae Shine6b7c842017-10-20 17:46:46 +090035# Args:
Jae Shin4736dc12017-11-22 19:25:36 +090036# $(1): list of obj names (e.g., libfoo.vendor, ld.config.txt, ...)
37# $(2): target class (e.g., SHARED_LIBRARIES, STATIC_LIBRARIES, ETC)
38# $(3): if not empty, evaluates for TARGET_2ND_ARCH
Jae Shine6b7c842017-10-20 17:46:46 +090039define paths-of-intermediates
Jae Shin4736dc12017-11-22 19:25:36 +090040$(strip \
41 $(foreach obj,$(1), \
42 $(eval file_name := $(if $(filter SHARED_LIBRARIES,$(2)),$(patsubst %.so,%,$(obj)).so,$(obj))) \
43 $(eval dir := $(call intermediates-dir-for,$(2),$(obj),,,$(3))) \
44 $(call append-path,$(dir),$(file_name)) \
45 ) \
46)
Jae Shine6b7c842017-10-20 17:46:46 +090047endef
48
Jae Shine6b7c842017-10-20 17:46:46 +090049# If in the future libclang_rt.ubsan* is removed from the VNDK-core list,
50# need to update the related logic in this file.
51ifeq (,$(filter libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES)))
Jae Shin4736dc12017-11-22 19:25:36 +090052 $(warning libclang_rt.ubsan* is no longer a VNDK-core library. Please update this file.)
53 vndk_core_libs := $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES))
54else
55 vndk_core_libs := $(addsuffix .vendor,$(filter-out libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES)))
56
57 # for TARGET_ARCH
58 vndk_core_libs += $(call clang-ubsan-vndk-core)
59
60 # TODO(b/69834489): Package additional arch variants
61 # ifdef TARGET_2ND_ARCH
62 # vndk_core_libs += $(call clang-ubsan-vndk-core,true)
63 # endif
Jae Shine6b7c842017-10-20 17:46:46 +090064endif
65
Jae Shin4736dc12017-11-22 19:25:36 +090066vndk_sp_libs := $(addsuffix .vendor,$(VNDK_SAMEPROCESS_LIBRARIES))
67vndk_private_libs := $(addsuffix .vendor,$(VNDK_PRIVATE_LIBRARIES))
Jae Shine6b7c842017-10-20 17:46:46 +090068
Jae Shin4736dc12017-11-22 19:25:36 +090069vndk_snapshot_libs := \
70 $(vndk_core_libs) \
71 $(vndk_sp_libs)
Jae Shine6b7c842017-10-20 17:46:46 +090072
Jae Shin4736dc12017-11-22 19:25:36 +090073vndk_prebuilt_txts := \
74 ld.config.txt \
75 vndksp.libraries.txt \
76 llndk.libraries.txt
77
78vndk_snapshot_top := $(call intermediates-dir-for,PACKAGING,vndk-snapshot)
79vndk_snapshot_out := $(vndk_snapshot_top)/vndk-snapshot
80vndk_snapshot_configs_out := $(vndk_snapshot_top)/configs
81
82#######################################
83# vndkcore.libraries.txt
84vndkcore.libraries.txt := $(vndk_snapshot_configs_out)/vndkcore.libraries.txt
85$(vndkcore.libraries.txt): $(vndk_core_libs)
86 @echo 'Generating: $@'
87 @rm -f $@
88 @mkdir -p $(dir $@)
89 $(hide) echo -n > $@
90 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
91
92
93#######################################
94# vndkprivate.libraries.txt
95vndkprivate.libraries.txt := $(vndk_snapshot_configs_out)/vndkprivate.libraries.txt
96$(vndkprivate.libraries.txt): $(vndk_private_libs)
97 @echo 'Generating: $@'
98 @rm -f $@
99 @mkdir -p $(dir $@)
100 $(hide) echo -n > $@
101 $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;)
102
103
104vndk_snapshot_configs := \
105 $(vndkcore.libraries.txt) \
106 $(vndkprivate.libraries.txt)
107
108#######################################
109# vndk_snapshot_zip
110vndk_snapshot_arch := $(vndk_snapshot_out)/arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT)
Jae Shine6b7c842017-10-20 17:46:46 +0900111vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_ARCH).zip
Jae Shin4736dc12017-11-22 19:25:36 +0900112
Jae Shine6b7c842017-10-20 17:46:46 +0900113$(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out)
114
Jae Shin4736dc12017-11-22 19:25:36 +0900115$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_snapshot_arch)/shared/vndk-core
116$(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \
117 $(call paths-of-intermediates,$(vndk_core_libs),SHARED_LIBRARIES)
Jae Shine6b7c842017-10-20 17:46:46 +0900118
Jae Shin4736dc12017-11-22 19:25:36 +0900119$(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_snapshot_arch)/shared/vndk-sp
120$(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \
121 $(call paths-of-intermediates,$(vndk_sp_libs),SHARED_LIBRARIES)
122
123$(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_arch)/configs
124$(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \
125 $(call paths-of-intermediates,$(vndk_prebuilt_txts),ETC) \
126 $(vndk_snapshot_configs)
127
128# TODO(b/69834489): Package additional arch variants
129# ifdef TARGET_2ND_ARCH
130# vndk_snapshot_arch_2ND := $(vndk_snapshot_out)/arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT)
131# $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-core
132# $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \
133# $(call paths-of-intermediates,$(vndk_core_libs),SHARED_LIBRARIES,true)
134# $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-sp
135# $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \
136# $(call paths-of-intermediates,$(vndk_sp_libs),SHARED_LIBRARIES,true)
137# endif
Jae Shine6b7c842017-10-20 17:46:46 +0900138
139# Args
140# $(1): destination directory
Jae Shin4736dc12017-11-22 19:25:36 +0900141# $(2): list of files to copy
Jae Shine6b7c842017-10-20 17:46:46 +0900142$(vndk_snapshot_zip): private-copy-vndk-intermediates = \
Jae Shin4736dc12017-11-22 19:25:36 +0900143 $(if $(2),$(strip \
144 @mkdir -p $(1); \
145 $(foreach file,$(2), \
146 if [ -e $(file) ]; then \
147 cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \
148 fi; \
149 ) \
150 ))
151
152vndk_snapshot_dependencies := \
153 $(vndk_snapshot_libs) \
154 $(vndk_prebuilt_txts) \
155 $(vndk_snapshot_configs)
Jae Shine6b7c842017-10-20 17:46:46 +0900156
157$(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP)
158 @echo 'Generating VNDK snapshot: $@'
159 @rm -f $@
160 @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT)
161 @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT)
162 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900163 $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900164 $(call private-copy-vndk-intermediates, \
Jae Shinc13c0ea2017-12-04 13:16:21 +0900165 $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES))
Jae Shine6b7c842017-10-20 17:46:46 +0900166 $(call private-copy-vndk-intermediates, \
Jae Shin4736dc12017-11-22 19:25:36 +0900167 $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES))
168# TODO(b/69834489): Package additional arch variants
169# ifdef TARGET_2ND_ARCH
170# $(call private-copy-vndk-intermediates, \
171# $(PRIVATE_VNDK_CORE_OUT_2ND),$(PRIVATE_VNDK_CORE_INTERMEDIATES_2ND))
172# $(call private-copy-vndk-intermediates, \
173# $(PRIVATE_VNDK_SP_OUT_2ND),$(PRIVATE_VNDK_SP_INTERMEDIATES_2ND))
174# endif
Jae Shinc13c0ea2017-12-04 13:16:21 +0900175 $(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_VNDK_SNAPSHOT_OUT) -D $(PRIVATE_VNDK_SNAPSHOT_OUT)
Jae Shine6b7c842017-10-20 17:46:46 +0900176
177.PHONY: vndk
178vndk: $(vndk_snapshot_zip)
179
180$(call dist-for-goals, vndk, $(vndk_snapshot_zip))
181
Jae Shin4736dc12017-11-22 19:25:36 +0900182# clear global vars
183clang-ubsan-vndk-core :=
184paths-of-intermediates :=
185vndk_core_libs :=
186vndk_sp_libs :=
187vndk_snapshot_libs :=
188vndk_prebuilt_txts :=
189vndk_snapshot_configs :=
190vndk_snapshot_top :=
191vndk_snapshot_out :=
192vndk_snapshot_configs_out :=
193vndk_snapshot_arch :=
194vndk_snapshot_dependencies :=
195# TODO(b/69834489): Package additional arch variants
196# ifdef TARGET_2ND_ARCH
197# vndk_snapshot_arch_2ND :=
198# endif
199
Jae Shine6b7c842017-10-20 17:46:46 +0900200else # BOARD_VNDK_VERSION is NOT set to 'current'
201
202.PHONY: vndk
203vndk:
204 $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'.)
205 exit 1
206
207endif # BOARD_VNDK_VERSION