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 20 # PLATFORM_VNDK_VERSION must be set. 21 ifneq (,$(PLATFORM_VNDK_VERSION)) 22 23 # BOARD_VNDK_RUNTIME_DISABLE must not be set to 'true'. 24 ifneq ($(BOARD_VNDK_RUNTIME_DISABLE),true) 25 26 # 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 32 define clang-ubsan-vndk-core 33 $(strip \ 34 $(eval prefix := $(if $(1),2ND_,)) \ 35 $(addsuffix .vendor,$($(addprefix $(prefix),UBSAN_RUNTIME_LIBRARY))) \ 36 ) 37 endef 38 39 # Returns list of file paths of the intermediate objs 40 # 41 # Args: 42 # $(1): list of module and filename pairs (e.g., ld.config.txt:ld.config.27.txt ...) 43 # $(2): target class (e.g., SHARED_LIBRARIES, STATIC_LIBRARIES, ETC) 44 # $(3): if not empty, evaluates for TARGET_2ND_ARCH 45 define paths-of-intermediates 46 $(strip \ 47 $(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)) \ 53 ) \ 54 ) 55 endef 56 57 # 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' 62 define 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 ) 71 endef 72 73 # If in the future libclang_rt.ubsan* is removed from the VNDK-core list, 74 # need to update the related logic in this file. 75 ifeq (,$(filter libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES))) 76 $(warning libclang_rt.ubsan* is no longer a VNDK-core library. Please update this file.) 77 vndk_core_libs := $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES)) 78 else 79 vndk_core_libs := $(addsuffix .vendor,$(filter-out libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES))) 80 81 vndk_core_libs += $(call clang-ubsan-vndk-core) 82 ifdef TARGET_2ND_ARCH 83 vndk_core_libs += $(call clang-ubsan-vndk-core,true) 84 endif 85 endif 86 87 vndk_sp_libs := $(addsuffix .vendor,$(VNDK_SAMEPROCESS_LIBRARIES)) 88 vndk_private_libs := $(addsuffix .vendor,$(VNDK_PRIVATE_LIBRARIES)) 89 90 vndk_snapshot_libs := \ 91 $(vndk_core_libs) \ 92 $(vndk_sp_libs) 93 94 vndk_prebuilt_txts := \ 95 ld.config.txt \ 96 vndksp.libraries.txt \ 97 llndk.libraries.txt 98 99 vndk_snapshot_top := $(call intermediates-dir-for,PACKAGING,vndk-snapshot) 100 vndk_snapshot_out := $(vndk_snapshot_top)/vndk-snapshot 101 vndk_snapshot_configs_out := $(vndk_snapshot_top)/configs 102 103 ####################################### 104 # vndkcore.libraries.txt 105 vndkcore.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 116 vndkprivate.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 125 ####################################### 126 # module_paths.txt 127 module_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 136 vndk_snapshot_configs := \ 137 $(vndkcore.libraries.txt) \ 138 $(vndkprivate.libraries.txt) \ 139 $(module_paths.txt) 140 141 ####################################### 142 # vndk_snapshot_zip 143 vndk_snapshot_variant := $(vndk_snapshot_out)/$(TARGET_ARCH) 144 binder := 145 ifneq ($(TARGET_USES_64_BIT_BINDER), true) 146 binder := binder32 147 endif 148 vndk_lib_dir := $(subst $(space),/,$(strip $(vndk_snapshot_variant) $(binder) arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT))) 149 vndk_lib_dir_2nd := $(subst $(space),/,$(strip $(vndk_snapshot_variant) $(binder) arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT))) 150 vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_PRODUCT).zip 151 152 $(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out) 153 154 $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_lib_dir)/shared/vndk-core 155 $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \ 156 $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES) 157 158 $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_lib_dir)/shared/vndk-sp 159 $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \ 160 $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES) 161 162 $(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_variant)/configs 163 $(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \ 164 $(call paths-of-intermediates,$(foreach txt,$(vndk_prebuilt_txts), \ 165 $(txt):$(patsubst %.txt,%.$(PLATFORM_VNDK_VERSION).txt,$(txt))),ETC) \ 166 $(vndk_snapshot_configs) 167 168 $(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_OUT := $(vndk_snapshot_variant)/NOTICE_FILES 169 $(vndk_snapshot_zip): PRIVATE_NOTICE_FILES_INTERMEDIATES := \ 170 $(call paths-of-notice-files,$(vndk_core_libs),vndk) \ 171 $(call paths-of-notice-files,$(vndk_sp_libs),vndk-sp) 172 173 ifdef TARGET_2ND_ARCH 174 $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-core 175 $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \ 176 $(call paths-of-intermediates,$(foreach lib,$(vndk_core_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true) 177 178 $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_lib_dir_2nd)/shared/vndk-sp 179 $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \ 180 $(call paths-of-intermediates,$(foreach lib,$(vndk_sp_libs),$(lib):$(lib).so),SHARED_LIBRARIES,true) 181 endif 182 183 # Args 184 # $(1): destination directory 185 # $(2): list of files to copy 186 $(vndk_snapshot_zip): private-copy-vndk-intermediates = \ 187 $(if $(2),$(strip \ 188 @mkdir -p $(1); \ 189 $(foreach file,$(2), \ 190 if [ -e $(file) ]; then \ 191 cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \ 192 fi; \ 193 ) \ 194 )) 195 196 vndk_snapshot_dependencies := \ 197 $(vndk_snapshot_libs) \ 198 $(vndk_prebuilt_txts) \ 199 $(vndk_snapshot_configs) 200 201 $(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP) 202 @echo 'Generating VNDK snapshot: $@' 203 @rm -f $@ 204 @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT) 205 @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT) 206 $(call private-copy-vndk-intermediates, \ 207 $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES)) 208 $(call private-copy-vndk-intermediates, \ 209 $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES)) 210 $(call private-copy-vndk-intermediates, \ 211 $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES)) 212 $(call private-copy-vndk-intermediates, \ 213 $(PRIVATE_NOTICE_FILES_OUT),$(PRIVATE_NOTICE_FILES_INTERMEDIATES)) 214 ifdef TARGET_2ND_ARCH 215 $(call private-copy-vndk-intermediates, \ 216 $(PRIVATE_VNDK_CORE_OUT_2ND),$(PRIVATE_VNDK_CORE_INTERMEDIATES_2ND)) 217 $(call private-copy-vndk-intermediates, \ 218 $(PRIVATE_VNDK_SP_OUT_2ND),$(PRIVATE_VNDK_SP_INTERMEDIATES_2ND)) 219 endif 220 $(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_VNDK_SNAPSHOT_OUT) -D $(PRIVATE_VNDK_SNAPSHOT_OUT) 221 222 .PHONY: vndk 223 vndk: $(vndk_snapshot_zip) 224 225 $(call dist-for-goals, vndk, $(vndk_snapshot_zip)) 226 227 # clear global vars 228 clang-ubsan-vndk-core := 229 paths-of-intermediates := 230 paths-of-notice-files := 231 vndk_core_libs := 232 vndk_sp_libs := 233 vndk_snapshot_libs := 234 vndk_prebuilt_txts := 235 vndk_snapshot_configs := 236 vndk_snapshot_top := 237 vndk_snapshot_out := 238 vndk_snapshot_configs_out := 239 vndk_snapshot_variant := 240 binder := 241 vndk_lib_dir := 242 vndk_lib_dir_2nd := 243 vndk_snapshot_dependencies := 244 245 else # BOARD_VNDK_RUNTIME_DISABLE is set to 'true' 246 error_msg := "CANNOT generate VNDK snapshot. BOARD_VNDK_RUNTIME_DISABLE must not be set to 'true'." 247 endif # BOARD_VNDK_RUNTIME_DISABLE 248 249 else # PLATFORM_VNDK_VERSION is NOT set 250 error_msg := "CANNOT generate VNDK snapshot. PLATFORM_VNDK_VERSION must be set." 251 endif # PLATFORM_VNDK_VERSION 252 253 else # BOARD_VNDK_VERSION is NOT set to 'current' 254 error_msg := "CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'." 255 endif # BOARD_VNDK_VERSION 256 257 ifneq (,$(error_msg)) 258 259 .PHONY: vndk 260 vndk: 261 $(call echo-error,$(current_makefile),$(error_msg)) 262 exit 1 263 264 endif 265