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 include $(BUILD_SYSTEM)/check_elf_file.mk 95 endif 96endif 97 98# The real dependency will be added after all Android.mks are loaded and the install paths 99# of the shared libraries are determined. 100ifdef LOCAL_INSTALLED_MODULE 101 ifdef LOCAL_SHARED_LIBRARIES 102 my_shared_libraries := $(LOCAL_SHARED_LIBRARIES) 103 ifdef LOCAL_USE_VNDK 104 my_shared_libraries := $(foreach l,$(my_shared_libraries),\ 105 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l))) 106 endif 107 $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \ 108 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries)) 109 endif 110endif 111 112my_check_same_vndk_variants := 113ifeq ($(LOCAL_CHECK_SAME_VNDK_VARIANTS),true) 114 ifeq ($(filter hwaddress address, $(SANITIZE_TARGET)),) 115 ifneq ($(CLANG_COVERAGE),true) 116 # Do not compare VNDK variant for special cases e.g. coverage builds. 117 ifneq ($(SKIP_VNDK_VARIANTS_CHECK),true) 118 my_check_same_vndk_variants := true 119 endif 120 endif 121 endif 122endif 123 124ifeq ($(my_check_same_vndk_variants),true) 125 same_vndk_variants_stamp := $(intermediates)/same_vndk_variants.timestamp 126 127 my_core_register_name := $(subst .vendor,,$(subst .product,,$(my_register_name))) 128 my_core_variant_files := $(call module-target-built-files,$(my_core_register_name)) 129 my_core_shared_lib := $(sort $(filter %.so,$(my_core_variant_files))) 130 131 $(same_vndk_variants_stamp): PRIVATE_CORE_VARIANT := $(my_core_shared_lib) 132 $(same_vndk_variants_stamp): PRIVATE_VENDOR_VARIANT := $(LOCAL_PREBUILT_MODULE_FILE) 133 $(same_vndk_variants_stamp): PRIVATE_TOOLS_PREFIX := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX) 134 135 $(same_vndk_variants_stamp): $(my_core_shared_lib) $(LOCAL_PREBUILT_MODULE_FILE) 136 $(call verify-vndk-libs-identical,\ 137 $(PRIVATE_CORE_VARIANT),\ 138 $(PRIVATE_VENDOR_VARIANT),\ 139 $(PRIVATE_TOOLS_PREFIX)) 140 touch $@ 141 142 $(LOCAL_BUILT_MODULE): $(same_vndk_variants_stamp) 143endif 144 145$(LOCAL_BUILT_MODULE): $(LOCAL_PREBUILT_MODULE_FILE) 146 $(transform-prebuilt-to-target) 147ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 148 $(hide) chmod +x $@ 149endif 150 151ifndef LOCAL_IS_HOST_MODULE 152 ifdef LOCAL_SOONG_UNSTRIPPED_BINARY 153 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true) 154 my_symbol_path := $(if $(LOCAL_SOONG_SYMBOL_PATH),$(LOCAL_SOONG_SYMBOL_PATH),$(my_module_path)) 155 # Store a copy with symbols for symbolic debugging 156 my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_symbol_path)) 157 # drop /root as /root is mounted as / 158 my_unstripped_path := $(patsubst $(TARGET_OUT_UNSTRIPPED)/root/%,$(TARGET_OUT_UNSTRIPPED)/%, $(my_unstripped_path)) 159 symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) 160 $(eval $(call copy-one-file,$(LOCAL_SOONG_UNSTRIPPED_BINARY),$(symbolic_output))) 161 $(call add-dependency,$(LOCAL_BUILT_MODULE),$(symbolic_output)) 162 163 ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) 164 my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_symbol_path)) 165 breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym 166 $(breakpad_output) : $(LOCAL_SOONG_UNSTRIPPED_BINARY) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF) 167 @echo "target breakpad: $(PRIVATE_MODULE) ($@)" 168 @mkdir -p $(dir $@) 169 $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \ 170 $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \ 171 else \ 172 echo "skipped for non-elf file."; \ 173 touch $@; \ 174 fi 175 $(call add-dependency,$(LOCAL_BUILT_MODULE),$(breakpad_output)) 176 endif 177 endif 178 endif 179endif 180 181ifeq ($(NATIVE_COVERAGE),true) 182 ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE))) 183 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).zip)) 184 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true) 185 ifdef LOCAL_IS_HOST_MODULE 186 my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path)) 187 else 188 my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 189 endif 190 my_coverage_path := $(my_coverage_path)/$(patsubst %.so,%,$(my_installed_module_stem)).zip 191 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path))) 192 $(LOCAL_BUILT_MODULE): $(my_coverage_path) 193 endif 194 else 195 # Coverage information is needed when static lib is a dependency of another 196 # coverage-enabled module. 197 ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS)) 198 GCNO_ARCHIVE := $(LOCAL_MODULE).zip 199 $(intermediates)/$(GCNO_ARCHIVE) : $(SOONG_ZIP) $(MERGE_ZIPS) 200 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS := 201 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := 202 $(intermediates)/$(GCNO_ARCHIVE) : 203 $(package-coverage-files) 204 endif 205 endif 206endif 207 208# A product may be configured to strip everything in some build variants. 209# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE 210# is still with the symbols and we don't need to clean it (and relink) when 211# you switch build variant. 212ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),) 213$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \ 214 $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE) 215endif 216 217$(LOCAL_BUILT_MODULE): $(LOCAL_ADDITIONAL_DEPENDENCIES) 218 219# We don't care about installed static libraries, since the libraries have 220# already been linked into the module at that point. We do, however, care 221# about the NOTICE files for any static libraries that we use. 222# (see notice_files.mk) 223# 224# Filter out some NDK libraries that are not being exported. 225my_static_libraries := \ 226 $(filter-out ndk_libc++_static ndk_libc++abi ndk_libandroid_support ndk_libunwind \ 227 ndk_libc++_static.native_bridge ndk_libc++abi.native_bridge \ 228 ndk_libandroid_support.native_bridge ndk_libunwind.native_bridge, \ 229 $(LOCAL_STATIC_LIBRARIES)) 230installed_static_library_notice_file_targets := \ 231 $(foreach lib,$(my_static_libraries) $(LOCAL_WHOLE_STATIC_LIBRARIES), \ 232 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST$(if $(my_host_cross),_CROSS,),TARGET)-STATIC_LIBRARIES-$(lib)) 233 234$(notice_target): | $(installed_static_library_notice_file_targets) 235$(LOCAL_INSTALLED_MODULE): | $(notice_target) 236 237# Reinstall shared library dependencies of fuzz targets to /data/fuzz/ (for 238# target) or /data/ (for host). 239ifdef LOCAL_IS_FUZZ_TARGET 240$(LOCAL_INSTALLED_MODULE): $(LOCAL_FUZZ_INSTALLED_SHARED_DEPS) 241endif 242