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_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 libraries by default. 35ifndef LOCAL_UNINSTALLABLE_MODULE 36 ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)) 37 LOCAL_UNINSTALLABLE_MODULE := true 38 endif 39endif 40 41# Don't install modules of current VNDK when it is told so 42ifeq ($(TARGET_SKIP_CURRENT_VNDK),true) 43 ifeq ($(LOCAL_SOONG_VNDK_VERSION),$(PLATFORM_VNDK_VERSION)) 44 LOCAL_UNINSTALLABLE_MODULE := true 45 endif 46endif 47 48####################################### 49include $(BUILD_SYSTEM)/base_rules.mk 50####################################### 51 52ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS)),) 53 # Soong module is a static or shared library 54 EXPORTS_LIST += $(intermediates) 55 EXPORTS.$(intermediates).FLAGS := $(LOCAL_EXPORT_CFLAGS) 56 EXPORTS.$(intermediates).DEPS := $(LOCAL_EXPORT_C_INCLUDE_DEPS) 57 58 ifdef LOCAL_SOONG_TOC 59 $(eval $(call copy-one-file,$(LOCAL_SOONG_TOC),$(LOCAL_BUILT_MODULE).toc)) 60 $(call add-dependency,$(LOCAL_BUILT_MODULE).toc,$(LOCAL_BUILT_MODULE)) 61 $(my_all_targets): $(LOCAL_BUILT_MODULE).toc 62 endif 63 64 SOONG_ALREADY_CONV += $(LOCAL_MODULE) 65 66 my_link_type := $(LOCAL_SOONG_LINK_TYPE) 67 my_warn_types := 68 my_allowed_types := 69 my_link_deps := 70 my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 71 my_common := 72 include $(BUILD_SYSTEM)/link_type.mk 73endif 74 75ifdef LOCAL_USE_VNDK 76 ifneq ($(LOCAL_VNDK_DEPEND_ON_CORE_VARIANT),true) 77 name_without_suffix := $(patsubst %.vendor,%,$(LOCAL_MODULE)) 78 ifneq ($(name_without_suffix),$(LOCAL_MODULE)) 79 SPLIT_VENDOR.$(LOCAL_MODULE_CLASS).$(name_without_suffix) := 1 80 else 81 name_without_suffix := $(patsubst %.product,%,$(LOCAL_MODULE)) 82 ifneq ($(name_without_suffix),$(LOCAL_MODULE)) 83 SPLIT_PRODUCT.$(LOCAL_MODULE_CLASS).$(name_without_suffix) := 1 84 endif 85 endif 86 name_without_suffix := 87 endif 88endif 89 90# Check prebuilt ELF binaries. 91ifdef LOCAL_INSTALLED_MODULE 92 ifneq ($(LOCAL_CHECK_ELF_FILES),) 93 my_prebuilt_src_file := $(LOCAL_PREBUILT_MODULE_FILE) 94 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) 95 include $(BUILD_SYSTEM)/check_elf_file.mk 96 endif 97endif 98 99# The real dependency will be added after all Android.mks are loaded and the install paths 100# of the shared libraries are determined. 101ifdef LOCAL_INSTALLED_MODULE 102 ifdef LOCAL_SHARED_LIBRARIES 103 my_shared_libraries := $(LOCAL_SHARED_LIBRARIES) 104 ifdef LOCAL_USE_VNDK 105 my_shared_libraries := $(foreach l,$(my_shared_libraries),\ 106 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l))) 107 endif 108 $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \ 109 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries)) 110 endif 111endif 112 113my_check_same_vndk_variants := 114ifeq ($(LOCAL_CHECK_SAME_VNDK_VARIANTS),true) 115 ifeq ($(filter hwaddress address, $(SANITIZE_TARGET)),) 116 ifneq ($(CLANG_COVERAGE),true) 117 # Do not compare VNDK variant for special cases e.g. coverage builds. 118 ifneq ($(SKIP_VNDK_VARIANTS_CHECK),true) 119 my_check_same_vndk_variants := true 120 endif 121 endif 122 endif 123endif 124 125ifeq ($(my_check_same_vndk_variants),true) 126 same_vndk_variants_stamp := $(intermediates)/same_vndk_variants.timestamp 127 128 my_core_register_name := $(subst .vendor,,$(subst .product,,$(my_register_name))) 129 my_core_variant_files := $(call module-target-built-files,$(my_core_register_name)) 130 my_core_shared_lib := $(sort $(filter %.so,$(my_core_variant_files))) 131 132 $(same_vndk_variants_stamp): PRIVATE_CORE_VARIANT := $(my_core_shared_lib) 133 $(same_vndk_variants_stamp): PRIVATE_VENDOR_VARIANT := $(LOCAL_PREBUILT_MODULE_FILE) 134 $(same_vndk_variants_stamp): PRIVATE_TOOLS_PREFIX := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX) 135 136 $(same_vndk_variants_stamp): $(my_core_shared_lib) $(LOCAL_PREBUILT_MODULE_FILE) 137 $(call verify-vndk-libs-identical,\ 138 $(PRIVATE_CORE_VARIANT),\ 139 $(PRIVATE_VENDOR_VARIANT),\ 140 $(PRIVATE_TOOLS_PREFIX)) 141 touch $@ 142 143 $(LOCAL_BUILT_MODULE): $(same_vndk_variants_stamp) 144endif 145 146# Use copy-or-link-prebuilt-to-target for host executables and shared libraries, 147# to preserve symlinks to the source trees. They can then run directly from the 148# prebuilt directories where the linker can load their dependencies using 149# relative RUNPATHs. 150$(LOCAL_BUILT_MODULE): $(LOCAL_PREBUILT_MODULE_FILE) 151ifeq ($(LOCAL_IS_HOST_MODULE) $(if $(filter EXECUTABLES SHARED_LIBRARIES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),true,),true true) 152 $(copy-or-link-prebuilt-to-target) 153 ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 154 [ -x $@ ] || ( $(call echo-error,$@,Target of symlink is not executable); false ) 155 endif 156else 157 $(transform-prebuilt-to-target) 158 ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 159 $(hide) chmod +x $@ 160 endif 161endif 162 163ifndef LOCAL_IS_HOST_MODULE 164 ifdef LOCAL_SOONG_UNSTRIPPED_BINARY 165 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true) 166 my_symbol_path := $(if $(LOCAL_SOONG_SYMBOL_PATH),$(LOCAL_SOONG_SYMBOL_PATH),$(my_module_path)) 167 # Store a copy with symbols for symbolic debugging 168 my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_symbol_path)) 169 # drop /root as /root is mounted as / 170 my_unstripped_path := $(patsubst $(TARGET_OUT_UNSTRIPPED)/root/%,$(TARGET_OUT_UNSTRIPPED)/%, $(my_unstripped_path)) 171 symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) 172 $(eval $(call copy-one-file,$(LOCAL_SOONG_UNSTRIPPED_BINARY),$(symbolic_output))) 173 $(LOCAL_BUILT_MODULE): | $(symbolic_output) 174 175 ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) 176 my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_symbol_path)) 177 breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym 178 $(breakpad_output) : $(LOCAL_SOONG_UNSTRIPPED_BINARY) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF) 179 @echo "target breakpad: $(PRIVATE_MODULE) ($@)" 180 @mkdir -p $(dir $@) 181 $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \ 182 $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \ 183 else \ 184 echo "skipped for non-elf file."; \ 185 touch $@; \ 186 fi 187 $(call add-dependency,$(LOCAL_BUILT_MODULE),$(breakpad_output)) 188 endif 189 endif 190 endif 191endif 192 193ifeq ($(NATIVE_COVERAGE),true) 194 ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE))) 195 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).zip)) 196 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true) 197 ifdef LOCAL_IS_HOST_MODULE 198 my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path)) 199 else 200 my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 201 endif 202 my_coverage_path := $(my_coverage_path)/$(patsubst %.so,%,$(my_installed_module_stem)).zip 203 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path))) 204 $(LOCAL_BUILT_MODULE): $(my_coverage_path) 205 endif 206 else 207 # Coverage information is needed when static lib is a dependency of another 208 # coverage-enabled module. 209 ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS)) 210 GCNO_ARCHIVE := $(LOCAL_MODULE).zip 211 $(intermediates)/$(GCNO_ARCHIVE) : $(SOONG_ZIP) $(MERGE_ZIPS) 212 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS := 213 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := 214 $(intermediates)/$(GCNO_ARCHIVE) : 215 $(package-coverage-files) 216 endif 217 endif 218endif 219 220# A product may be configured to strip everything in some build variants. 221# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE 222# is still with the symbols and we don't need to clean it (and relink) when 223# you switch build variant. 224ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),) 225$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \ 226 $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE) 227endif 228 229$(LOCAL_BUILT_MODULE): $(LOCAL_ADDITIONAL_DEPENDENCIES) 230 231# We don't care about installed static libraries, since the libraries have 232# already been linked into the module at that point. We do, however, care 233# about the NOTICE files for any static libraries that we use. 234# (see notice_files.mk) 235# 236# Filter out some NDK libraries that are not being exported. 237my_static_libraries := \ 238 $(filter-out ndk_libc++_static ndk_libc++abi ndk_libandroid_support ndk_libunwind \ 239 ndk_libc++_static.native_bridge ndk_libc++abi.native_bridge \ 240 ndk_libandroid_support.native_bridge ndk_libunwind.native_bridge, \ 241 $(LOCAL_STATIC_LIBRARIES)) 242installed_static_library_notice_file_targets := \ 243 $(foreach lib,$(my_static_libraries) $(LOCAL_WHOLE_STATIC_LIBRARIES), \ 244 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST$(if $(my_host_cross),_CROSS,),TARGET)-STATIC_LIBRARIES-$(lib)) 245 246$(notice_target): | $(installed_static_library_notice_file_targets) 247$(LOCAL_INSTALLED_MODULE): | $(notice_target) 248 249# Reinstall shared library dependencies of fuzz targets to /data/fuzz/ (for 250# target) or /data/ (for host). 251ifdef LOCAL_IS_FUZZ_TARGET 252$(LOCAL_INSTALLED_MODULE): $(LOCAL_FUZZ_INSTALLED_SHARED_DEPS) 253endif 254