1# Native prebuilt coming from Soong. 2# Extra inputs: 3# LOCAL_SOONG_LINK_TYPE 4# LOCAL_SOONG_TOC 5# LOCAL_SOONG_UNSTRIPPED_BINARY 6# LOCAL_SOONG_VNDK_VERSION : means the version of VNDK where this module belongs 7 8ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK)) 9 $(call pretty-error,soong_cc_rust_prebuilt.mk may only be used from Soong) 10endif 11 12ifdef LOCAL_IS_HOST_MODULE 13 ifneq ($(HOST_OS),$(LOCAL_MODULE_HOST_OS)) 14 my_prefix := HOST_CROSS_ 15 LOCAL_HOST_PREFIX := $(my_prefix) 16 else 17 my_prefix := HOST_ 18 LOCAL_HOST_PREFIX := 19 endif 20else 21 my_prefix := TARGET_ 22endif 23 24ifeq ($($(my_prefix)ARCH),$(LOCAL_MODULE_$(my_prefix)ARCH)) 25 # primary arch 26 LOCAL_2ND_ARCH_VAR_PREFIX := 27else ifeq ($($(my_prefix)2ND_ARCH),$(LOCAL_MODULE_$(my_prefix)ARCH)) 28 # secondary arch 29 LOCAL_2ND_ARCH_VAR_PREFIX := $($(my_prefix)2ND_ARCH_VAR_PREFIX) 30else 31 $(call pretty-error,Unsupported LOCAL_MODULE_$(my_prefix)ARCH=$(LOCAL_MODULE_$(my_prefix)ARCH)) 32endif 33 34# Don't install static/rlib/proc_macro libraries. 35ifndef LOCAL_UNINSTALLABLE_MODULE 36 ifneq ($(filter STATIC_LIBRARIES RLIB_LIBRARIES PROC_MACRO_LIBRARIES,$(LOCAL_MODULE_CLASS)),) 37 LOCAL_UNINSTALLABLE_MODULE := true 38 endif 39endif 40 41# Use the Soong output as the checkbuild target instead of LOCAL_BUILT_MODULE 42# to avoid checkbuilds making an extra copy of every module. 43LOCAL_CHECKED_MODULE := $(LOCAL_PREBUILT_MODULE_FILE) 44 45my_check_same_vndk_variants := 46same_vndk_variants_stamp := 47ifeq ($(LOCAL_CHECK_SAME_VNDK_VARIANTS),true) 48 ifeq ($(filter hwaddress address, $(SANITIZE_TARGET)),) 49 ifneq ($(CLANG_COVERAGE),true) 50 # Do not compare VNDK variant for special cases e.g. coverage builds. 51 ifneq ($(SKIP_VNDK_VARIANTS_CHECK),true) 52 my_check_same_vndk_variants := true 53 same_vndk_variants_stamp := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX))/same_vndk_variants.timestamp 54 endif 55 endif 56 endif 57endif 58 59ifeq ($(my_check_same_vndk_variants),true) 60 # Add the timestamp to the CHECKED list so that `checkbuild` can run it. 61 # Note that because `checkbuild` doesn't check LOCAL_BUILT_MODULE for soong-built modules adding 62 # the timestamp to LOCAL_BUILT_MODULE isn't enough. It is skipped when the vendor variant 63 # isn't used at all and it may break in the downstream trees. 64 LOCAL_ADDITIONAL_CHECKED_MODULE := $(same_vndk_variants_stamp) 65endif 66 67####################################### 68include $(BUILD_SYSTEM)/base_rules.mk 69####################################### 70 71ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES RLIB_LIBRARIES DYLIB_LIBRARIES HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS)),) 72 # Soong module is a static or shared library 73 EXPORTS_LIST += $(intermediates) 74 EXPORTS.$(intermediates).FLAGS := $(LOCAL_EXPORT_CFLAGS) 75 EXPORTS.$(intermediates).DEPS := $(LOCAL_EXPORT_C_INCLUDE_DEPS) 76 77 ifdef LOCAL_SOONG_TOC 78 $(eval $(call copy-one-file,$(LOCAL_SOONG_TOC),$(LOCAL_BUILT_MODULE).toc)) 79 $(call add-dependency,$(LOCAL_BUILT_MODULE).toc,$(LOCAL_BUILT_MODULE)) 80 $(my_all_targets): $(LOCAL_BUILT_MODULE).toc 81 endif 82 83 SOONG_ALREADY_CONV += $(LOCAL_MODULE) 84 85 my_link_type := $(LOCAL_SOONG_LINK_TYPE) 86 my_warn_types := 87 my_allowed_types := 88 my_link_deps := 89 my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 90 my_common := 91 include $(BUILD_SYSTEM)/link_type.mk 92endif 93 94ifeq ($(call module-in-vendor-or-product),true) 95 ifneq ($(LOCAL_VNDK_DEPEND_ON_CORE_VARIANT),true) 96 name_without_suffix := $(patsubst %.vendor,%,$(LOCAL_MODULE)) 97 ifneq ($(name_without_suffix),$(LOCAL_MODULE)) 98 SPLIT_VENDOR.$(LOCAL_MODULE_CLASS).$(name_without_suffix) := 1 99 else 100 name_without_suffix := $(patsubst %.product,%,$(LOCAL_MODULE)) 101 ifneq ($(name_without_suffix),$(LOCAL_MODULE)) 102 SPLIT_PRODUCT.$(LOCAL_MODULE_CLASS).$(name_without_suffix) := 1 103 endif 104 endif 105 name_without_suffix := 106 endif 107endif 108 109# Check prebuilt ELF binaries. 110ifdef LOCAL_INSTALLED_MODULE 111 ifneq ($(LOCAL_CHECK_ELF_FILES),) 112 my_prebuilt_src_file := $(LOCAL_PREBUILT_MODULE_FILE) 113 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) 114 include $(BUILD_SYSTEM)/check_elf_file.mk 115 endif 116endif 117 118# The real dependency will be added after all Android.mks are loaded and the install paths 119# of the shared libraries are determined. 120ifdef LOCAL_INSTALLED_MODULE 121 ifdef LOCAL_SHARED_LIBRARIES 122 my_shared_libraries := $(LOCAL_SHARED_LIBRARIES) 123 ifeq ($(call module-in-vendor-or-product),true) 124 ifdef LOCAL_IN_PRODUCT 125 my_shared_libraries := $(foreach l,$(my_shared_libraries),\ 126 $(if $(SPLIT_PRODUCT.SHARED_LIBRARIES.$(l)),$(l).product,$(l))) 127 else 128 my_shared_libraries := $(foreach l,$(my_shared_libraries),\ 129 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l))) 130 endif 131 endif 132 $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \ 133 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries)) 134 endif 135 ifdef LOCAL_DYLIB_LIBRARIES 136 my_dylibs := $(LOCAL_DYLIB_LIBRARIES) 137 # Treat these as shared library dependencies for installation purposes. 138 ifeq ($(call module-in-vendor-or-product),true) 139 ifdef LOCAL_IN_PRODUCT 140 my_dylibs := $(foreach l,$(my_dylibs),\ 141 $(if $(SPLIT_PRODUCT.SHARED_LIBRARIES.$(l)),$(l).product,$(l))) 142 else 143 my_dylibs := $(foreach l,$(my_dylibs),\ 144 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l))) 145 endif 146 endif 147 $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \ 148 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_dylibs)) 149 endif 150endif 151 152ifeq ($(my_check_same_vndk_variants),true) 153 my_core_register_name := $(subst .vendor,,$(subst .product,,$(my_register_name))) 154 my_core_variant_files := $(call module-target-built-files,$(my_core_register_name)) 155 my_core_shared_lib := $(sort $(filter %.so,$(my_core_variant_files))) 156 157 $(same_vndk_variants_stamp): PRIVATE_CORE_VARIANT := $(my_core_shared_lib) 158 $(same_vndk_variants_stamp): PRIVATE_VENDOR_VARIANT := $(LOCAL_PREBUILT_MODULE_FILE) 159 $(same_vndk_variants_stamp): PRIVATE_TOOLS_PREFIX := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX) 160 161 $(same_vndk_variants_stamp): $(my_core_shared_lib) $(LOCAL_PREBUILT_MODULE_FILE) 162 $(call verify-vndk-libs-identical,\ 163 $(PRIVATE_CORE_VARIANT),\ 164 $(PRIVATE_VENDOR_VARIANT),\ 165 $(PRIVATE_TOOLS_PREFIX)) 166 touch $@ 167 168 $(LOCAL_BUILT_MODULE): $(same_vndk_variants_stamp) 169endif 170 171# Use copy-or-link-prebuilt-to-target for host executables and shared libraries, 172# to preserve symlinks to the source trees. They can then run directly from the 173# prebuilt directories where the linker can load their dependencies using 174# relative RUNPATHs. 175$(LOCAL_BUILT_MODULE): $(LOCAL_PREBUILT_MODULE_FILE) 176ifeq ($(LOCAL_IS_HOST_MODULE) $(if $(filter EXECUTABLES SHARED_LIBRARIES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),true,),true true) 177 $(copy-or-link-prebuilt-to-target) 178 ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 179 [ -x $@ ] || ( $(call echo-error,$@,Target of symlink is not executable); false ) 180 endif 181else 182 $(transform-prebuilt-to-target) 183 ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 184 $(hide) chmod +x $@ 185 endif 186endif 187 188ifndef LOCAL_IS_HOST_MODULE 189 ifdef LOCAL_SOONG_UNSTRIPPED_BINARY 190 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true) 191 my_symbol_path := $(if $(LOCAL_SOONG_SYMBOL_PATH),$(LOCAL_SOONG_SYMBOL_PATH),$(my_module_path)) 192 # Store a copy with symbols for symbolic debugging 193 my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_symbol_path)) 194 # drop /root as /root is mounted as / 195 my_unstripped_path := $(patsubst $(TARGET_OUT_UNSTRIPPED)/root/%,$(TARGET_OUT_UNSTRIPPED)/%, $(my_unstripped_path)) 196 symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) 197 $(eval $(call copy-unstripped-elf-file-with-mapping,$(LOCAL_SOONG_UNSTRIPPED_BINARY),$(symbolic_output))) 198 $(LOCAL_BUILT_MODULE): | $(symbolic_output) 199 200 ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) 201 my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_symbol_path)) 202 breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym 203 $(breakpad_output) : $(LOCAL_SOONG_UNSTRIPPED_BINARY) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF) 204 @echo "target breakpad: $(PRIVATE_MODULE) ($@)" 205 @mkdir -p $(dir $@) 206 $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \ 207 $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \ 208 else \ 209 echo "skipped for non-elf file."; \ 210 touch $@; \ 211 fi 212 $(call add-dependency,$(LOCAL_BUILT_MODULE),$(breakpad_output)) 213 endif 214 endif 215 endif 216endif 217 218ifeq ($(NATIVE_COVERAGE),true) 219 ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE))) 220 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).zip)) 221 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true) 222 ifdef LOCAL_IS_HOST_MODULE 223 my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path)) 224 else 225 my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 226 endif 227 my_coverage_path := $(my_coverage_path)/$(patsubst %.so,%,$(my_installed_module_stem)).zip 228 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path))) 229 $(LOCAL_BUILT_MODULE): $(my_coverage_path) 230 endif 231 else 232 # Coverage information is needed when static lib is a dependency of another 233 # coverage-enabled module. 234 ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS)) 235 GCNO_ARCHIVE := $(LOCAL_MODULE).zip 236 $(intermediates)/$(GCNO_ARCHIVE) : $(SOONG_ZIP) $(MERGE_ZIPS) 237 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS := 238 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := 239 $(intermediates)/$(GCNO_ARCHIVE) : 240 $(package-coverage-files) 241 endif 242 endif 243endif 244 245# A product may be configured to strip everything in some build variants. 246# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE 247# is still with the symbols and we don't need to clean it (and relink) when 248# you switch build variant. 249ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),) 250$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \ 251 $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE) 252endif 253 254$(LOCAL_BUILT_MODULE): $(LOCAL_ADDITIONAL_DEPENDENCIES) 255 256# Reinstall shared library dependencies of fuzz targets to /data/fuzz/ (for 257# target) or /data/ (for host). 258ifdef LOCAL_IS_FUZZ_TARGET 259$(LOCAL_INSTALLED_MODULE): $(LOCAL_FUZZ_INSTALLED_SHARED_DEPS) 260endif 261