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