Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 1 | # 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 | |
| 15 | current_makefile := $(lastword $(MAKEFILE_LIST)) |
| 16 | |
| 17 | # BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot. |
| 18 | ifeq ($(BOARD_VNDK_VERSION),current) |
| 19 | |
Jae Shin | 0b1792e | 2017-12-21 19:04:13 +0900 | [diff] [blame] | 20 | # PLATFORM_VNDK_VERSION must be set. |
| 21 | ifneq (,$(PLATFORM_VNDK_VERSION)) |
| 22 | |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 23 | # 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 |
| 29 | define clang-ubsan-vndk-core |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 30 | $(strip \ |
| 31 | $(eval prefix := $(if $(1),2ND_,)) \ |
| 32 | $(addsuffix .vendor,$($(addprefix $(prefix),UBSAN_RUNTIME_LIBRARY))) \ |
| 33 | ) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 34 | endef |
| 35 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 36 | # Returns list of file paths of the intermediate objs |
| 37 | # |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 38 | # Args: |
Jae Shin | 77c07dd | 2017-12-22 11:24:00 +0900 | [diff] [blame] | 39 | # $(1): list of module and filename pairs (e.g., ld.config.txt:ld.config.27.txt ...) |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 40 | # $(2): target class (e.g., SHARED_LIBRARIES, STATIC_LIBRARIES, ETC) |
| 41 | # $(3): if not empty, evaluates for TARGET_2ND_ARCH |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 42 | define paths-of-intermediates |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 43 | $(strip \ |
Jae Shin | 77c07dd | 2017-12-22 11:24:00 +0900 | [diff] [blame] | 44 | $(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 Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 50 | ) \ |
| 51 | ) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 52 | endef |
| 53 | |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 54 | # 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' |
| 59 | define 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 | ) |
| 68 | endef |
| 69 | |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 70 | # If in the future libclang_rt.ubsan* is removed from the VNDK-core list, |
| 71 | # need to update the related logic in this file. |
| 72 | ifeq (,$(filter libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES))) |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 73 | $(warning libclang_rt.ubsan* is no longer a VNDK-core library. Please update this file.) |
| 74 | vndk_core_libs := $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES)) |
| 75 | else |
| 76 | vndk_core_libs := $(addsuffix .vendor,$(filter-out libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES))) |
| 77 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 78 | vndk_core_libs += $(call clang-ubsan-vndk-core) |
Jae Shin | 893fca6 | 2017-12-28 16:00:10 +0900 | [diff] [blame^] | 79 | ifdef TARGET_2ND_ARCH |
| 80 | vndk_core_libs += $(call clang-ubsan-vndk-core,true) |
| 81 | endif |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 82 | endif |
| 83 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 84 | vndk_sp_libs := $(addsuffix .vendor,$(VNDK_SAMEPROCESS_LIBRARIES)) |
| 85 | vndk_private_libs := $(addsuffix .vendor,$(VNDK_PRIVATE_LIBRARIES)) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 86 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 87 | vndk_snapshot_libs := \ |
| 88 | $(vndk_core_libs) \ |
| 89 | $(vndk_sp_libs) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 90 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 91 | vndk_prebuilt_txts := \ |
| 92 | ld.config.txt \ |
| 93 | vndksp.libraries.txt \ |
| 94 | llndk.libraries.txt |
| 95 | |
| 96 | vndk_snapshot_top := $(call intermediates-dir-for,PACKAGING,vndk-snapshot) |
| 97 | vndk_snapshot_out := $(vndk_snapshot_top)/vndk-snapshot |
| 98 | vndk_snapshot_configs_out := $(vndk_snapshot_top)/configs |
| 99 | |
| 100 | ####################################### |
| 101 | # vndkcore.libraries.txt |
| 102 | vndkcore.libraries.txt := $(vndk_snapshot_configs_out)/vndkcore.libraries.txt |
| 103 | $(vndkcore.libraries.txt): $(vndk_core_libs) |
| 104 | @echo 'Generating: $@' |
| 105 | @rm -f $@ |
| 106 | @mkdir -p $(dir $@) |
| 107 | $(hide) echo -n > $@ |
| 108 | $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;) |
| 109 | |
| 110 | |
| 111 | ####################################### |
| 112 | # vndkprivate.libraries.txt |
| 113 | vndkprivate.libraries.txt := $(vndk_snapshot_configs_out)/vndkprivate.libraries.txt |
| 114 | $(vndkprivate.libraries.txt): $(vndk_private_libs) |
| 115 | @echo 'Generating: $@' |
| 116 | @rm -f $@ |
| 117 | @mkdir -p $(dir $@) |
| 118 | $(hide) echo -n > $@ |
| 119 | $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;) |
| 120 | |
| 121 | |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 122 | ####################################### |
| 123 | # module_paths.txt |
| 124 | module_paths.txt := $(vndk_snapshot_configs_out)/module_paths.txt |
| 125 | $(module_paths.txt): $(vndk_snapshot_libs) |
| 126 | @echo 'Generating: $@' |
| 127 | @rm -f $@ |
| 128 | @mkdir -p $(dir $@) |
| 129 | $(hide) echo -n > $@ |
| 130 | $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so $(ALL_MODULES.$(lib).PATH) >> $@;) |
| 131 | |
| 132 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 133 | vndk_snapshot_configs := \ |
| 134 | $(vndkcore.libraries.txt) \ |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 135 | $(vndkprivate.libraries.txt) \ |
| 136 | $(module_paths.txt) |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 137 | |
| 138 | ####################################### |
| 139 | # vndk_snapshot_zip |
Jae Shin | 893fca6 | 2017-12-28 16:00:10 +0900 | [diff] [blame^] | 140 | vndk_snapshot_variant := $(vndk_snapshot_out)/$(TARGET_ARCH) |
| 141 | vndk_lib_dir := $(vndk_snapshot_variant)/arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT) |
| 142 | vndk_lib_dir_2nd := $(vndk_snapshot_variant)/arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 143 | vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_ARCH).zip |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 144 | |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 145 | $(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out) |
| 146 | |
Jae Shin | 893fca6 | 2017-12-28 16:00:10 +0900 | [diff] [blame^] | 147 | $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_lib_dir)/shared/vndk-core |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 148 | $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \ |
Jae Shin | 77c07dd | 2017-12-22 11:24:00 +0900 | [diff] [blame] | 149 | $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 150 | |
Jae Shin | 893fca6 | 2017-12-28 16:00:10 +0900 | [diff] [blame^] | 151 | $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_lib_dir)/shared/vndk-sp |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 152 | $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \ |
Jae Shin | 77c07dd | 2017-12-22 11:24:00 +0900 | [diff] [blame] | 153 | $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES) |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 154 | |
Jae Shin | 893fca6 | 2017-12-28 16:00:10 +0900 | [diff] [blame^] | 155 | $(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_variant)/configs |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 156 | $(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \ |
Jae Shin | 77c07dd | 2017-12-22 11:24:00 +0900 | [diff] [blame] | 157 | $(call paths-of-intermediates,$(foreach txt,$(vndk_prebuilt_txts), \ |
| 158 | $(txt):$(patsubst %.txt,%.$(PLATFORM_VNDK_VERSION).txt,$(txt))),ETC) \ |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 159 | $(vndk_snapshot_configs) |
| 160 | |
Jae Shin | 893fca6 | 2017-12-28 16:00:10 +0900 | [diff] [blame^] | 161 | $(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_variant)/NOTICE_FILES |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 162 | $(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := \ |
| 163 | $(call paths-of-notice-files,$(vndk_core_libs),vndk) \ |
| 164 | $(call paths-of-notice-files,$(vndk_sp_libs),vndk-sp) |
| 165 | |
Jae Shin | 893fca6 | 2017-12-28 16:00:10 +0900 | [diff] [blame^] | 166 | ifdef TARGET_2ND_ARCH |
| 167 | $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-core |
| 168 | $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \ |
| 169 | $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true) |
| 170 | |
| 171 | $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-sp |
| 172 | $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \ |
| 173 | $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true) |
| 174 | endif |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 175 | |
| 176 | # Args |
| 177 | # $(1): destination directory |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 178 | # $(2): list of files to copy |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 179 | $(vndk_snapshot_zip): private-copy-vndk-intermediates = \ |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 180 | $(if $(2),$(strip \ |
| 181 | @mkdir -p $(1); \ |
| 182 | $(foreach file,$(2), \ |
| 183 | if [ -e $(file) ]; then \ |
| 184 | cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \ |
| 185 | fi; \ |
| 186 | ) \ |
| 187 | )) |
| 188 | |
| 189 | vndk_snapshot_dependencies := \ |
| 190 | $(vndk_snapshot_libs) \ |
| 191 | $(vndk_prebuilt_txts) \ |
| 192 | $(vndk_snapshot_configs) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 193 | |
| 194 | $(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP) |
| 195 | @echo 'Generating VNDK snapshot: $@' |
| 196 | @rm -f $@ |
| 197 | @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT) |
| 198 | @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT) |
| 199 | $(call private-copy-vndk-intermediates, \ |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 200 | $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES)) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 201 | $(call private-copy-vndk-intermediates, \ |
Jae Shin | c13c0ea | 2017-12-04 13:16:21 +0900 | [diff] [blame] | 202 | $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES)) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 203 | $(call private-copy-vndk-intermediates, \ |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 204 | $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES)) |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 205 | $(call private-copy-vndk-intermediates, \ |
| 206 | $(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES)) |
Jae Shin | 893fca6 | 2017-12-28 16:00:10 +0900 | [diff] [blame^] | 207 | ifdef TARGET_2ND_ARCH |
| 208 | $(call private-copy-vndk-intermediates, \ |
| 209 | $(PRIVATE_VNDK_CORE_OUT_2ND),$(PRIVATE_VNDK_CORE_INTERMEDIATES_2ND)) |
| 210 | $(call private-copy-vndk-intermediates, \ |
| 211 | $(PRIVATE_VNDK_SP_OUT_2ND),$(PRIVATE_VNDK_SP_INTERMEDIATES_2ND)) |
| 212 | endif |
Jae Shin | c13c0ea | 2017-12-04 13:16:21 +0900 | [diff] [blame] | 213 | $(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_VNDK_SNAPSHOT_OUT) -D $(PRIVATE_VNDK_SNAPSHOT_OUT) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 214 | |
| 215 | .PHONY: vndk |
| 216 | vndk: $(vndk_snapshot_zip) |
| 217 | |
| 218 | $(call dist-for-goals, vndk, $(vndk_snapshot_zip)) |
| 219 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 220 | # clear global vars |
| 221 | clang-ubsan-vndk-core := |
| 222 | paths-of-intermediates := |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 223 | paths-of-notice-files := |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 224 | vndk_core_libs := |
| 225 | vndk_sp_libs := |
| 226 | vndk_snapshot_libs := |
| 227 | vndk_prebuilt_txts := |
| 228 | vndk_snapshot_configs := |
| 229 | vndk_snapshot_top := |
| 230 | vndk_snapshot_out := |
| 231 | vndk_snapshot_configs_out := |
Jae Shin | 893fca6 | 2017-12-28 16:00:10 +0900 | [diff] [blame^] | 232 | vndk_snapshot_variant := |
| 233 | vndk_lib_dir := |
| 234 | vndk_lib_dir_2nd := |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 235 | vndk_snapshot_dependencies := |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 236 | |
Jae Shin | 0b1792e | 2017-12-21 19:04:13 +0900 | [diff] [blame] | 237 | else # PLATFORM_VNDK_VERSION is NOT set |
| 238 | |
| 239 | .PHONY: vndk |
| 240 | vndk: |
| 241 | $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. PLATFORM_VNDK_VERSION must be set.) |
| 242 | exit 1 |
| 243 | |
| 244 | endif # PLATFORM_VNDK_VERSION |
| 245 | |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 246 | else # BOARD_VNDK_VERSION is NOT set to 'current' |
| 247 | |
| 248 | .PHONY: vndk |
| 249 | vndk: |
| 250 | $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'.) |
| 251 | exit 1 |
| 252 | |
| 253 | endif # BOARD_VNDK_VERSION |