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 | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 39 | # $(1): list of obj names (e.g., libfoo.vendor, ld.config.txt, ...) |
| 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 \ |
| 44 | $(foreach obj,$(1), \ |
| 45 | $(eval file_name := $(if $(filter SHARED_LIBRARIES,$(2)),$(patsubst %.so,%,$(obj)).so,$(obj))) \ |
| 46 | $(eval dir := $(call intermediates-dir-for,$(2),$(obj),,,$(3))) \ |
| 47 | $(call append-path,$(dir),$(file_name)) \ |
| 48 | ) \ |
| 49 | ) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 50 | endef |
| 51 | |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 52 | # Returns paths of notice files under $(TARGET_OUT_NOTICE_FILES) |
| 53 | # |
| 54 | # Args: |
| 55 | # $(1): list of lib names (e.g., libfoo.vendor) |
| 56 | # $(2): vndk lib type, one of 'vndk' or 'vndk-sp' |
| 57 | define paths-of-notice-files |
| 58 | $(strip \ |
| 59 | $(eval lib_dir := lib$(if $(TARGET_IS_64BIT),64,)) \ |
| 60 | $(eval vndk_dir := $(2)-$(PLATFORM_VNDK_VERSION)) \ |
| 61 | $(foreach lib,$(1), \ |
| 62 | $(eval notice_file_name := $(patsubst %.vendor,%.so.txt,$(lib))) \ |
| 63 | $(TARGET_OUT_NOTICE_FILES)/src/system/$(lib_dir)/$(vndk_dir)/$(notice_file_name) \ |
| 64 | ) \ |
| 65 | ) |
| 66 | endef |
| 67 | |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 68 | # If in the future libclang_rt.ubsan* is removed from the VNDK-core list, |
| 69 | # need to update the related logic in this file. |
| 70 | ifeq (,$(filter libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES))) |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 71 | $(warning libclang_rt.ubsan* is no longer a VNDK-core library. Please update this file.) |
| 72 | vndk_core_libs := $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES)) |
| 73 | else |
| 74 | vndk_core_libs := $(addsuffix .vendor,$(filter-out libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES))) |
| 75 | |
| 76 | # for TARGET_ARCH |
| 77 | vndk_core_libs += $(call clang-ubsan-vndk-core) |
| 78 | |
| 79 | # TODO(b/69834489): Package additional arch variants |
| 80 | # ifdef TARGET_2ND_ARCH |
| 81 | # vndk_core_libs += $(call clang-ubsan-vndk-core,true) |
| 82 | # endif |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 83 | endif |
| 84 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 85 | vndk_sp_libs := $(addsuffix .vendor,$(VNDK_SAMEPROCESS_LIBRARIES)) |
| 86 | vndk_private_libs := $(addsuffix .vendor,$(VNDK_PRIVATE_LIBRARIES)) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 87 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 88 | vndk_snapshot_libs := \ |
| 89 | $(vndk_core_libs) \ |
| 90 | $(vndk_sp_libs) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 91 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 92 | vndk_prebuilt_txts := \ |
| 93 | ld.config.txt \ |
| 94 | vndksp.libraries.txt \ |
| 95 | llndk.libraries.txt |
| 96 | |
| 97 | vndk_snapshot_top := $(call intermediates-dir-for,PACKAGING,vndk-snapshot) |
| 98 | vndk_snapshot_out := $(vndk_snapshot_top)/vndk-snapshot |
| 99 | vndk_snapshot_configs_out := $(vndk_snapshot_top)/configs |
| 100 | |
| 101 | ####################################### |
| 102 | # vndkcore.libraries.txt |
| 103 | vndkcore.libraries.txt := $(vndk_snapshot_configs_out)/vndkcore.libraries.txt |
| 104 | $(vndkcore.libraries.txt): $(vndk_core_libs) |
| 105 | @echo 'Generating: $@' |
| 106 | @rm -f $@ |
| 107 | @mkdir -p $(dir $@) |
| 108 | $(hide) echo -n > $@ |
| 109 | $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;) |
| 110 | |
| 111 | |
| 112 | ####################################### |
| 113 | # vndkprivate.libraries.txt |
| 114 | vndkprivate.libraries.txt := $(vndk_snapshot_configs_out)/vndkprivate.libraries.txt |
| 115 | $(vndkprivate.libraries.txt): $(vndk_private_libs) |
| 116 | @echo 'Generating: $@' |
| 117 | @rm -f $@ |
| 118 | @mkdir -p $(dir $@) |
| 119 | $(hide) echo -n > $@ |
| 120 | $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;) |
| 121 | |
| 122 | |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 123 | ####################################### |
| 124 | # module_paths.txt |
| 125 | module_paths.txt := $(vndk_snapshot_configs_out)/module_paths.txt |
| 126 | $(module_paths.txt): $(vndk_snapshot_libs) |
| 127 | @echo 'Generating: $@' |
| 128 | @rm -f $@ |
| 129 | @mkdir -p $(dir $@) |
| 130 | $(hide) echo -n > $@ |
| 131 | $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so $(ALL_MODULES.$(lib).PATH) >> $@;) |
| 132 | |
| 133 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 134 | vndk_snapshot_configs := \ |
| 135 | $(vndkcore.libraries.txt) \ |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 136 | $(vndkprivate.libraries.txt) \ |
| 137 | $(module_paths.txt) |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 138 | |
| 139 | ####################################### |
| 140 | # vndk_snapshot_zip |
| 141 | vndk_snapshot_arch := $(vndk_snapshot_out)/arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 142 | vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_ARCH).zip |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 143 | |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 144 | $(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out) |
| 145 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 146 | $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_snapshot_arch)/shared/vndk-core |
| 147 | $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \ |
| 148 | $(call paths-of-intermediates,$(vndk_core_libs),SHARED_LIBRARIES) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 149 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 150 | $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_snapshot_arch)/shared/vndk-sp |
| 151 | $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \ |
| 152 | $(call paths-of-intermediates,$(vndk_sp_libs),SHARED_LIBRARIES) |
| 153 | |
| 154 | $(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_arch)/configs |
| 155 | $(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \ |
| 156 | $(call paths-of-intermediates,$(vndk_prebuilt_txts),ETC) \ |
| 157 | $(vndk_snapshot_configs) |
| 158 | |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 159 | $(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_arch)/NOTICE_FILES |
| 160 | $(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := \ |
| 161 | $(call paths-of-notice-files,$(vndk_core_libs),vndk) \ |
| 162 | $(call paths-of-notice-files,$(vndk_sp_libs),vndk-sp) |
| 163 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 164 | # TODO(b/69834489): Package additional arch variants |
| 165 | # ifdef TARGET_2ND_ARCH |
| 166 | # vndk_snapshot_arch_2ND := $(vndk_snapshot_out)/arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT) |
| 167 | # $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-core |
| 168 | # $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \ |
| 169 | # $(call paths-of-intermediates,$(vndk_core_libs),SHARED_LIBRARIES,true) |
| 170 | # $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-sp |
| 171 | # $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \ |
| 172 | # $(call paths-of-intermediates,$(vndk_sp_libs),SHARED_LIBRARIES,true) |
| 173 | # endif |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 174 | |
| 175 | # Args |
| 176 | # $(1): destination directory |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 177 | # $(2): list of files to copy |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 178 | $(vndk_snapshot_zip): private-copy-vndk-intermediates = \ |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 179 | $(if $(2),$(strip \ |
| 180 | @mkdir -p $(1); \ |
| 181 | $(foreach file,$(2), \ |
| 182 | if [ -e $(file) ]; then \ |
| 183 | cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \ |
| 184 | fi; \ |
| 185 | ) \ |
| 186 | )) |
| 187 | |
| 188 | vndk_snapshot_dependencies := \ |
| 189 | $(vndk_snapshot_libs) \ |
| 190 | $(vndk_prebuilt_txts) \ |
| 191 | $(vndk_snapshot_configs) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 192 | |
| 193 | $(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP) |
| 194 | @echo 'Generating VNDK snapshot: $@' |
| 195 | @rm -f $@ |
| 196 | @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT) |
| 197 | @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT) |
| 198 | $(call private-copy-vndk-intermediates, \ |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 199 | $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES)) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 200 | $(call private-copy-vndk-intermediates, \ |
Jae Shin | c13c0ea | 2017-12-04 13:16:21 +0900 | [diff] [blame] | 201 | $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES)) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 202 | $(call private-copy-vndk-intermediates, \ |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 203 | $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES)) |
Jae Shin | 410a1af | 2017-12-15 19:35:16 +0900 | [diff] [blame] | 204 | $(call private-copy-vndk-intermediates, \ |
| 205 | $(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES)) |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 206 | # TODO(b/69834489): Package additional arch variants |
| 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 := |
| 232 | vndk_snapshot_arch := |
| 233 | vndk_snapshot_dependencies := |
| 234 | # TODO(b/69834489): Package additional arch variants |
| 235 | # ifdef TARGET_2ND_ARCH |
| 236 | # vndk_snapshot_arch_2ND := |
| 237 | # endif |
| 238 | |
Jae Shin | 0b1792e | 2017-12-21 19:04:13 +0900 | [diff] [blame^] | 239 | else # PLATFORM_VNDK_VERSION is NOT set |
| 240 | |
| 241 | .PHONY: vndk |
| 242 | vndk: |
| 243 | $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. PLATFORM_VNDK_VERSION must be set.) |
| 244 | exit 1 |
| 245 | |
| 246 | endif # PLATFORM_VNDK_VERSION |
| 247 | |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 248 | else # BOARD_VNDK_VERSION is NOT set to 'current' |
| 249 | |
| 250 | .PHONY: vndk |
| 251 | vndk: |
| 252 | $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'.) |
| 253 | exit 1 |
| 254 | |
| 255 | endif # BOARD_VNDK_VERSION |