1# Native prebuilt coming from Soong.
2# Extra inputs:
3# LOCAL_SOONG_LINK_TYPE
4# LOCAL_SOONG_TOC
5# LOCAL_SOONG_UNSTRIPPED_BINARY
6
7ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
8  $(call pretty-error,soong_cc_prebuilt.mk may only be used from Soong)
9endif
10
11ifdef LOCAL_IS_HOST_MODULE
12  ifneq ($(HOST_OS),$(LOCAL_MODULE_HOST_OS))
13    my_prefix := HOST_CROSS_
14    LOCAL_HOST_PREFIX := $(my_prefix)
15  else
16    my_prefix := HOST_
17    LOCAL_HOST_PREFIX :=
18  endif
19else
20  my_prefix := TARGET_
21endif
22
23ifeq ($($(my_prefix)ARCH),$(LOCAL_MODULE_$(my_prefix)ARCH))
24  # primary arch
25  LOCAL_2ND_ARCH_VAR_PREFIX :=
26else ifeq ($($(my_prefix)2ND_ARCH),$(LOCAL_MODULE_$(my_prefix)ARCH))
27  # secondary arch
28  LOCAL_2ND_ARCH_VAR_PREFIX := $($(my_prefix)2ND_ARCH_VAR_PREFIX)
29else
30  $(call pretty-error,Unsupported LOCAL_MODULE_$(my_prefix)ARCH=$(LOCAL_MODULE_$(my_prefix)ARCH))
31endif
32
33skip_module :=
34ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true)
35  ifndef LOCAL_IS_HOST_MODULE
36    ifdef LOCAL_2ND_ARCH_VAR_PREFIX
37      # Only support shared and static libraries and tests for translated arch
38      ifeq ($(filter SHARED_LIBRARIES STATIC_LIBRARIES HEADER_LIBRARIES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
39        skip_module := true
40      endif
41    endif
42  endif
43endif
44
45ifndef skip_module
46
47# Don't install static libraries by default.
48ifndef LOCAL_UNINSTALLABLE_MODULE
49  ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS))
50    LOCAL_UNINSTALLABLE_MODULE := true
51  endif
52endif
53
54#######################################
55include $(BUILD_SYSTEM)/base_rules.mk
56#######################################
57
58ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
59  # Soong module is a static or shared library
60  export_includes := $(intermediates)/export_includes
61  $(export_includes): PRIVATE_EXPORT_CFLAGS := $(LOCAL_EXPORT_CFLAGS)
62  $(export_includes): $(LOCAL_EXPORT_C_INCLUDE_DEPS)
63	@echo Export includes file: $< -- $@
64	$(hide) mkdir -p $(dir $@) && rm -f $@
65  ifdef LOCAL_EXPORT_CFLAGS
66	$(hide) echo "$(PRIVATE_EXPORT_CFLAGS)" >$@
67  else
68	$(hide) touch $@
69  endif
70
71  ifdef LOCAL_SOONG_TOC
72    $(eval $(call copy-one-file,$(LOCAL_SOONG_TOC),$(LOCAL_BUILT_MODULE).toc))
73    $(call add-dependency,$(LOCAL_BUILT_MODULE).toc,$(LOCAL_BUILT_MODULE))
74    $(my_all_targets): $(LOCAL_BUILT_MODULE).toc
75  endif
76
77  SOONG_ALREADY_CONV := $(SOONG_ALREADY_CONV) $(LOCAL_MODULE)
78
79  my_link_type := $(LOCAL_SOONG_LINK_TYPE)
80  my_warn_types :=
81  my_allowed_types :=
82  my_link_deps :=
83  my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
84  my_common :=
85  include $(BUILD_SYSTEM)/link_type.mk
86endif
87
88ifdef LOCAL_USE_VNDK
89  ifneq ($(LOCAL_VNDK_DEPEND_ON_CORE_VARIANT),true)
90    name_without_suffix := $(patsubst %.vendor,%,$(LOCAL_MODULE))
91    ifneq ($(name_without_suffix),$(LOCAL_MODULE)
92      SPLIT_VENDOR.$(LOCAL_MODULE_CLASS).$(name_without_suffix) := 1
93    endif
94    name_without_suffix :=
95  endif
96endif
97
98# Check prebuilt ELF binaries.
99ifneq ($(LOCAL_CHECK_ELF_FILES),)
100my_prebuilt_src_file := $(LOCAL_PREBUILT_MODULE_FILE)
101include $(BUILD_SYSTEM)/check_elf_file.mk
102endif
103
104# The real dependency will be added after all Android.mks are loaded and the install paths
105# of the shared libraries are determined.
106ifdef LOCAL_INSTALLED_MODULE
107  ifdef LOCAL_SHARED_LIBRARIES
108    my_shared_libraries := $(LOCAL_SHARED_LIBRARIES)
109    ifdef LOCAL_USE_VNDK
110      my_shared_libraries := $(foreach l,$(my_shared_libraries),\
111        $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
112    endif
113    $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
114      $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries))
115  endif
116endif
117
118ifeq ($(LOCAL_VNDK_DEPEND_ON_CORE_VARIANT),true)
119  # Add $(LOCAL_BUILT_MODULE) as a dependency to no_vendor_variant_vndk_check so
120  # that the vendor variant will be built and checked against the core variant.
121  no_vendor_variant_vndk_check: $(LOCAL_BUILT_MODULE)
122
123  my_core_register_name := $(subst .vendor,,$(my_register_name))
124  my_core_variant_files := $(call module-target-built-files,$(my_core_register_name))
125  my_core_shared_lib := $(sort $(filter %.so,$(my_core_variant_files)))
126  $(LOCAL_BUILT_MODULE): PRIVATE_CORE_VARIANT := $(my_core_shared_lib)
127
128  # The built vendor variant library needs to depend on the built core variant
129  # so that we can perform identity check against the core variant.
130  $(LOCAL_BUILT_MODULE): $(my_core_shared_lib)
131endif
132
133ifeq ($(LOCAL_VNDK_DEPEND_ON_CORE_VARIANT),true)
134$(LOCAL_BUILT_MODULE): $(LOCAL_PREBUILT_MODULE_FILE) $(LIBRARY_IDENTITY_CHECK_SCRIPT)
135	$(call verify-vndk-libs-identical,\
136		$(PRIVATE_CORE_VARIANT),\
137		$<,\
138		$($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX))
139	$(copy-file-to-target)
140else
141$(LOCAL_BUILT_MODULE): $(LOCAL_PREBUILT_MODULE_FILE)
142	$(transform-prebuilt-to-target)
143endif
144ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
145	$(hide) chmod +x $@
146endif
147
148ifndef LOCAL_IS_HOST_MODULE
149  ifdef LOCAL_SOONG_UNSTRIPPED_BINARY
150    ifneq ($(LOCAL_VNDK_DEPEND_ON_CORE_VARIANT),true)
151      my_symbol_path := $(if $(LOCAL_SOONG_SYMBOL_PATH),$(LOCAL_SOONG_SYMBOL_PATH),$(my_module_path))
152      # Store a copy with symbols for symbolic debugging
153      my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_symbol_path))
154      # drop /root as /root is mounted as /
155      my_unstripped_path := $(patsubst $(TARGET_OUT_UNSTRIPPED)/root/%,$(TARGET_OUT_UNSTRIPPED)/%, $(my_unstripped_path))
156      symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
157      $(eval $(call copy-one-file,$(LOCAL_SOONG_UNSTRIPPED_BINARY),$(symbolic_output)))
158      $(call add-dependency,$(LOCAL_BUILT_MODULE),$(symbolic_output))
159
160      ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
161        my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_symbol_path))
162        breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym
163        $(breakpad_output) : $(LOCAL_SOONG_UNSTRIPPED_BINARY) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF)
164	@echo "target breakpad: $(PRIVATE_MODULE) ($@)"
165	@mkdir -p $(dir $@)
166	$(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \
167	  $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \
168	else \
169	  echo "skipped for non-elf file."; \
170	  touch $@; \
171	fi
172        $(call add-dependency,$(LOCAL_BUILT_MODULE),$(breakpad_output))
173      endif
174    endif
175  endif
176endif
177
178ifeq ($(NATIVE_COVERAGE),true)
179  ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE)))
180    $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).gcnodir))
181    ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true)
182      ifdef LOCAL_IS_HOST_MODULE
183        my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path))
184      else
185        my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
186      endif
187      my_coverage_path := $(my_coverage_path)/$(patsubst %.so,%,$(my_installed_module_stem)).gcnodir
188      $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path)))
189      $(LOCAL_BUILT_MODULE): $(my_coverage_path)
190    endif
191  else
192    # Coverage information is needed when static lib is a dependency of another
193    # coverage-enabled module.
194    ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS))
195      GCNO_ARCHIVE := $(LOCAL_MODULE).gcnodir
196      $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS :=
197      $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES :=
198      $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_PREFIX := $(my_prefix)
199      $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX)
200      $(intermediates)/$(GCNO_ARCHIVE) :
201	$(transform-o-to-static-lib)
202    endif
203  endif
204endif
205
206# A product may be configured to strip everything in some build variants.
207# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE
208# is still with the symbols and we don't need to clean it (and relink) when
209# you switch build variant.
210ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),)
211$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \
212  $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE)
213endif
214
215$(LOCAL_BUILT_MODULE): $(LOCAL_ADDITIONAL_DEPENDENCIES)
216
217# We don't care about installed static libraries, since the libraries have
218# already been linked into the module at that point. We do, however, care
219# about the NOTICE files for any static libraries that we use.
220# (see notice_files.mk)
221#
222# Filter out some NDK libraries that are not being exported.
223my_static_libraries := \
224    $(filter-out ndk_libc++_static ndk_libc++abi ndk_libandroid_support ndk_libunwind, \
225      $(LOCAL_STATIC_LIBRARIES))
226installed_static_library_notice_file_targets := \
227    $(foreach lib,$(my_static_libraries) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
228      NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST$(if $(my_host_cross),_CROSS,),TARGET)-STATIC_LIBRARIES-$(lib))
229
230$(notice_target): | $(installed_static_library_notice_file_targets)
231$(LOCAL_INSTALLED_MODULE): | $(notice_target)
232
233endif # !skip_module
234
235skip_module :=
236