1###########################################################
2## Standard rules for building binary object files from
3## asm/c/cpp/yacc/lex/etc source files.
4##
5## The list of object files is exported in $(all_objects).
6###########################################################
7
8#######################################
9include $(BUILD_SYSTEM)/base_rules.mk
10include $(BUILD_SYSTEM)/use_lld_setup.mk
11#######################################
12
13##################################################
14# Compute the dependency of the shared libraries
15##################################################
16# On the target, we compile with -nostdlib, so we must add in the
17# default system shared libraries, unless they have requested not
18# to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value.  One would
19# supply that, for example, when building libc itself.
20ifdef LOCAL_IS_HOST_MODULE
21  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
22      my_system_shared_libraries :=
23  else
24      my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
25  endif
26else
27  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
28      my_system_shared_libraries := libc libm libdl
29  else
30      my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
31      my_system_shared_libraries := $(patsubst libc,libc libdl,$(my_system_shared_libraries))
32  endif
33endif
34
35my_soong_problems :=
36
37# The following LOCAL_ variables will be modified in this file.
38# Because the same LOCAL_ variables may be used to define modules for both 1st arch and 2nd arch,
39# we can't modify them in place.
40my_src_files := $(LOCAL_SRC_FILES)
41my_src_files_exclude := $(LOCAL_SRC_FILES_EXCLUDE)
42my_static_libraries := $(LOCAL_STATIC_LIBRARIES)
43my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES)
44my_shared_libraries := $(filter-out $(my_system_shared_libraries),$(LOCAL_SHARED_LIBRARIES))
45my_header_libraries := $(LOCAL_HEADER_LIBRARIES)
46my_cflags := $(LOCAL_CFLAGS)
47my_conlyflags := $(LOCAL_CONLYFLAGS)
48my_cppflags := $(LOCAL_CPPFLAGS)
49my_cflags_no_override := $(GLOBAL_CLANG_CFLAGS_NO_OVERRIDE)
50my_cppflags_no_override := $(GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE)
51my_ldflags := $(LOCAL_LDFLAGS)
52my_ldlibs := $(LOCAL_LDLIBS)
53my_asflags := $(LOCAL_ASFLAGS)
54my_cc := $(LOCAL_CC)
55my_cc_wrapper := $(CC_WRAPPER)
56my_cxx := $(LOCAL_CXX)
57my_cxx_link := $(LOCAL_CXX)
58my_cxx_ldlibs :=
59my_cxx_wrapper := $(CXX_WRAPPER)
60my_c_includes := $(LOCAL_C_INCLUDES)
61my_generated_sources := $(LOCAL_GENERATED_SOURCES)
62my_additional_dependencies := $(LOCAL_ADDITIONAL_DEPENDENCIES)
63my_export_c_include_dirs := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
64my_export_c_include_deps := $(LOCAL_EXPORT_C_INCLUDE_DEPS)
65my_arflags :=
66
67# Configure the pool to use for clang rules.
68# If LOCAL_CC or LOCAL_CXX is set don't use goma or RBE.
69my_pool :=
70ifeq (,$(strip $(my_cc))$(strip $(my_cxx)))
71  my_pool := $(GOMA_OR_RBE_POOL)
72endif
73
74# TODO(b/158212027): Remove `$(COVERAGE_PATHS)` from this condition when all users have been moved
75# to `NATIVE_COVERAGE_PATHS`.
76ifneq (,$(strip $(foreach dir,$(COVERAGE_PATHS) $(NATIVE_COVERAGE_PATHS),$(filter $(dir)%,$(LOCAL_PATH)))))
77# TODO(b/158212027): Remove `$(COVERAGE_EXCLUDE_PATHS)` from this condition when all users have been
78# moved to `NATIVE_COVERAGE_EXCLUDE_PATHS`.
79ifeq (,$(strip $(foreach dir,$(COVERAGE_EXCLUDE_PATHS) $(NATIVE_COVERAGE_EXCLUDE_PATHS),$(filter $(dir)%,$(LOCAL_PATH)))))
80  my_native_coverage := true
81else
82  my_native_coverage := false
83endif
84else
85  my_native_coverage := false
86endif
87ifneq ($(NATIVE_COVERAGE),true)
88  my_native_coverage := false
89endif
90
91# Exclude directories from checking allowed manual binder interface lists.
92# TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
93ifneq (,$(filter $(addsuffix %,$(ALLOWED_MANUAL_INTERFACE_PATHS)),$(LOCAL_PATH)))
94  my_cflags += -DDO_NOT_CHECK_MANUAL_BINDER_INTERFACES
95endif
96
97my_allow_undefined_symbols := $(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS))
98ifdef SANITIZE_HOST
99ifdef LOCAL_IS_HOST_MODULE
100my_allow_undefined_symbols := true
101endif
102endif
103
104my_ndk_sysroot :=
105my_ndk_sysroot_include :=
106my_ndk_sysroot_lib :=
107my_api_level := 10000
108
109ifneq ($(LOCAL_SDK_VERSION),)
110  ifdef LOCAL_IS_HOST_MODULE
111    $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
112  endif
113
114  # Make sure we've built the NDK.
115  my_additional_dependencies += $(SOONG_OUT_DIR)/ndk_base.timestamp
116
117  # mips32r6 is not supported by the NDK. No released NDK contains these
118  # libraries, but the r10 in prebuilts/ndk had a local hack to add them :(
119  #
120  # We need to find a real solution to this problem, but until we do just drop
121  # mips32r6 things back to r10 to get the tree building again.
122  ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
123    ifeq ($(LOCAL_NDK_VERSION), current)
124      LOCAL_NDK_VERSION := r10
125    endif
126  endif
127
128  my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
129  ifneq (,$(filter arm64 mips64 x86_64,$(my_arch)))
130    my_min_sdk_version := 21
131  else
132    my_min_sdk_version := $(MIN_SUPPORTED_SDK_VERSION)
133  endif
134
135  # Historically we've just set up a bunch of symlinks in prebuilts/ndk to map
136  # missing API levels to existing ones where necessary, but we're not doing
137  # that for the generated libraries. Clip the API level to the minimum where
138  # appropriate.
139  my_ndk_api := $(LOCAL_SDK_VERSION)
140  ifneq ($(my_ndk_api),current)
141    my_ndk_api := $(call math_max,$(my_ndk_api),$(my_min_sdk_version))
142  endif
143
144  my_ndk_hist_api := $(my_ndk_api)
145  ifeq ($(my_ndk_api),current)
146    # The last API level supported by the old prebuilt NDKs.
147    my_ndk_hist_api := 24
148  else
149    my_api_level := $(my_ndk_api)
150  endif
151
152  my_ndk_source_root := \
153      $(HISTORICAL_NDK_VERSIONS_ROOT)/$(LOCAL_NDK_VERSION)/sources
154  my_ndk_sysroot := \
155    $(HISTORICAL_NDK_VERSIONS_ROOT)/$(LOCAL_NDK_VERSION)/platforms/android-$(my_ndk_hist_api)/arch-$(my_arch)
156  my_built_ndk := $(SOONG_OUT_DIR)/ndk
157  my_ndk_triple := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_TRIPLE)
158  my_ndk_sysroot_include := \
159      $(my_built_ndk)/sysroot/usr/include \
160      $(my_built_ndk)/sysroot/usr/include/$(my_ndk_triple) \
161      $(my_ndk_sysroot)/usr/include \
162
163  # x86_64 and and mips64 are both multilib toolchains, so their libraries are
164  # installed in /usr/lib64. Aarch64, on the other hand, is not a multilib
165  # compiler, so its libraries are in /usr/lib.
166  #
167  # Mips32r6 is yet another variation, with libraries installed in libr6.
168  #
169  # For the rest, the libraries are installed simply to /usr/lib.
170  ifneq (,$(filter x86_64 mips64,$(my_arch)))
171    my_ndk_libdir_name := lib64
172  else ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
173    my_ndk_libdir_name := libr6
174  else
175    my_ndk_libdir_name := lib
176  endif
177
178  my_ndk_platform_dir := \
179      $(my_built_ndk)/platforms/android-$(my_ndk_api)/arch-$(my_arch)
180  my_built_ndk_libs := $(my_ndk_platform_dir)/usr/$(my_ndk_libdir_name)
181  my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/$(my_ndk_libdir_name)
182
183  # The bionic linker now has support for packed relocations and gnu style
184  # hashes (which are much faster!), but shipping to older devices requires
185  # the old style hash. Fortunately, we can build with both and it'll work
186  # anywhere.
187  #
188  # This is not currently supported on MIPS architectures.
189  ifeq (,$(filter mips mips64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
190    my_ldflags += -Wl,--hash-style=both
191  endif
192
193  # We don't want to expose the relocation packer to the NDK just yet.
194  LOCAL_PACK_MODULE_RELOCATIONS := false
195
196  # Set up the NDK stl variant. Starting from NDK-r5 the c++ stl resides in a separate location.
197  # See ndk/docs/CPLUSPLUS-SUPPORT.html
198  my_ndk_stl_include_path :=
199  my_ndk_stl_shared_lib_fullpath :=
200  my_ndk_stl_static_lib :=
201  my_cpu_variant := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)
202  ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
203    my_cpu_variant := mips32r6
204  endif
205  LOCAL_NDK_STL_VARIANT := $(strip $(LOCAL_NDK_STL_VARIANT))
206  ifeq (,$(LOCAL_NDK_STL_VARIANT))
207    LOCAL_NDK_STL_VARIANT := system
208  endif
209  ifneq (1,$(words $(filter none system c++_static c++_shared, $(LOCAL_NDK_STL_VARIANT))))
210    $(error $(LOCAL_PATH): Unknown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT))
211  endif
212
213  ifeq (system,$(LOCAL_NDK_STL_VARIANT))
214    my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/system/include
215    my_system_shared_libraries += libstdc++
216  else ifneq (,$(filter c++_%, $(LOCAL_NDK_STL_VARIANT)))
217    my_ndk_stl_include_path := \
218      $(my_ndk_source_root)/cxx-stl/llvm-libc++/include
219    my_ndk_stl_include_path += \
220      $(my_ndk_source_root)/cxx-stl/llvm-libc++abi/include
221
222    my_libcxx_libdir := \
223      $(my_ndk_source_root)/cxx-stl/llvm-libc++/libs/$(my_cpu_variant)
224
225    ifeq (c++_static,$(LOCAL_NDK_STL_VARIANT))
226      my_ndk_stl_static_lib := \
227        $(my_libcxx_libdir)/libc++_static.a \
228        $(my_libcxx_libdir)/libc++abi.a
229    else
230      my_ndk_stl_shared_lib_fullpath := $(my_libcxx_libdir)/libc++_shared.so
231    endif
232
233    ifneq ($(my_ndk_api),current)
234      ifeq ($(call math_lt,$(my_ndk_api),21),true)
235        my_ndk_stl_include_path += $(my_ndk_source_root)/android/support/include
236        my_ndk_stl_static_lib += $(my_libcxx_libdir)/libandroid_support.a
237      endif
238    endif
239
240    ifneq (,$(filter armeabi armeabi-v7a,$(my_cpu_variant)))
241      my_ndk_stl_static_lib += $(my_libcxx_libdir)/libunwind.a
242    endif
243
244    my_ldlibs += -ldl
245  else # LOCAL_NDK_STL_VARIANT must be none
246    # Do nothing.
247  endif
248
249  # Clang's coverage/profile runtime needs symbols like 'stderr' that were not
250  # exported from libc prior to API level 23
251  ifneq ($(my_ndk_api),current)
252    ifeq ($(call math_lt, $(my_ndk_api),23),true)
253      my_native_coverage := false
254    endif
255  endif
256endif
257
258ifeq ($(NATIVE_COVERAGE),true)
259  ifndef LOCAL_IS_HOST_MODULE
260    my_ldflags += -Wl,--wrap,getenv
261
262    ifneq ($(LOCAL_MODULE_CLASS),STATIC_LIBRARIES)
263      ifeq ($(LOCAL_SDK_VERSION),)
264        my_whole_static_libraries += libprofile-extras
265      else
266        my_whole_static_libraries += libprofile-extras_ndk
267      endif
268    endif
269  endif
270endif
271
272ifneq ($(LOCAL_USE_VNDK),)
273  # Required VNDK version for vendor modules is BOARD_VNDK_VERSION.
274  my_api_level := $(BOARD_VNDK_VERSION)
275  ifeq ($(my_api_level),current)
276    # Build with current PLATFORM_VNDK_VERSION.
277    # If PLATFORM_VNDK_VERSION has a CODENAME, it will return
278    # __ANDROID_API_FUTURE__.
279    my_api_level := $(call codename-or-sdk-to-sdk,$(PLATFORM_VNDK_VERSION))
280  else
281    # Build with current BOARD_VNDK_VERSION.
282    my_api_level := $(call codename-or-sdk-to-sdk,$(BOARD_VNDK_VERSION))
283  endif
284  my_cflags += -D__ANDROID_VNDK__
285endif
286
287ifndef LOCAL_IS_HOST_MODULE
288# For device libraries, move LOCAL_LDLIBS references to my_shared_libraries. We
289# no longer need to use my_ldlibs to pick up NDK prebuilt libraries since we're
290# linking my_shared_libraries by full path now.
291my_allowed_ldlibs :=
292
293# Sort ldlibs and ldflags between -l and other linker flags
294# We'll do this again later, since there are still changes happening, but that's fine.
295my_ldlib_flags := $(my_ldflags) $(my_ldlibs)
296my_ldlibs := $(filter -l%,$(my_ldlib_flags))
297my_ldflags := $(filter-out -l%,$(my_ldlib_flags))
298my_ldlib_flags :=
299
300# Move other ldlibs back to shared libraries
301my_shared_libraries += $(patsubst -l%,lib%,$(filter-out $(my_allowed_ldlibs),$(my_ldlibs)))
302my_ldlibs := $(filter $(my_allowed_ldlibs),$(my_ldlibs))
303else # LOCAL_IS_HOST_MODULE
304  # Add -ldl, -lpthread, -lm and -lrt to host builds to match the default behavior of
305  # device builds
306  my_ldlibs += -ldl -lpthread -lm
307  ifneq ($(HOST_OS),darwin)
308    my_ldlibs += -lrt
309  endif
310endif
311
312ifneq ($(LOCAL_SDK_VERSION),)
313  my_all_ndk_libraries := \
314      $(NDK_MIGRATED_LIBS) $(addprefix lib,$(NDK_PREBUILT_SHARED_LIBRARIES))
315  my_ndk_shared_libraries := \
316      $(filter $(my_all_ndk_libraries),\
317        $(my_shared_libraries) $(my_system_shared_libraries))
318
319  my_shared_libraries := \
320      $(filter-out $(my_all_ndk_libraries),$(my_shared_libraries))
321  my_system_shared_libraries := \
322      $(filter-out $(my_all_ndk_libraries),$(my_system_shared_libraries))
323endif
324
325# MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
326# all code is position independent, and then those warnings get promoted to
327# errors.
328ifneq ($(LOCAL_NO_PIC),true)
329  ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
330    my_cflags += -fPIE
331    ifndef BUILD_HOST_static
332      ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
333        my_ldflags += -pie
334      endif
335    endif
336  else
337    my_cflags += -fPIC
338  endif
339endif
340
341ifdef LOCAL_IS_HOST_MODULE
342my_src_files += $(LOCAL_SRC_FILES_$($(my_prefix)OS)) $(LOCAL_SRC_FILES_$($(my_prefix)OS)_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
343my_static_libraries += $(LOCAL_STATIC_LIBRARIES_$($(my_prefix)OS))
344my_shared_libraries += $(LOCAL_SHARED_LIBRARIES_$($(my_prefix)OS))
345my_header_libraries += $(LOCAL_HEADER_LIBRARIES_$($(my_prefix)OS))
346my_cflags += $(LOCAL_CFLAGS_$($(my_prefix)OS))
347my_cppflags += $(LOCAL_CPPFLAGS_$($(my_prefix)OS))
348my_ldflags += $(LOCAL_LDFLAGS_$($(my_prefix)OS))
349my_ldlibs += $(LOCAL_LDLIBS_$($(my_prefix)OS))
350my_asflags += $(LOCAL_ASFLAGS_$($(my_prefix)OS))
351my_c_includes += $(LOCAL_C_INCLUDES_$($(my_prefix)OS))
352my_generated_sources += $(LOCAL_GENERATED_SOURCES_$($(my_prefix)OS))
353endif
354
355my_src_files += $(LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SRC_FILES_$(my_32_64_bit_suffix))
356my_src_files_exclude += $(LOCAL_SRC_FILES_EXCLUDE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SRC_FILES_EXCLUDE_$(my_32_64_bit_suffix))
357my_shared_libraries += $(LOCAL_SHARED_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SHARED_LIBRARIES_$(my_32_64_bit_suffix))
358my_cflags += $(LOCAL_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CFLAGS_$(my_32_64_bit_suffix))
359my_cppflags += $(LOCAL_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CPPFLAGS_$(my_32_64_bit_suffix))
360my_ldflags += $(LOCAL_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_LDFLAGS_$(my_32_64_bit_suffix))
361my_asflags += $(LOCAL_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_ASFLAGS_$(my_32_64_bit_suffix))
362my_c_includes += $(LOCAL_C_INCLUDES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_C_INCLUDES_$(my_32_64_bit_suffix))
363my_generated_sources += $(LOCAL_GENERATED_SOURCES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_GENERATED_SOURCES_$(my_32_64_bit_suffix))
364
365my_missing_exclude_files := $(filter-out $(my_src_files),$(my_src_files_exclude))
366ifneq ($(my_missing_exclude_files),)
367$(warning Files are listed in LOCAL_SRC_FILES_EXCLUDE but not LOCAL_SRC_FILES)
368$(error $(my_missing_exclude_files))
369endif
370my_src_files := $(filter-out $(my_src_files_exclude),$(my_src_files))
371
372# Strip '/' from the beginning of each src file. This helps the ../ detection in case
373# the source file is in the form of /../file
374my_src_files := $(patsubst /%,%,$(my_src_files))
375
376my_clang := $(strip $(LOCAL_CLANG))
377ifdef LOCAL_CLANG_$(my_32_64_bit_suffix)
378my_clang := $(strip $(LOCAL_CLANG_$(my_32_64_bit_suffix)))
379endif
380ifdef LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
381my_clang := $(strip $(LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
382endif
383ifeq ($(my_clang),false)
384    $(call pretty-error,LOCAL_CLANG false is no longer supported)
385endif
386
387ifeq ($(LOCAL_C_STD),)
388    my_c_std_version := $(DEFAULT_C_STD_VERSION)
389else ifeq ($(LOCAL_C_STD),experimental)
390    my_c_std_version := $(EXPERIMENTAL_C_STD_VERSION)
391else
392    my_c_std_version := $(LOCAL_C_STD)
393endif
394
395ifeq ($(LOCAL_CPP_STD),)
396    my_cpp_std_version := $(DEFAULT_CPP_STD_VERSION)
397else ifeq ($(LOCAL_CPP_STD),experimental)
398    my_cpp_std_version := $(EXPERIMENTAL_CPP_STD_VERSION)
399else
400    my_cpp_std_version := $(LOCAL_CPP_STD)
401endif
402
403my_c_std_conlyflags :=
404my_cpp_std_cppflags :=
405ifneq (,$(my_c_std_version))
406    my_c_std_conlyflags := -std=$(my_c_std_version)
407endif
408
409ifneq (,$(my_cpp_std_version))
410   my_cpp_std_cppflags := -std=$(my_cpp_std_version)
411endif
412
413# Extra cflags for projects under external/ directory
414ifneq ($(filter external/%,$(LOCAL_PATH)),)
415    my_cflags += $(CLANG_EXTERNAL_CFLAGS)
416endif
417
418# arch-specific static libraries go first so that generic ones can depend on them
419my_static_libraries := $(LOCAL_STATIC_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_STATIC_LIBRARIES_$(my_32_64_bit_suffix)) $(my_static_libraries)
420my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_WHOLE_STATIC_LIBRARIES_$(my_32_64_bit_suffix)) $(my_whole_static_libraries)
421my_header_libraries := $(LOCAL_HEADER_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_HEADER_LIBRARIES_$(my_32_64_bit_suffix)) $(my_header_libraries)
422
423include $(BUILD_SYSTEM)/cxx_stl_setup.mk
424
425ifneq ($(strip $(CUSTOM_$(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)LINKER)),)
426  my_linker := $(CUSTOM_$(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)LINKER)
427else
428  my_linker := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)LINKER)
429endif
430
431include $(BUILD_SYSTEM)/config_sanitizers.mk
432
433ifneq ($(filter ../%,$(my_src_files)),)
434my_soong_problems += dotdot_srcs
435endif
436ifneq ($(foreach i,$(my_c_includes),$(filter %/..,$(i))$(findstring /../,$(i))),)
437my_soong_problems += dotdot_incs
438endif
439
440####################################################
441## Add FDO flags if FDO is turned on and supported
442## Please note that we will do option filtering during FDO build.
443## i.e. Os->O2, remove -fno-early-inline and -finline-limit.
444##################################################################
445my_fdo_build :=
446ifneq ($(filter true always, $(LOCAL_FDO_SUPPORT)),)
447  ifeq ($(BUILD_FDO_INSTRUMENT),true)
448    my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_CFLAGS)
449    my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_LDFLAGS)
450    my_fdo_build := true
451  else ifneq ($(filter true,$(BUILD_FDO_OPTIMIZE))$(filter always,$(LOCAL_FDO_SUPPORT)),)
452    my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_OPTIMIZE_CFLAGS)
453    my_fdo_build := true
454  endif
455  # Disable ccache (or other compiler wrapper) except gomacc, which
456  # can handle -fprofile-use properly.
457  my_cc_wrapper := $(filter $(GOMA_CC) $(RBE_WRAPPER),$(my_cc_wrapper))
458  my_cxx_wrapper := $(filter $(GOMA_CC) $(RBE_WRAPPER),$(my_cxx_wrapper))
459endif
460
461###########################################################
462## Explicitly declare assembly-only __ASSEMBLY__ macro for
463## assembly source
464###########################################################
465my_asflags += -D__ASSEMBLY__
466
467###########################################################
468# TODO: support a mix of standard extensions so that this isn't necessary
469LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
470ifeq ($(LOCAL_CPP_EXTENSION),)
471  LOCAL_CPP_EXTENSION := .cpp
472endif
473
474# Certain modules like libdl have to have symbols resolved at runtime and blow
475# up if --no-undefined is passed to the linker.
476ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
477  ifeq ($(my_allow_undefined_symbols),)
478    ifneq ($(HOST_OS),darwin)
479      my_ldflags += -Wl,--no-undefined
480    endif
481  else
482    ifdef LOCAL_IS_HOST_MODULE
483      ifeq ($(HOST_OS),darwin)
484        # darwin defaults to treating undefined symbols as errors
485        my_ldflags += -Wl,-undefined,dynamic_lookup
486      endif
487    endif
488  endif
489endif
490
491ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES))
492$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true
493else
494$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES :=
495endif
496
497###########################################################
498## Define arm-vs-thumb-mode flags.
499###########################################################
500LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
501ifeq ($($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH),arm)
502normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
503
504# Read the values from something like TARGET_arm_CFLAGS or
505# TARGET_thumb_CFLAGS.  HOST_(arm|thumb)_CFLAGS values aren't
506# actually used (although they are usually empty).
507normal_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(normal_objects_mode)_CFLAGS)
508
509else
510normal_objects_mode :=
511normal_objects_cflags :=
512endif
513
514###########################################################
515## Define per-module debugging flags.  Users can turn on
516## debugging for a particular module by setting DEBUG_MODULE_ModuleName
517## to a non-empty value in their environment or buildspec.mk,
518## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
519## debug flags that they want to use.
520###########################################################
521ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
522  debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
523else
524  debug_cflags :=
525endif
526
527####################################################
528## Keep track of src -> obj mapping
529####################################################
530
531my_tracked_gen_files :=
532my_tracked_src_files :=
533
534###########################################################
535## Stuff source generated from one-off tools
536###########################################################
537$(my_generated_sources): PRIVATE_MODULE := $(my_register_name)
538
539my_gen_sources_copy := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(filter $(generated_sources_dir)/%,$(my_generated_sources)))
540
541$(my_gen_sources_copy): $(intermediates)/% : $(generated_sources_dir)/%
542	@echo "Copy: $@"
543	$(copy-file-to-target)
544
545my_generated_sources := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(my_generated_sources))
546
547# Generated sources that will actually produce object files.
548# Other files (like headers) are allowed in LOCAL_GENERATED_SOURCES,
549# since other compiled sources may depend on them, and we set up
550# the dependencies.
551my_gen_src_files := $(filter %.c %$(LOCAL_CPP_EXTENSION) %.S %.s,$(my_generated_sources))
552
553ALL_GENERATED_SOURCES += $(my_generated_sources)
554
555####################################################
556## Compile RenderScript with reflected C++
557####################################################
558
559renderscript_sources := $(filter %.rscript %.fs,$(my_src_files))
560
561ifneq (,$(renderscript_sources))
562my_soong_problems += rs
563
564renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
565RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp
566renderscript_intermediate := $(intermediates)/renderscript
567
568renderscript_target_api :=
569
570ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
571renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
572else
573ifneq (,$(LOCAL_SDK_VERSION))
574# Set target-api for LOCAL_SDK_VERSIONs other than current.
575ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
576renderscript_target_api := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
577endif
578endif  # LOCAL_SDK_VERSION is set
579endif  # LOCAL_RENDERSCRIPT_TARGET_API is set
580
581
582ifeq ($(LOCAL_RENDERSCRIPT_CC),)
583LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
584endif
585
586# Turn on all warnings and warnings as errors for RS compiles.
587# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
588renderscript_flags := -Wall -Werror
589renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
590# -m32 or -m64
591renderscript_flags += -m$(my_32_64_bit_suffix)
592
593renderscript_includes := \
594    $(TOPDIR)external/clang/lib/Headers \
595    $(TOPDIR)frameworks/rs/script_api/include \
596    $(LOCAL_RENDERSCRIPT_INCLUDES)
597
598ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
599renderscript_includes := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
600endif
601
602bc_dep_files := $(addprefix $(renderscript_intermediate)/, \
603    $(patsubst %.fs,%.d, $(patsubst %.rscript,%.d, $(notdir $(renderscript_sources)))))
604
605$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(renderscript_includes)
606$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
607$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
608$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
609$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate)
610$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(patsubst current,0,$(renderscript_target_api))
611$(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files)
612$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
613	$(transform-renderscripts-to-cpp-and-bc)
614
615# include the dependency files (.d) generated by llvm-rs-cc.
616$(call include-depfile,$(RenderScript_file_stamp).d,$(RenderScript_file_stamp))
617
618LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
619
620rs_generated_cpps := $(addprefix \
621    $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rscript,%.cpp, \
622    $(notdir $(renderscript_sources)))))
623
624$(call track-src-file-gen,$(renderscript_sources),$(rs_generated_cpps))
625
626# This is just a dummy rule to make sure gmake doesn't skip updating the dependents.
627$(rs_generated_cpps) : $(RenderScript_file_stamp)
628	@echo "Updated RS generated cpp file $@."
629	$(hide) touch $@
630
631my_c_includes += $(renderscript_intermediate)
632my_generated_sources += $(rs_generated_cpps)
633
634endif
635
636
637###########################################################
638## Compile the .proto files to .cc (or .c) and then to .o
639###########################################################
640ifeq ($(strip $(LOCAL_PROTOC_OPTIMIZE_TYPE)),)
641  LOCAL_PROTOC_OPTIMIZE_TYPE := lite
642endif
643proto_sources := $(filter %.proto,$(my_src_files))
644ifneq ($(proto_sources),)
645proto_gen_dir := $(generated_sources_dir)/proto
646proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
647
648my_rename_cpp_ext :=
649ifneq (,$(filter nanopb-c nanopb-c-enable_malloc nanopb-c-16bit nanopb-c-enable_malloc-16bit nanopb-c-32bit nanopb-c-enable_malloc-32bit, $(LOCAL_PROTOC_OPTIMIZE_TYPE)))
650my_proto_source_suffix := .c
651my_proto_c_includes := external/nanopb-c
652my_protoc_flags := --nanopb_out=$(proto_gen_dir) \
653    --plugin=$(HOST_OUT_EXECUTABLES)/protoc-gen-nanopb
654my_protoc_deps := $(NANOPB_SRCS) $(proto_sources_fullpath:%.proto=%.options)
655else
656my_proto_source_suffix := $(LOCAL_CPP_EXTENSION)
657ifneq ($(my_proto_source_suffix),.cc)
658# aprotoc is hardcoded to write out only .cc file.
659# We need to rename the extension to $(LOCAL_CPP_EXTENSION) if it's not .cc.
660my_rename_cpp_ext := true
661endif
662my_proto_c_includes := external/protobuf/src
663my_cflags += -DGOOGLE_PROTOBUF_NO_RTTI
664my_protoc_flags := --cpp_out=$(if $(filter lite lite-static,$(LOCAL_PROTOC_OPTIMIZE_TYPE)),lite:,)$(proto_gen_dir)
665my_protoc_deps :=
666endif
667my_proto_c_includes += $(proto_gen_dir)
668
669proto_generated_cpps := $(addprefix $(proto_gen_dir)/, \
670    $(patsubst %.proto,%.pb$(my_proto_source_suffix),$(proto_sources_fullpath)))
671
672# Ensure the transform-proto-to-cc rule is only defined once in multilib build.
673ifndef $(my_host)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined
674$(proto_generated_cpps): PRIVATE_PROTO_INCLUDES := $(TOP)
675$(proto_generated_cpps): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) $(my_protoc_flags)
676$(proto_generated_cpps): PRIVATE_RENAME_CPP_EXT := $(my_rename_cpp_ext)
677$(proto_generated_cpps): $(proto_gen_dir)/%.pb$(my_proto_source_suffix): %.proto $(my_protoc_deps) $(PROTOC)
678	$(transform-proto-to-cc)
679
680$(my_host)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined := true
681endif
682# Ideally we can generate the source directly into $(intermediates).
683# But many Android.mks assume the .pb.hs are in $(generated_sources_dir).
684# As a workaround, we make a copy in the $(intermediates).
685proto_intermediate_dir := $(intermediates)/proto
686proto_intermediate_cpps := $(patsubst $(proto_gen_dir)/%,$(proto_intermediate_dir)/%,\
687    $(proto_generated_cpps))
688$(proto_intermediate_cpps) : $(proto_intermediate_dir)/% : $(proto_gen_dir)/%
689	@echo "Copy: $@"
690	$(copy-file-to-target)
691	$(hide) cp $(basename $<).h $(basename $@).h
692$(call track-src-file-gen,$(proto_sources),$(proto_intermediate_cpps))
693
694my_generated_sources += $(proto_intermediate_cpps)
695
696my_c_includes += $(my_proto_c_includes)
697# Auto-export the generated proto source dir.
698my_export_c_include_dirs += $(my_proto_c_includes)
699
700ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc)
701    my_static_libraries += libprotobuf-c-nano-enable_malloc
702else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c)
703    my_static_libraries += libprotobuf-c-nano
704else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc-16bit)
705    my_static_libraries += libprotobuf-c-nano-enable_malloc-16bit
706else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-16bit)
707    my_static_libraries += libprotobuf-c-nano-16bit
708else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc-32bit)
709    my_static_libraries += libprotobuf-c-nano-enable_malloc-32bit
710else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-32bit)
711    my_static_libraries += libprotobuf-c-nano-32bit
712else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
713    ifdef LOCAL_SDK_VERSION
714        my_static_libraries += libprotobuf-cpp-full-ndk
715    else
716        my_shared_libraries += libprotobuf-cpp-full
717    endif
718else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),lite-static)
719    my_static_libraries += libprotobuf-cpp-lite
720else
721    ifdef LOCAL_SDK_VERSION
722        my_static_libraries += libprotobuf-cpp-lite-ndk
723    else
724        my_shared_libraries += libprotobuf-cpp-lite
725    endif
726endif
727endif  # $(proto_sources) non-empty
728
729###########################################################
730## AIDL: Compile .aidl files to .cpp and .h files
731###########################################################
732aidl_src := $(strip $(filter %.aidl,$(my_src_files)))
733aidl_gen_cpp :=
734ifneq ($(aidl_src),)
735
736# Use the intermediates directory to avoid writing our own .cpp -> .o rules.
737aidl_gen_cpp_root := $(intermediates)/aidl-generated/src
738aidl_gen_include_root := $(intermediates)/aidl-generated/include
739
740# Multi-architecture builds have distinct intermediates directories.
741# Thus we'll actually generate source for each architecture.
742$(foreach s,$(aidl_src),\
743    $(eval $(call define-aidl-cpp-rule,$(s),$(aidl_gen_cpp_root),aidl_gen_cpp)))
744$(foreach cpp,$(aidl_gen_cpp), \
745    $(call include-depfile,$(addsuffix .aidl.d,$(basename $(cpp))),$(cpp)))
746$(call track-src-file-gen,$(aidl_src),$(aidl_gen_cpp))
747
748$(aidl_gen_cpp) : PRIVATE_MODULE := $(LOCAL_MODULE)
749$(aidl_gen_cpp) : PRIVATE_HEADER_OUTPUT_DIR := $(aidl_gen_include_root)
750$(aidl_gen_cpp) : PRIVATE_AIDL_FLAGS := $(addprefix -I,$(LOCAL_AIDL_INCLUDES))
751
752# Add generated headers to include paths.
753my_c_includes += $(aidl_gen_include_root)
754my_export_c_include_dirs += $(aidl_gen_include_root)
755# Pick up the generated C++ files later for transformation to .o files.
756my_generated_sources += $(aidl_gen_cpp)
757
758endif  # $(aidl_src) non-empty
759
760###########################################################
761## Compile the .vts files to .cc (or .c) and then to .o
762###########################################################
763
764vts_src := $(strip $(filter %.vts,$(my_src_files)))
765vts_gen_cpp :=
766ifneq ($(vts_src),)
767my_soong_problems += vts
768
769# Use the intermediates directory to avoid writing our own .cpp -> .o rules.
770vts_gen_cpp_root := $(intermediates)/vts-generated/src
771vts_gen_include_root := $(intermediates)/vts-generated/include
772
773# Multi-architecture builds have distinct intermediates directories.
774# Thus we'll actually generate source for each architecture.
775$(foreach s,$(vts_src),\
776    $(eval $(call define-vts-cpp-rule,$(s),$(vts_gen_cpp_root),vts_gen_cpp)))
777$(call track-src-file-gen,$(vts_src),$(vts_gen_cpp))
778
779$(vts_gen_cpp) : PRIVATE_MODULE := $(LOCAL_MODULE)
780$(vts_gen_cpp) : PRIVATE_HEADER_OUTPUT_DIR := $(vts_gen_include_root)
781$(vts_gen_cpp) : PRIVATE_VTS_FLAGS := $(addprefix -I,$(LOCAL_VTS_INCLUDES)) $(addprefix -m,$(LOCAL_VTS_MODE))
782
783# Add generated headers to include paths.
784my_c_includes += $(vts_gen_include_root)
785my_export_c_include_dirs += $(vts_gen_include_root)
786# Pick up the generated C++ files later for transformation to .o files.
787my_generated_sources += $(vts_gen_cpp)
788
789endif  # $(vts_src) non-empty
790
791###########################################################
792## YACC: Compile .y/.yy files to .c/.cpp and then to .o.
793###########################################################
794
795y_yacc_sources := $(filter %.y,$(my_src_files))
796y_yacc_cs := $(addprefix \
797    $(intermediates)/,$(y_yacc_sources:.y=.c))
798ifneq ($(y_yacc_cs),)
799$(y_yacc_cs): $(intermediates)/%.c: \
800    $(TOPDIR)$(LOCAL_PATH)/%.y $(BISON) $(BISON_DATA) $(M4) \
801    $(my_additional_dependencies)
802	$(call transform-y-to-c-or-cpp)
803$(call track-src-file-gen,$(y_yacc_sources),$(y_yacc_cs))
804
805my_generated_sources += $(y_yacc_cs)
806endif
807
808yy_yacc_sources := $(filter %.yy,$(my_src_files))
809yy_yacc_cpps := $(addprefix \
810    $(intermediates)/,$(yy_yacc_sources:.yy=$(LOCAL_CPP_EXTENSION)))
811ifneq ($(yy_yacc_cpps),)
812$(yy_yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
813    $(TOPDIR)$(LOCAL_PATH)/%.yy $(BISON) $(BISON_DATA) $(M4) \
814    $(my_additional_dependencies)
815	$(call transform-y-to-c-or-cpp)
816$(call track-src-file-gen,$(yy_yacc_sources),$(yy_yacc_cpps))
817
818my_generated_sources += $(yy_yacc_cpps)
819endif
820
821###########################################################
822## LEX: Compile .l/.ll files to .c/.cpp and then to .o.
823###########################################################
824
825l_lex_sources := $(filter %.l,$(my_src_files))
826l_lex_cs := $(addprefix \
827    $(intermediates)/,$(l_lex_sources:.l=.c))
828ifneq ($(l_lex_cs),)
829$(l_lex_cs): $(LEX) $(M4)
830$(l_lex_cs): $(intermediates)/%.c: \
831    $(TOPDIR)$(LOCAL_PATH)/%.l
832	$(transform-l-to-c-or-cpp)
833$(call track-src-file-gen,$(l_lex_sources),$(l_lex_cs))
834
835my_generated_sources += $(l_lex_cs)
836endif
837
838ll_lex_sources := $(filter %.ll,$(my_src_files))
839ll_lex_cpps := $(addprefix \
840    $(intermediates)/,$(ll_lex_sources:.ll=$(LOCAL_CPP_EXTENSION)))
841ifneq ($(ll_lex_cpps),)
842$(ll_lex_cpps): $(LEX) $(M4)
843$(ll_lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
844    $(TOPDIR)$(LOCAL_PATH)/%.ll
845	$(transform-l-to-c-or-cpp)
846$(call track-src-file-gen,$(ll_lex_sources),$(ll_lex_cpps))
847
848my_generated_sources += $(ll_lex_cpps)
849endif
850
851###########################################################
852## C++: Compile .cpp files to .o.
853###########################################################
854
855ifneq ($(filter %$(LOCAL_CPP_EXTENSION).arm,$(my_src_files)),)
856$(call pretty-error,Files ending in $(LOCAL_CPP_EXTENSION).arm are deprecated. See $(CHANGES_URL)#file_arm)
857endif
858
859dotdot_sources := $(filter ../%$(LOCAL_CPP_EXTENSION),$(my_src_files))
860dotdot_objects :=
861$(foreach s,$(dotdot_sources),\
862  $(eval $(call compile-dotdot-cpp-file,$(s),\
863    $(my_additional_dependencies),\
864    dotdot_objects,\
865    $(my_pool))))
866$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects))
867
868cpp_normal_sources := $(filter-out ../%,$(filter %$(LOCAL_CPP_EXTENSION),$(my_src_files)))
869cpp_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
870$(call track-src-file-obj,$(cpp_normal_sources),$(cpp_objects))
871
872$(dotdot_objects) $(cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
873$(dotdot_objects) $(cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
874
875ifneq ($(strip $(cpp_objects)),)
876$(cpp_objects): .KATI_NINJA_POOL := $(my_pool)
877$(cpp_objects): $(intermediates)/%.o: \
878    $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
879    $(my_additional_dependencies) $(CLANG_CXX)
880	$(transform-$(PRIVATE_HOST)cpp-to-o)
881$(call include-depfiles-for-objs, $(cpp_objects))
882endif
883
884cpp_objects += $(dotdot_objects)
885
886###########################################################
887## C++: Compile generated .cpp files to .o.
888###########################################################
889
890gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(my_generated_sources))
891gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
892$(call track-gen-file-obj,$(gen_cpp_sources),$(gen_cpp_objects))
893
894ifneq ($(strip $(gen_cpp_objects)),)
895# Compile all generated files as thumb.
896$(gen_cpp_objects): .KATI_NINJA_POOL := $(my_pool)
897$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
898$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
899$(gen_cpp_objects): $(intermediates)/%.o: \
900    $(intermediates)/%$(LOCAL_CPP_EXTENSION) \
901    $(my_additional_dependencies) $(CLANG_CXX)
902	$(transform-$(PRIVATE_HOST)cpp-to-o)
903$(call include-depfiles-for-objs, $(gen_cpp_objects))
904endif
905
906###########################################################
907## S: Compile generated .S and .s files to .o.
908###########################################################
909
910gen_S_sources := $(filter %.S,$(my_generated_sources))
911gen_S_objects := $(gen_S_sources:%.S=%.o)
912$(call track-gen-file-obj,$(gen_S_sources),$(gen_S_objects))
913
914ifneq ($(strip $(gen_S_sources)),)
915$(gen_S_objects): .KATI_NINJA_POOL := $(my_pool)
916$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \
917    $(my_additional_dependencies) $(CLANG)
918	$(transform-$(PRIVATE_HOST)s-to-o)
919$(call include-depfiles-for-objs, $(gen_S_objects))
920endif
921
922gen_s_sources := $(filter %.s,$(my_generated_sources))
923gen_s_objects := $(gen_s_sources:%.s=%.o)
924$(call track-gen-file-obj,$(gen_s_sources),$(gen_s_objects))
925
926ifneq ($(strip $(gen_s_objects)),)
927$(gen_s_objects): .KATI_NINJA_POOL := $(my_pool)
928$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \
929    $(my_additional_dependencies) $(CLANG)
930	$(transform-$(PRIVATE_HOST)s-to-o)
931endif
932
933gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
934$(gen_asm_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
935
936###########################################################
937## o: Include generated .o files in output.
938###########################################################
939
940gen_o_objects := $(filter %.o,$(my_generated_sources))
941
942###########################################################
943## C: Compile .c files to .o.
944###########################################################
945
946ifneq ($(filter %.c.arm,$(my_src_files)),)
947$(call pretty-error,Files ending in .c.arm are deprecated. See $(CHANGES_URL)#file_arm)
948endif
949
950dotdot_sources := $(filter ../%.c, $(my_src_files))
951dotdot_objects :=
952$(foreach s, $(dotdot_sources),\
953  $(eval $(call compile-dotdot-c-file,$(s),\
954    $(my_additional_dependencies),\
955    dotdot_objects,\
956    $(my_pool))))
957$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects))
958
959c_normal_sources := $(filter-out ../%,$(filter %.c,$(my_src_files)))
960c_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
961$(call track-src-file-obj,$(c_normal_sources),$(c_objects))
962
963$(dotdot_objects) $(c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
964$(dotdot_objects) $(c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
965
966ifneq ($(strip $(c_objects)),)
967$(c_objects): .KATI_NINJA_POOL := $(my_pool)
968$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c \
969    $(my_additional_dependencies) $(CLANG)
970	$(transform-$(PRIVATE_HOST)c-to-o)
971$(call include-depfiles-for-objs, $(c_objects))
972endif
973
974c_objects += $(dotdot_objects)
975
976###########################################################
977## C: Compile generated .c files to .o.
978###########################################################
979
980gen_c_sources := $(filter %.c,$(my_generated_sources))
981gen_c_objects := $(gen_c_sources:%.c=%.o)
982$(call track-gen-file-obj,$(gen_c_sources),$(gen_c_objects))
983
984ifneq ($(strip $(gen_c_objects)),)
985# Compile all generated files as thumb.
986$(gen_c_objects): .KATI_NINJA_POOL := $(my_pool)
987$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
988$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
989$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c \
990    $(my_additional_dependencies) $(CLANG)
991	$(transform-$(PRIVATE_HOST)c-to-o)
992$(call include-depfiles-for-objs, $(gen_c_objects))
993endif
994
995###########################################################
996## ObjC: Compile .m files to .o
997###########################################################
998
999objc_sources := $(filter %.m,$(my_src_files))
1000objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
1001$(call track-src-file-obj,$(objc_sources),$(objc_objects))
1002
1003ifneq ($(strip $(objc_objects)),)
1004my_soong_problems += objc
1005$(objc_objects): .KATI_NINJA_POOL := $(my_pool)
1006$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m \
1007    $(my_additional_dependencies) $(CLANG)
1008	$(transform-$(PRIVATE_HOST)m-to-o)
1009$(call include-depfiles-for-objs, $(objc_objects))
1010endif
1011
1012###########################################################
1013## ObjC++: Compile .mm files to .o
1014###########################################################
1015
1016objcpp_sources := $(filter %.mm,$(my_src_files))
1017objcpp_objects := $(addprefix $(intermediates)/,$(objcpp_sources:.mm=.o))
1018$(call track-src-file-obj,$(objcpp_sources),$(objcpp_objects))
1019
1020ifneq ($(strip $(objcpp_objects)),)
1021$(objcpp_objects): .KATI_NINJA_POOL := $(my_pool)
1022$(objcpp_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.mm \
1023    $(my_additional_dependencies) $(CLANG_CXX)
1024	$(transform-$(PRIVATE_HOST)mm-to-o)
1025$(call include-depfiles-for-objs, $(objcpp_objects))
1026endif
1027
1028###########################################################
1029## AS: Compile .S files to .o.
1030###########################################################
1031
1032asm_sources_S := $(filter %.S,$(my_src_files))
1033dotdot_sources := $(filter ../%,$(asm_sources_S))
1034asm_sources_S := $(filter-out ../%,$(asm_sources_S))
1035asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
1036$(call track-src-file-obj,$(asm_sources_S),$(asm_objects_S))
1037
1038dotdot_objects_S :=
1039$(foreach s,$(dotdot_sources),\
1040  $(eval $(call compile-dotdot-s-file,$(s),\
1041    $(my_additional_dependencies),\
1042    dotdot_objects_S,\
1043    $(my_pool))))
1044$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects_S))
1045
1046ifneq ($(strip $(asm_objects_S)),)
1047$(asm_objects_S): .KATI_NINJA_POOL := $(my_pool)
1048$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \
1049    $(my_additional_dependencies) $(CLANG)
1050	$(transform-$(PRIVATE_HOST)s-to-o)
1051$(call include-depfiles-for-objs, $(asm_objects_S))
1052endif
1053
1054asm_sources_s := $(filter %.s,$(my_src_files))
1055dotdot_sources := $(filter ../%,$(asm_sources_s))
1056asm_sources_s := $(filter-out ../%,$(asm_sources_s))
1057asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
1058$(call track-src-file-obj,$(asm_sources_s),$(asm_objects_s))
1059
1060dotdot_objects_s :=
1061$(foreach s,$(dotdot_sources),\
1062  $(eval $(call compile-dotdot-s-file-no-deps,$(s),\
1063    $(my_additional_dependencies),\
1064    dotdot_objects_s,\
1065    $(my_pool))))
1066$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects_s))
1067
1068ifneq ($(strip $(asm_objects_s)),)
1069$(asm_objects_s): .KATI_NINJA_POOL := $(my_pool)
1070$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \
1071    $(my_additional_dependencies) $(CLANG)
1072	$(transform-$(PRIVATE_HOST)s-to-o)
1073endif
1074
1075asm_objects := $(dotdot_objects_S) $(dotdot_objects_s) $(asm_objects_S) $(asm_objects_s)
1076$(asm_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
1077
1078
1079# .asm for x86/x86_64 needs to be compiled with yasm.
1080asm_sources_asm := $(filter %.asm,$(my_src_files))
1081ifneq ($(strip $(asm_sources_asm)),)
1082asm_objects_asm := $(addprefix $(intermediates)/,$(asm_sources_asm:.asm=.o))
1083$(asm_objects_asm): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.asm \
1084    $(my_additional_dependencies) $(YASM)
1085	$(transform-asm-to-o)
1086$(call track-src-file-obj,$(asm_sources_asm),$(asm_objects_asm))
1087
1088asm_objects += $(asm_objects_asm)
1089endif
1090
1091###################################################################
1092## When compiling a CFI enabled target, use the .cfi variant of any
1093## static dependencies (where they exist).
1094##################################################################
1095define use_soong_cfi_static_libraries
1096  $(foreach l,$(1),$(if $(filter $(l),$(SOONG_CFI_STATIC_LIBRARIES)),\
1097      $(l).cfi,$(l)))
1098endef
1099
1100ifneq ($(filter cfi,$(my_sanitize)),)
1101  my_whole_static_libraries := $(call use_soong_cfi_static_libraries,\
1102    $(my_whole_static_libraries))
1103  my_static_libraries := $(call use_soong_cfi_static_libraries,\
1104    $(my_static_libraries))
1105endif
1106
1107ifneq ($(LOCAL_USE_VNDK),)
1108  my_soong_hwasan_static_libraries := $(SOONG_HWASAN_VENDOR_STATIC_LIBRARIES)
1109else
1110  my_soong_hwasan_static_libraries = $(SOONG_HWASAN_STATIC_LIBRARIES)
1111endif
1112
1113define use_soong_hwasan_static_libraries
1114  $(foreach l,$(1),$(if $(filter $(l),$(my_soong_hwasan_static_libraries)),\
1115      $(l).hwasan,$(l)))
1116endef
1117
1118ifneq ($(filter hwaddress,$(my_sanitize)),)
1119  my_whole_static_libraries := $(call use_soong_hwasan_static_libraries,\
1120    $(my_whole_static_libraries))
1121  my_static_libraries := $(call use_soong_hwasan_static_libraries,\
1122    $(my_static_libraries))
1123endif
1124
1125###########################################################
1126## When compiling against the VNDK, use LL-NDK libraries
1127###########################################################
1128ifneq ($(LOCAL_USE_VNDK),)
1129  #####################################################
1130  ## Soong modules may be built three times, once for
1131  ## /system, once for /vendor and once for /product.
1132  ## If we're using the VNDK, switch all soong
1133  ## libraries over to the /vendor or /product variant.
1134  #####################################################
1135  ifeq ($(LOCAL_USE_VNDK_PRODUCT),true)
1136    my_whole_static_libraries := $(foreach l,$(my_whole_static_libraries),\
1137      $(if $(SPLIT_PRODUCT.STATIC_LIBRARIES.$(l)),$(l).product,$(l)))
1138    my_static_libraries := $(foreach l,$(my_static_libraries),\
1139      $(if $(SPLIT_PRODUCT.STATIC_LIBRARIES.$(l)),$(l).product,$(l)))
1140    my_shared_libraries := $(foreach l,$(my_shared_libraries),\
1141      $(if $(SPLIT_PRODUCT.SHARED_LIBRARIES.$(l)),$(l).product,$(l)))
1142    my_system_shared_libraries := $(foreach l,$(my_system_shared_libraries),\
1143      $(if $(SPLIT_PRODUCT.SHARED_LIBRARIES.$(l)),$(l).product,$(l)))
1144    my_header_libraries := $(foreach l,$(my_header_libraries),\
1145      $(if $(SPLIT_PRODUCT.HEADER_LIBRARIES.$(l)),$(l).product,$(l)))
1146  else
1147    my_whole_static_libraries := $(foreach l,$(my_whole_static_libraries),\
1148      $(if $(SPLIT_VENDOR.STATIC_LIBRARIES.$(l)),$(l).vendor,$(l)))
1149    my_static_libraries := $(foreach l,$(my_static_libraries),\
1150      $(if $(SPLIT_VENDOR.STATIC_LIBRARIES.$(l)),$(l).vendor,$(l)))
1151    my_shared_libraries := $(foreach l,$(my_shared_libraries),\
1152      $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
1153    my_system_shared_libraries := $(foreach l,$(my_system_shared_libraries),\
1154      $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
1155    my_header_libraries := $(foreach l,$(my_header_libraries),\
1156      $(if $(SPLIT_VENDOR.HEADER_LIBRARIES.$(l)),$(l).vendor,$(l)))
1157  endif
1158endif
1159
1160# Platform can use vendor public libraries. If a required shared lib is one of
1161# the vendor public libraries, the lib is switched to the stub version of the lib.
1162ifeq ($(LOCAL_USE_VNDK),)
1163  my_shared_libraries := $(foreach l,$(my_shared_libraries),\
1164    $(if $(filter $(l),$(VENDOR_PUBLIC_LIBRARIES)),$(l).vendorpublic,$(l)))
1165endif
1166
1167###########################################################
1168## When compiling against the NDK, use SDK variants of Soong libraries
1169###########################################################
1170
1171ifneq ($(LOCAL_SDK_VERSION),)
1172  my_whole_static_libraries := $(call use_soong_sdk_libraries,$(my_whole_static_libraries))
1173  my_static_libraries := $(call use_soong_sdk_libraries,$(my_static_libraries))
1174  my_shared_libraries := $(call use_soong_sdk_libraries,$(my_shared_libraries))
1175  my_system_shared_libraries := $(call use_soong_sdk_libraries,$(my_system_shared_libraries))
1176  my_header_libraries := $(call use_soong_sdk_libraries,$(my_header_libraries))
1177endif
1178
1179##########################################################
1180## Set up installed module dependency
1181## We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for
1182## they may cusomize their install path with LOCAL_MODULE_PATH
1183##########################################################
1184# Get the list of INSTALLED libraries as module names.
1185ifneq ($(LOCAL_SDK_VERSION),)
1186  installed_shared_library_module_names := \
1187      $(my_shared_libraries)
1188else
1189  installed_shared_library_module_names := \
1190      $(my_shared_libraries) $(my_system_shared_libraries)
1191endif
1192
1193# The real dependency will be added after all Android.mks are loaded and the install paths
1194# of the shared libraries are determined.
1195ifdef LOCAL_INSTALLED_MODULE
1196ifdef installed_shared_library_module_names
1197$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
1198    $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(installed_shared_library_module_names))
1199endif
1200endif
1201
1202
1203####################################################
1204## Verify that NDK-built libraries only link against
1205## other NDK-built libraries
1206####################################################
1207
1208include $(BUILD_SYSTEM)/allowed_ndk_types.mk
1209
1210ifdef LOCAL_SDK_VERSION
1211my_link_type := native:ndk:$(my_ndk_stl_family):$(my_ndk_stl_link_type)
1212my_warn_types := $(my_warn_ndk_types)
1213my_allowed_types := $(my_allowed_ndk_types)
1214else ifdef LOCAL_USE_VNDK
1215    _name := $(patsubst %.vendor,%,$(LOCAL_MODULE))
1216    _name := $(patsubst %.product,%,$(LOCAL_MODULE))
1217    ifneq ($(filter $(_name),$(VNDK_CORE_LIBRARIES) $(VNDK_SAMEPROCESS_LIBRARIES) $(LLNDK_LIBRARIES)),)
1218        ifeq ($(filter $(_name),$(VNDK_PRIVATE_LIBRARIES)),)
1219            my_link_type := native:vndk
1220        else
1221            my_link_type := native:vndk_private
1222        endif
1223        my_warn_types :=
1224        my_allowed_types := native:vndk native:vndk_private
1225    else ifeq ($(LOCAL_USE_VNDK_PRODUCT),true)
1226        # Modules installed to /product cannot directly depend on modules marked
1227        # with vendor_available: false
1228        my_link_type := native:product
1229        my_warn_types :=
1230        my_allowed_types := native:product native:vndk native:platform_vndk
1231    else
1232        # Modules installed to /vendor cannot directly depend on modules marked
1233        # with vendor_available: false
1234        my_link_type := native:vendor
1235        my_warn_types :=
1236        my_allowed_types := native:vendor native:vndk native:platform_vndk
1237    endif
1238else ifneq ($(filter $(TARGET_RECOVERY_OUT)/%,$(call get_non_asan_path,$(LOCAL_MODULE_PATH))),)
1239my_link_type := native:recovery
1240my_warn_types :=
1241# TODO(b/113303515) remove native:platform and my_allowed_ndk_types
1242my_allowed_types := native:recovery native:platform native:platform_vndk $(my_allowed_ndk_types)
1243else
1244my_link_type := native:platform
1245my_warn_types := $(my_warn_ndk_types)
1246my_allowed_types := $(my_allowed_ndk_types) native:platform native:platform_vndk
1247endif
1248
1249my_link_deps := $(addprefix STATIC_LIBRARIES:,$(my_whole_static_libraries) $(my_static_libraries))
1250ifneq ($(filter-out STATIC_LIBRARIES HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
1251my_link_deps += $(addprefix SHARED_LIBRARIES:,$(my_shared_libraries))
1252endif
1253
1254my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
1255my_common :=
1256include $(BUILD_SYSTEM)/link_type.mk
1257
1258###########################################################
1259## Common object handling.
1260###########################################################
1261
1262my_unused_src_files := $(filter-out $(logtags_sources) $(my_tracked_src_files),$(my_src_files) $(my_gen_src_files))
1263ifneq ($(my_unused_src_files),)
1264  $(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Unused source files: $(my_unused_src_files))
1265endif
1266
1267# some rules depend on asm_objects being first.  If your code depends on
1268# being first, it's reasonable to require it to be assembly
1269normal_objects := \
1270    $(asm_objects) \
1271    $(cpp_objects) \
1272    $(gen_cpp_objects) \
1273    $(gen_asm_objects) \
1274    $(c_objects) \
1275    $(gen_c_objects) \
1276    $(objc_objects) \
1277    $(objcpp_objects)
1278
1279new_order_normal_objects := $(foreach f,$(my_src_files),$(my_src_file_obj_$(f)))
1280new_order_normal_objects += $(foreach f,$(my_gen_src_files),$(my_src_file_obj_$(f)))
1281
1282ifneq ($(sort $(normal_objects)),$(sort $(new_order_normal_objects)))
1283$(warning $(LOCAL_MODULE_MAKEFILE) Internal build system warning: New object list does not match old)
1284$(info Only in old: $(filter-out $(new_order_normal_objects),$(sort $(normal_objects))))
1285$(info Only in new: $(filter-out $(normal_objects),$(sort $(new_order_normal_objects))))
1286endif
1287
1288ifeq ($(BINARY_OBJECTS_ORDER),soong)
1289normal_objects := $(new_order_normal_objects)
1290endif
1291
1292normal_objects += $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
1293
1294all_objects := $(normal_objects) $(gen_o_objects)
1295
1296LOCAL_INTERMEDIATE_TARGETS += $(all_objects)
1297
1298# Cleanup file tracking
1299$(foreach f,$(my_tracked_gen_files),$(eval my_src_file_gen_$(s):=))
1300my_tracked_gen_files :=
1301$(foreach f,$(my_tracked_src_files),$(eval my_src_file_obj_$(s):=))
1302my_tracked_src_files :=
1303
1304my_c_includes += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(generated_sources_dir)
1305
1306# The platform JNI header is for platform modules only.
1307ifeq ($(LOCAL_SDK_VERSION)$(LOCAL_USE_VNDK),)
1308  my_c_includes += $(JNI_H_INCLUDE)
1309endif
1310
1311my_c_includes := $(foreach inc,$(my_c_includes),$(call clean-path,$(inc)))
1312
1313my_outside_includes := $(filter-out $(OUT_DIR)/%,$(filter /%,$(my_c_includes)) $(filter ../%,$(my_c_includes)))
1314ifneq ($(my_outside_includes),)
1315  ifeq ($(BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS),true)
1316    $(call pretty-warning,C_INCLUDES must be under the source or output directories: $(my_outside_includes))
1317  else
1318    $(call pretty-error,C_INCLUDES must be under the source or output directories: $(my_outside_includes))
1319  endif
1320endif
1321
1322# all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES;
1323# use normal_objects here to avoid creating circular dependencies. This assumes
1324# that custom build rules which generate .o files don't consume other generated
1325# sources as input (or if they do they take care of that dependency themselves).
1326$(normal_objects) : | $(my_generated_sources)
1327ALL_C_CPP_ETC_OBJECTS += $(all_objects)
1328
1329
1330###########################################################
1331# Standard library handling.
1332###########################################################
1333
1334###########################################################
1335# The list of libraries that this module will link against are in
1336# these variables.  Each is a list of bare module names like "libc libm".
1337#
1338# LOCAL_SHARED_LIBRARIES
1339# LOCAL_STATIC_LIBRARIES
1340# LOCAL_WHOLE_STATIC_LIBRARIES
1341#
1342# We need to convert the bare names into the dependencies that
1343# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
1344# LOCAL_BUILT_MODULE should depend on the BUILT versions of the
1345# libraries, so that simply building this module doesn't force
1346# an install of a library.  Similarly, LOCAL_INSTALLED_MODULE
1347# should depend on the INSTALLED versions of the libraries so
1348# that they get installed when this module does.
1349###########################################################
1350# NOTE:
1351# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
1352# module without leaving anything out, which is useful for turning
1353# a collection of .a files into a .so file.  Linking against a
1354# normal STATIC_LIBRARY will only pull in code/symbols that are
1355# referenced by the module. (see gcc/ld's --whole-archive option)
1356###########################################################
1357
1358# Get the list of BUILT libraries, which are under
1359# various intermediates directories.
1360so_suffix := $($(my_prefix)SHLIB_SUFFIX)
1361a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
1362
1363ifneq ($(LOCAL_SDK_VERSION),)
1364built_shared_libraries := \
1365    $(foreach lib,$(my_shared_libraries), \
1366      $(call intermediates-dir-for, \
1367        SHARED_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(so_suffix))
1368built_shared_library_deps := $(addsuffix .toc, $(built_shared_libraries))
1369
1370# Add the NDK libraries to the built module dependency
1371my_system_shared_libraries_fullpath := \
1372    $(my_ndk_stl_shared_lib_fullpath) \
1373    $(addprefix $(my_ndk_sysroot_lib)/, \
1374        $(addsuffix $(so_suffix), $(my_system_shared_libraries)))
1375
1376# We need to preserve the ordering of LOCAL_SHARED_LIBRARIES regardless of
1377# whether the libs are generated or prebuilt, so we simply can't split into two
1378# lists and use addprefix.
1379my_ndk_shared_libraries_fullpath := \
1380    $(foreach _lib,$(my_ndk_shared_libraries),\
1381        $(if $(filter $(NDK_MIGRATED_LIBS),$(_lib)),\
1382            $(my_built_ndk_libs)/$(_lib)$(so_suffix),\
1383            $(my_ndk_sysroot_lib)/$(_lib)$(so_suffix)))
1384
1385built_shared_libraries += \
1386    $(my_ndk_shared_libraries_fullpath) \
1387    $(my_system_shared_libraries_fullpath) \
1388
1389built_shared_library_deps += \
1390    $(my_ndk_shared_libraries_fullpath) \
1391    $(my_system_shared_libraries_fullpath) \
1392
1393else
1394built_shared_libraries := \
1395    $(foreach lib,$(installed_shared_library_module_names), \
1396      $(call intermediates-dir-for, \
1397        SHARED_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(so_suffix))
1398built_shared_library_deps := $(addsuffix .toc, $(built_shared_libraries))
1399my_system_shared_libraries_fullpath :=
1400endif
1401
1402built_static_libraries := \
1403    $(foreach lib,$(my_static_libraries), \
1404      $(call intermediates-dir-for, \
1405        STATIC_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(a_suffix))
1406
1407ifdef LOCAL_SDK_VERSION
1408built_static_libraries += $(my_ndk_stl_static_lib)
1409endif
1410
1411built_whole_libraries := \
1412    $(foreach lib,$(my_whole_static_libraries), \
1413      $(call intermediates-dir-for, \
1414        STATIC_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(a_suffix))
1415
1416# We don't care about installed static libraries, since the
1417# libraries have already been linked into the module at that point.
1418# We do, however, care about the NOTICE files for any static
1419# libraries that we use. (see notice_files.mk)
1420installed_static_library_notice_file_targets := \
1421    $(foreach lib,$(my_static_libraries) $(my_whole_static_libraries), \
1422      NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST$(if $(my_host_cross),_CROSS,),TARGET)-STATIC_LIBRARIES-$(lib))
1423
1424$(notice_target): | $(installed_static_library_notice_file_targets)
1425$(LOCAL_INSTALLED_MODULE): | $(notice_target)
1426
1427# Default is -fno-rtti.
1428ifeq ($(strip $(LOCAL_RTTI_FLAG)),)
1429LOCAL_RTTI_FLAG := -fno-rtti
1430endif
1431
1432###########################################################
1433# Rule-specific variable definitions
1434###########################################################
1435
1436my_cflags += $(LOCAL_CLANG_CFLAGS)
1437my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS)
1438my_cppflags += $(LOCAL_CLANG_CPPFLAGS)
1439my_asflags += $(LOCAL_CLANG_ASFLAGS)
1440my_ldflags += $(LOCAL_CLANG_LDFLAGS)
1441my_cflags += $(LOCAL_CLANG_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CFLAGS_$(my_32_64_bit_suffix))
1442my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CONLYFLAGS_$(my_32_64_bit_suffix))
1443my_cppflags += $(LOCAL_CLANG_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CPPFLAGS_$(my_32_64_bit_suffix))
1444my_ldflags += $(LOCAL_CLANG_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_LDFLAGS_$(my_32_64_bit_suffix))
1445my_asflags += $(LOCAL_CLANG_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_ASFLAGS_$(my_32_64_bit_suffix))
1446my_cflags := $(call convert-to-clang-flags,$(my_cflags))
1447my_cppflags := $(call convert-to-clang-flags,$(my_cppflags))
1448my_asflags := $(call convert-to-clang-flags,$(my_asflags))
1449my_ldflags := $(call convert-to-clang-flags,$(my_ldflags))
1450
1451ifeq ($(my_fdo_build), true)
1452  my_cflags := $(patsubst -Os,-O2,$(my_cflags))
1453  fdo_incompatible_flags := -fno-early-inlining -finline-limit=%
1454  my_cflags := $(filter-out $(fdo_incompatible_flags),$(my_cflags))
1455endif
1456
1457# No one should ever use this flag. On GCC it's mere presence will disable all
1458# warnings, even those that are specified after it (contrary to typical warning
1459# flag behavior). This circumvents CFLAGS_NO_OVERRIDE from forcibly enabling the
1460# warnings that are *always* bugs.
1461my_illegal_flags := -w
1462my_cflags := $(filter-out $(my_illegal_flags),$(my_cflags))
1463my_cppflags := $(filter-out $(my_illegal_flags),$(my_cppflags))
1464my_conlyflags := $(filter-out $(my_illegal_flags),$(my_conlyflags))
1465
1466# We can enforce some rules more strictly in the code we own. my_strict
1467# indicates if this is code that we can be stricter with. If we have rules that
1468# we want to apply to *our* code (but maybe can't for vendor/device specific
1469# things), we could extend this to be a ternary value.
1470my_strict := true
1471ifneq ($(filter external/%,$(LOCAL_PATH)),)
1472    my_strict := false
1473endif
1474
1475# Can be used to make some annotations stricter for code we can fix (such as
1476# when we mark functions as deprecated).
1477ifeq ($(my_strict),true)
1478    my_cflags += -DANDROID_STRICT
1479endif
1480
1481# Check if -Werror or -Wno-error is used in C compiler flags.
1482# Header libraries do not need cflags.
1483my_all_cflags := $(my_cflags) $(my_cppflags) $(my_cflags_no_override)
1484ifneq (HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS))
1485  # Prebuilt modules do not need cflags.
1486  ifeq (,$(LOCAL_PREBUILT_MODULE_FILE))
1487    # Issue warning if -Wno-error is used.
1488    ifneq (,$(filter -Wno-error,$(my_all_cflags)))
1489      $(eval MODULES_USING_WNO_ERROR := $(MODULES_USING_WNO_ERROR) $(LOCAL_MODULE_MAKEFILE):$(LOCAL_MODULE))
1490    else
1491      # Issue warning if -Werror is not used. Add it.
1492      ifeq (,$(filter -Werror,$(my_all_cflags)))
1493        # Add -Wall -Werror unless the project is in the WARNING_ALLOWED project list.
1494        ifeq (,$(strip $(call find_warning_allowed_projects,$(LOCAL_PATH))))
1495          my_cflags := -Wall -Werror $(my_cflags)
1496        else
1497          $(eval MODULES_ADDED_WALL := $(MODULES_ADDED_WALL) $(LOCAL_MODULE_MAKEFILE):$(LOCAL_MODULE))
1498          my_cflags := -Wall $(my_cflags)
1499        endif
1500      endif
1501    endif
1502  endif
1503endif
1504
1505ifneq (,$(filter -Weverything,$(my_all_cflags)))
1506  ifeq (,$(ANDROID_TEMPORARILY_ALLOW_WEVERYTHING))
1507    $(call pretty-error, -Weverything is not allowed in Android.mk files.\
1508      Build with `m ANDROID_TEMPORARILY_ALLOW_WEVERYTHING=true` to experiment locally with -Weverything.)
1509  endif
1510endif
1511
1512# Disable clang-tidy if it is not found.
1513ifeq ($(PATH_TO_CLANG_TIDY),)
1514  my_tidy_enabled := false
1515else
1516  # If LOCAL_TIDY is not defined, use global WITH_TIDY
1517  my_tidy_enabled := $(LOCAL_TIDY)
1518  ifeq ($(my_tidy_enabled),)
1519    my_tidy_enabled := $(WITH_TIDY)
1520  endif
1521endif
1522
1523# my_tidy_checks is empty if clang-tidy is disabled.
1524my_tidy_checks :=
1525my_tidy_flags :=
1526ifneq (,$(filter 1 true,$(my_tidy_enabled)))
1527  tidy_only: $(cpp_objects) $(c_objects) $(gen_c_objects) $(gen_cpp_objects)
1528  # Set up global default checks
1529  my_tidy_checks := $(WITH_TIDY_CHECKS)
1530  ifeq ($(my_tidy_checks),)
1531    my_tidy_checks := $(call default_global_tidy_checks,$(LOCAL_PATH))
1532  endif
1533  # Append local clang-tidy checks.
1534  ifneq ($(LOCAL_TIDY_CHECKS),)
1535    my_tidy_checks := $(my_tidy_checks),$(LOCAL_TIDY_CHECKS)
1536  endif
1537  my_tidy_flags := $(strip $(WITH_TIDY_FLAGS) $(LOCAL_TIDY_FLAGS))
1538  # If tidy flags are not specified, default to check all header files.
1539  ifeq ($(my_tidy_flags),)
1540    my_tidy_flags := $(call default_tidy_header_filter,$(LOCAL_PATH))
1541  endif
1542  # If clang-tidy is not enabled globally, add the -quiet flag.
1543  ifeq (,$(filter 1 true,$(WITH_TIDY)))
1544    my_tidy_flags += -quiet -extra-arg-before=-fno-caret-diagnostics
1545  endif
1546
1547  ifneq ($(my_tidy_checks),)
1548    # We might be using the static analyzer through clang-tidy.
1549    # https://bugs.llvm.org/show_bug.cgi?id=32914
1550    my_tidy_flags += -extra-arg-before=-D__clang_analyzer__
1551
1552    # A recent change in clang-tidy (r328258) enabled destructor inlining,
1553    # which appears to cause a number of false positives. Until that's
1554    # resolved, this turns off the effects of r328258.
1555    # https://bugs.llvm.org/show_bug.cgi?id=37459
1556    my_tidy_flags += -extra-arg-before=-Xclang
1557    my_tidy_flags += -extra-arg-before=-analyzer-config
1558    my_tidy_flags += -extra-arg-before=-Xclang
1559    my_tidy_flags += -extra-arg-before=c++-temp-dtor-inlining=false
1560  endif
1561endif
1562
1563my_tidy_checks := $(subst $(space),,$(my_tidy_checks))
1564
1565# Add dependency of clang-tidy and clang-tidy.sh
1566ifneq ($(my_tidy_checks),)
1567  $(cpp_objects): $(intermediates)/%.o: $(PATH_TO_CLANG_TIDY)
1568  $(c_objects): $(intermediates)/%.o: $(PATH_TO_CLANG_TIDY)
1569  $(gen_cpp_objects): $(intermediates)/%.o: $(PATH_TO_CLANG_TIDY)
1570  $(gen_c_objects): $(intermediates)/%.o: $(PATH_TO_CLANG_TIDY)
1571endif
1572
1573# Move -l* entries from ldflags to ldlibs, and everything else to ldflags
1574my_ldlib_flags := $(my_ldflags) $(my_ldlibs)
1575my_ldlibs := $(filter -l%,$(my_ldlib_flags))
1576my_ldflags := $(filter-out -l%,$(my_ldlib_flags))
1577
1578# One last verification check for ldlibs
1579my_allowed_ldlibs :=
1580ifndef LOCAL_IS_HOST_MODULE
1581  ifneq ($(LOCAL_SDK_VERSION),)
1582    my_allowed_ldlibs := $(addprefix -l,$(NDK_PREBUILT_SHARED_LIBRARIES))
1583  endif
1584else
1585  my_allowed_ldlibs := $($(my_prefix)AVAILABLE_LIBRARIES)
1586endif
1587
1588my_bad_ldlibs := $(filter-out $(my_allowed_ldlibs),$(my_ldlibs))
1589ifneq ($(my_bad_ldlibs),)
1590  $(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Bad LOCAL_LDLIBS entries: $(my_bad_ldlibs))
1591endif
1592
1593# my_cxx_ldlibs may contain linker flags need to wrap certain libraries
1594# (start-group/end-group), so append after the check above.
1595my_ldlibs += $(my_cxx_ldlibs)
1596
1597###########################################################
1598## Define PRIVATE_ variables from global vars
1599###########################################################
1600ifndef LOCAL_IS_HOST_MODULE
1601ifdef LOCAL_USE_VNDK
1602my_target_global_c_includes := \
1603    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_INCLUDES)
1604my_target_global_c_system_includes := \
1605    $(TARGET_OUT_HEADERS) \
1606    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_SYSTEM_INCLUDES)
1607else ifdef LOCAL_SDK_VERSION
1608my_target_global_c_includes :=
1609my_target_global_c_system_includes := $(my_ndk_stl_include_path) $(my_ndk_sysroot_include)
1610else ifdef BOARD_VNDK_VERSION
1611my_target_global_c_includes := $(SRC_HEADERS) \
1612    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_INCLUDES) \
1613    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
1614my_target_global_c_system_includes := $(SRC_SYSTEM_HEADERS) \
1615    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_SYSTEM_INCLUDES) \
1616    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_SYSTEM_INCLUDES)
1617else
1618my_target_global_c_includes := $(SRC_HEADERS) \
1619    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_INCLUDES) \
1620    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
1621my_target_global_c_system_includes := $(SRC_SYSTEM_HEADERS) $(TARGET_OUT_HEADERS) \
1622    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_SYSTEM_INCLUDES) \
1623    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_SYSTEM_INCLUDES)
1624endif
1625
1626my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CFLAGS)
1627my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CONLYFLAGS) $(my_c_std_conlyflags)
1628my_target_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CPPFLAGS) $(my_cpp_std_cppflags)
1629ifeq ($(my_use_clang_lld),true)
1630  my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LLDFLAGS)
1631  include $(BUILD_SYSTEM)/pack_dyn_relocs_setup.mk
1632  ifeq ($(my_pack_module_relocations),true)
1633    my_target_global_ldflags += -Wl,--pack-dyn-relocs=android+relr -Wl,--use-android-relr-tags
1634  else
1635    my_target_global_ldflags += -Wl,--pack-dyn-relocs=none
1636  endif
1637else
1638  my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LDFLAGS)
1639endif # my_use_clang_lld
1640
1641my_target_triple := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)TRIPLE)
1642ifndef LOCAL_IS_HOST_MODULE
1643  my_target_triple_flag := -target $(my_target_triple)$(my_api_level)
1644else
1645  my_target_triple_flag := -target $(my_target_triple)
1646endif
1647my_asflags += $(my_target_triple_flag)
1648my_cflags += $(my_target_triple_flag)
1649my_ldflags += $(my_target_triple_flag)
1650
1651$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_INCLUDES := $(my_target_global_c_includes)
1652$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_SYSTEM_INCLUDES := $(my_target_global_c_system_includes)
1653$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
1654$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CONLYFLAGS := $(my_target_global_conlyflags)
1655$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags)
1656$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
1657
1658else # LOCAL_IS_HOST_MODULE
1659
1660my_host_global_c_includes := $(SRC_HEADERS) \
1661    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
1662my_host_global_c_system_includes := $(SRC_SYSTEM_HEADERS) \
1663    $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_SYSTEM_INCLUDES)
1664
1665my_host_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CFLAGS)
1666my_host_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CONLYFLAGS) $(my_c_std_conlyflags)
1667my_host_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CPPFLAGS) $(my_cpp_std_cppflags)
1668ifeq ($(my_use_clang_lld),true)
1669  my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LLDFLAGS)
1670else
1671  my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LDFLAGS)
1672endif # my_use_clang_lld
1673
1674$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_INCLUDES := $(my_host_global_c_includes)
1675$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_SYSTEM_INCLUDES := $(my_host_global_c_system_includes)
1676$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CFLAGS := $(my_host_global_cflags)
1677$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CONLYFLAGS := $(my_host_global_conlyflags)
1678$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CPPFLAGS := $(my_host_global_cppflags)
1679$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_LDFLAGS := $(my_host_global_ldflags)
1680endif # LOCAL_IS_HOST_MODULE
1681
1682# To enable coverage for a given module, set LOCAL_NATIVE_COVERAGE=true and
1683# build with NATIVE_COVERAGE=true in your enviornment.
1684ifeq ($(NATIVE_COVERAGE),true)
1685    ifeq ($(my_native_coverage),true)
1686        # Note that clang coverage doesn't play nicely with acov out of the box.
1687        # Clang apparently generates .gcno files that aren't compatible with
1688        # gcov-4.8.  This can be solved by installing gcc-4.6 and invoking lcov
1689        # with `--gcov-tool /usr/bin/gcov-4.6`.
1690        #
1691        # http://stackoverflow.com/questions/17758126/clang-code-coverage-invalid-output
1692        my_cflags += --coverage -O0
1693        my_ldflags += --coverage
1694    endif
1695
1696    my_coverage_lib := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)LIBPROFILE_RT)
1697
1698    $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_COVERAGE_LIB := $(my_coverage_lib)
1699    $(LOCAL_INTERMEDIATE_TARGETS): $(my_coverage_lib)
1700endif
1701
1702####################################################
1703## Import includes
1704####################################################
1705imported_includes := $(strip \
1706    $(if $(LOCAL_USE_VNDK),\
1707      $(call intermediates-dir-for,HEADER_LIBRARIES,device_kernel_headers,$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))) \
1708    $(foreach l, $(installed_shared_library_module_names), \
1709      $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))) \
1710    $(foreach l, $(my_static_libraries) $(my_whole_static_libraries), \
1711      $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))) \
1712    $(foreach l, $(my_header_libraries), \
1713      $(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))))
1714
1715$(foreach dep,$(imported_includes),\
1716  $(eval EXPORTS.$$(dep).USERS := $$(EXPORTS.$$(dep).USERS) $$(all_objects)))
1717
1718###########################################################
1719## Define PRIVATE_ variables used by multiple module types
1720###########################################################
1721$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
1722    $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
1723
1724ifeq ($(strip $(WITH_STATIC_ANALYZER)),)
1725  LOCAL_NO_STATIC_ANALYZER := true
1726endif
1727
1728ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
1729  my_syntax_arch := host
1730else
1731  my_syntax_arch := $($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
1732endif
1733
1734ifeq ($(strip $(my_cc)),)
1735  my_cc := $(my_cc_wrapper) $(CLANG)
1736endif
1737
1738SYNTAX_TOOLS_PREFIX := \
1739    $(LLVM_PREBUILTS_BASE)/$(BUILD_OS)-x86/$(LLVM_PREBUILTS_VERSION)/libexec
1740
1741ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
1742  my_cc := CCC_CC=$(CLANG) CLANG=$(CLANG) \
1743           $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer
1744endif
1745
1746$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(my_cc)
1747
1748ifeq ($(strip $(my_cxx)),)
1749  my_cxx := $(my_cxx_wrapper) $(CLANG_CXX)
1750endif
1751
1752ifeq ($(strip $(my_cxx_link)),)
1753  my_cxx_link := $(CLANG_CXX)
1754endif
1755
1756ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
1757  my_cxx := CCC_CXX=$(CLANG_CXX) CLANG_CXX=$(CLANG_CXX) \
1758            $(SYNTAX_TOOLS_PREFIX)/c++-analyzer
1759  my_cxx_link := CCC_CXX=$(CLANG_CXX) CLANG_CXX=$(CLANG_CXX) \
1760                 $(SYNTAX_TOOLS_PREFIX)/c++-analyzer
1761endif
1762
1763$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LINKER := $(my_linker)
1764$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(my_cxx)
1765$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX_LINK := $(my_cxx_link)
1766
1767$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
1768$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(my_asflags)
1769$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(my_conlyflags)
1770$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(my_cflags)
1771$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(my_cppflags)
1772$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS_NO_OVERRIDE := $(my_cflags_no_override)
1773$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS_NO_OVERRIDE := $(my_cppflags_no_override)
1774$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
1775$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
1776$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(my_c_includes)
1777$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORTED_INCLUDES := $(imported_includes)
1778$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(my_ldflags)
1779$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(my_ldlibs)
1780$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TIDY_CHECKS := $(my_tidy_checks)
1781$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TIDY_FLAGS := $(my_tidy_flags)
1782$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ARFLAGS := $(my_arflags)
1783
1784# this is really the way to get the files onto the command line instead
1785# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
1786$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
1787$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
1788$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
1789$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(strip $(all_objects))
1790
1791###########################################################
1792# Define library dependencies.
1793###########################################################
1794# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
1795all_libraries := \
1796    $(built_shared_library_deps) \
1797    $(my_system_shared_libraries_fullpath) \
1798    $(built_static_libraries) \
1799    $(built_whole_libraries)
1800
1801###########################################################
1802# Export includes
1803###########################################################
1804
1805# Headers exported by whole static libraries are also exported by this library.
1806export_include_deps := $(strip \
1807   $(foreach l,$(my_whole_static_libraries), \
1808     $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))))
1809# Re-export requested headers from shared libraries.
1810export_include_deps += $(strip \
1811   $(foreach l,$(LOCAL_EXPORT_SHARED_LIBRARY_HEADERS), \
1812     $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))))
1813# Re-export requested headers from static libraries.
1814export_include_deps += $(strip \
1815   $(foreach l,$(LOCAL_EXPORT_STATIC_LIBRARY_HEADERS), \
1816     $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))))
1817# Re-export requested headers from header libraries.
1818export_include_deps += $(strip \
1819   $(foreach l,$(LOCAL_EXPORT_HEADER_LIBRARY_HEADERS), \
1820     $(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))))
1821
1822ifneq ($(strip $(my_export_c_include_dirs)$(export_include_deps)),)
1823  EXPORTS_LIST += $(intermediates)
1824  EXPORTS.$(intermediates).FLAGS := $(foreach d,$(my_export_c_include_dirs),-I $(call clean-path,$(d)))
1825  EXPORTS.$(intermediates).REEXPORT := $(export_include_deps)
1826  EXPORTS.$(intermediates).DEPS := $(my_export_c_include_deps) $(my_generated_sources) $(LOCAL_EXPORT_C_INCLUDE_DEPS)
1827endif
1828
1829ifneq (,$(filter-out $(LOCAL_PATH)/%,$(my_export_c_include_dirs)))
1830my_soong_problems += non_local__export_c_include_dirs
1831endif
1832
1833SOONG_CONV.$(LOCAL_MODULE).PROBLEMS := \
1834    $(SOONG_CONV.$(LOCAL_MODULE).PROBLEMS) $(my_soong_problems)
1835SOONG_CONV.$(LOCAL_MODULE).DEPS := \
1836    $(SOONG_CONV.$(LOCAL_MODULE).DEPS) \
1837    $(filter-out $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY),\
1838        $(my_static_libraries) \
1839        $(my_whole_static_libraries) \
1840        $(my_shared_libraries) \
1841        $(my_system_shared_libraries))
1842SOONG_CONV.$(LOCAL_MODULE).TYPE := native
1843SOONG_CONV := $(SOONG_CONV) $(LOCAL_MODULE)
1844
1845###########################################################
1846# Coverage packaging.
1847###########################################################
1848ifeq ($(my_native_coverage),true)
1849my_gcno_objects := \
1850    $(cpp_objects) \
1851    $(gen_cpp_objects) \
1852    $(c_objects) \
1853    $(gen_c_objects) \
1854    $(objc_objects) \
1855    $(objcpp_objects)
1856
1857LOCAL_GCNO_FILES := $(patsubst %.o,%.gcno,$(my_gcno_objects))
1858$(foreach f,$(my_gcno_objects),$(eval $(call gcno-touch-rule,$(f),$(f:.o=.gcno))))
1859endif
1860