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