binary.mk revision 3bb168f10d8a8e7b4c0f2aa5840c21638a3d1fda
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
10#######################################
11
12##################################################
13# Compute the dependency of the shared libraries
14##################################################
15# On the target, we compile with -nostdlib, so we must add in the
16# default system shared libraries, unless they have requested not
17# to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value.  One would
18# supply that, for example, when building libc itself.
19ifdef LOCAL_IS_HOST_MODULE
20  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
21      my_system_shared_libraries :=
22  else
23      my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
24  endif
25else
26  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
27      my_system_shared_libraries := libc libm
28  else
29      my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
30  endif
31endif
32
33# The following LOCAL_ variables will be modified in this file.
34# Because the same LOCAL_ variables may be used to define modules for both 1st arch and 2nd arch,
35# we can't modify them in place.
36my_src_files := $(LOCAL_SRC_FILES)
37my_src_files_exclude := $(LOCAL_SRC_FILES_EXCLUDE)
38my_static_libraries := $(LOCAL_STATIC_LIBRARIES)
39my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES)
40my_shared_libraries := $(LOCAL_SHARED_LIBRARIES)
41my_cflags := $(LOCAL_CFLAGS)
42my_conlyflags := $(LOCAL_CONLYFLAGS)
43my_cppflags := $(LOCAL_CPPFLAGS)
44my_cflags_no_override := $(GLOBAL_CFLAGS_NO_OVERRIDE)
45my_cppflags_no_override := $(GLOBAL_CPPFLAGS_NO_OVERRIDE)
46my_ldflags := $(LOCAL_LDFLAGS)
47my_ldlibs := $(LOCAL_LDLIBS)
48my_asflags := $(LOCAL_ASFLAGS)
49my_cc := $(LOCAL_CC)
50my_cc_wrapper := $(CC_WRAPPER)
51my_cxx := $(LOCAL_CXX)
52my_cxx_wrapper := $(CXX_WRAPPER)
53my_c_includes := $(LOCAL_C_INCLUDES)
54my_generated_sources := $(LOCAL_GENERATED_SOURCES)
55my_native_coverage := $(LOCAL_NATIVE_COVERAGE)
56my_additional_dependencies := $(LOCAL_MODULE_MAKEFILE_DEP) $(LOCAL_ADDITIONAL_DEPENDENCIES)
57my_export_c_include_dirs := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
58
59ifdef LOCAL_IS_HOST_MODULE
60my_allow_undefined_symbols := true
61else
62my_allow_undefined_symbols := $(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS))
63endif
64
65my_ndk_sysroot :=
66my_ndk_sysroot_include :=
67my_ndk_sysroot_lib :=
68ifdef LOCAL_SDK_VERSION
69  ifdef LOCAL_NDK_VERSION
70    $(error $(LOCAL_PATH): LOCAL_NDK_VERSION is now retired.)
71  endif
72  ifdef LOCAL_IS_HOST_MODULE
73    $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
74  endif
75  my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources
76  my_ndk_sysroot := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
77  my_ndk_sysroot_include := $(my_ndk_sysroot)/usr/include
78
79  # x86_64 and and mips64 are both multilib toolchains, so their libraries are
80  # installed in /usr/lib64. Aarch64, on the other hand, is not a multilib
81  # compiler, so its libraries are in /usr/lib.
82  #
83  # Mips32r6 is yet another variation, with libraries installed in libr6.
84  #
85  # For the rest, the libraries are installed simply to /usr/lib.
86  ifneq (,$(filter x86_64 mips64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
87    my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/lib64
88  else ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
89    my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/libr6
90  else
91    my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/lib
92  endif
93
94  # The bionic linker now has support for packed relocations and gnu style
95  # hashes (which are much faster!), but shipping to older devices requires
96  # the old style hash. Fortunately, we can build with both and it'll work
97  # anywhere.
98  #
99  # This is not currently supported on MIPS architectures.
100  ifeq (,$(filter mips mips64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
101    my_ldflags += -Wl,--hash-style=both
102  endif
103
104  # We don't want to expose the relocation packer to the NDK just yet.
105  LOCAL_PACK_MODULE_RELOCATIONS := false
106
107  # Set up the NDK stl variant. Starting from NDK-r5 the c++ stl resides in a separate location.
108  # See ndk/docs/CPLUSPLUS-SUPPORT.html
109  my_ndk_stl_include_path :=
110  my_ndk_stl_shared_lib_fullpath :=
111  my_ndk_stl_shared_lib :=
112  my_ndk_stl_static_lib :=
113  my_ndk_stl_cppflags :=
114  my_cpu_variant := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)
115  ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
116    my_cpu_variant := mips32r6
117  endif
118  LOCAL_NDK_STL_VARIANT := $(strip $(LOCAL_NDK_STL_VARIANT))
119  ifeq (,$(LOCAL_NDK_STL_VARIANT))
120    LOCAL_NDK_STL_VARIANT := system
121  endif
122  ifneq (1,$(words $(filter none system stlport_static stlport_shared c++_static c++_shared gnustl_static, $(LOCAL_NDK_STL_VARIANT))))
123    $(error $(LOCAL_PATH): Unknown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT))
124  endif
125  ifeq (system,$(LOCAL_NDK_STL_VARIANT))
126    my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/system/include
127    my_system_shared_libraries += libstdc++
128  else # LOCAL_NDK_STL_VARIANT is not system
129  ifneq (,$(filter stlport_%, $(LOCAL_NDK_STL_VARIANT)))
130    my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/stlport/stlport
131    my_system_shared_libraries += libstdc++
132    ifeq (stlport_static,$(LOCAL_NDK_STL_VARIANT))
133      my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(my_cpu_variant)/libstlport_static.a
134    else
135      my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(my_cpu_variant)/libstlport_shared.so
136      my_ndk_stl_shared_lib := -lstlport_shared
137    endif
138  else # LOCAL_NDK_STL_VARIANT is not stlport_* either
139  ifneq (,$(filter c++_%, $(LOCAL_NDK_STL_VARIANT)))
140    my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/llvm-libc++/libcxx/include \
141                               $(my_ndk_source_root)/cxx-stl/llvm-libc++/gabi++/include \
142                               $(my_ndk_source_root)/android/support/include
143    ifeq (c++_static,$(LOCAL_NDK_STL_VARIANT))
144      my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/llvm-libc++/libs/$(my_cpu_variant)/libc++_static.a
145    else
146      my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/llvm-libc++/libs/$(my_cpu_variant)/libc++_shared.so
147      my_ndk_stl_shared_lib := -lc++_shared
148    endif
149    my_ndk_stl_cppflags := -std=c++11
150  else # LOCAL_NDK_STL_VARIANT is not c++_* either
151  ifneq (,$(filter gnustl_%, $(LOCAL_NDK_STL_VARIANT)))
152    my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/$($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_GCC_VERSION)/libs/$(my_cpu_variant)/include \
153                               $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/$($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_GCC_VERSION)/include
154    my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/$($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_GCC_VERSION)/libs/$(my_cpu_variant)/libgnustl_static.a
155  else # LOCAL_NDK_STL_VARIANT must be none
156    # Do nothing.
157  endif
158  endif
159  endif
160  endif
161endif
162
163# MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
164# all code is position independent, and then those warnings get promoted to
165# errors.
166ifneq ($($(my_prefix)OS),windows)
167ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES)
168my_cflags += -fpie
169else
170my_cflags += -fPIC
171endif
172endif
173
174ifdef LOCAL_IS_HOST_MODULE
175my_src_files += $(LOCAL_SRC_FILES_$($(my_prefix)OS)) $(LOCAL_SRC_FILES_$($(my_prefix)OS)_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
176my_static_libraries += $(LOCAL_STATIC_LIBRARIES_$($(my_prefix)OS))
177my_shared_libraries += $(LOCAL_SHARED_LIBRARIES_$($(my_prefix)OS))
178my_cflags += $(LOCAL_CFLAGS_$($(my_prefix)OS))
179my_cppflags += $(LOCAL_CPPFLAGS_$($(my_prefix)OS))
180my_ldflags += $(LOCAL_LDFLAGS_$($(my_prefix)OS))
181my_ldlibs += $(LOCAL_LDLIBS_$($(my_prefix)OS))
182my_asflags += $(LOCAL_ASFLAGS_$($(my_prefix)OS))
183my_c_includes += $(LOCAL_C_INCLUDES_$($(my_prefix)OS))
184my_generated_sources += $(LOCAL_GENERATED_SOURCES_$($(my_prefix)OS))
185endif
186
187my_src_files += $(LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SRC_FILES_$(my_32_64_bit_suffix))
188my_src_files_exclude += $(LOCAL_SRC_FILES_EXCLUDE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SRC_FILES_EXCLUDE_$(my_32_64_bit_suffix))
189my_shared_libraries += $(LOCAL_SHARED_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SHARED_LIBRARIES_$(my_32_64_bit_suffix))
190my_cflags += $(LOCAL_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CFLAGS_$(my_32_64_bit_suffix))
191my_cppflags += $(LOCAL_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CPPFLAGS_$(my_32_64_bit_suffix))
192my_ldflags += $(LOCAL_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_LDFLAGS_$(my_32_64_bit_suffix))
193my_asflags += $(LOCAL_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_ASFLAGS_$(my_32_64_bit_suffix))
194my_c_includes += $(LOCAL_C_INCLUDES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_C_INCLUDES_$(my_32_64_bit_suffix))
195my_generated_sources += $(LOCAL_GENERATED_SOURCES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_GENERATED_SOURCES_$(my_32_64_bit_suffix))
196
197my_missing_exclude_files := $(filter-out $(my_src_files),$(my_src_files_exclude))
198ifneq ($(my_missing_exclude_files),)
199$(warning Files are listed in LOCAL_SRC_FILES_EXCLUDE but not LOCAL_SRC_FILES)
200$(error $(my_missing_exclude_files))
201endif
202my_src_files := $(filter-out $(my_src_files_exclude),$(my_src_files))
203
204my_clang := $(strip $(LOCAL_CLANG))
205ifdef LOCAL_CLANG_$(my_32_64_bit_suffix)
206my_clang := $(strip $(LOCAL_CLANG_$(my_32_64_bit_suffix)))
207endif
208ifdef LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
209my_clang := $(strip $(LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
210endif
211
212# clang is enabled by default for host builds
213# enable it unless we've specifically disabled clang above
214ifdef LOCAL_IS_HOST_MODULE
215    ifneq ($($(my_prefix)OS),windows)
216    ifeq ($(my_clang),)
217        my_clang := true
218    endif
219    endif
220# Add option to make clang the default for device build
221else ifeq ($(USE_CLANG_PLATFORM_BUILD),true)
222    ifeq ($(my_clang),)
223        my_clang := true
224    endif
225endif
226
227my_cpp_std_version := -std=gnu++14
228
229ifneq ($(my_clang),true)
230    # GCC uses an invalid C++14 ABI (emits calls to
231    # __cxa_throw_bad_array_length, which is not a valid C++ RT ABI).
232    # http://b/25022512
233    my_cpp_std_version := -std=gnu++11
234endif
235
236ifdef LOCAL_SDK_VERSION
237    # The NDK handles this itself.
238    my_cpp_std_version :=
239endif
240
241ifdef LOCAL_IS_HOST_MODULE
242    ifneq ($(my_clang),true)
243        # The host GCC doesn't support C++14 (and is deprecated, so likely
244        # never will). Build these modules with C++11.
245        my_cpp_std_version := -std=gnu++11
246    endif
247endif
248
249my_cppflags := $(my_cpp_std_version) $(my_cppflags)
250
251
252# arch-specific static libraries go first so that generic ones can depend on them
253my_static_libraries := $(LOCAL_STATIC_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_STATIC_LIBRARIES_$(my_32_64_bit_suffix)) $(my_static_libraries)
254my_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)
255
256include $(BUILD_SYSTEM)/cxx_stl_setup.mk
257
258# Add static HAL libraries
259ifdef LOCAL_HAL_STATIC_LIBRARIES
260$(foreach lib, $(LOCAL_HAL_STATIC_LIBRARIES), \
261    $(eval b_lib := $(filter $(lib).%,$(BOARD_HAL_STATIC_LIBRARIES)))\
262    $(if $(b_lib), $(eval my_static_libraries += $(b_lib)),\
263                   $(eval my_static_libraries += $(lib).default)))
264b_lib :=
265endif
266
267ifneq ($(strip $(CUSTOM_$(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)LINKER)),)
268  my_linker := $(CUSTOM_$(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)LINKER)
269else
270  my_linker := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LINKER)
271endif
272
273include $(BUILD_SYSTEM)/config_sanitizers.mk
274
275# Add in libcompiler_rt for all regular device builds
276ifeq (,$(LOCAL_SDK_VERSION)$(WITHOUT_LIBCOMPILER_RT))
277  my_static_libraries += $(COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES)
278endif
279
280####################################################
281## Add FDO flags if FDO is turned on and supported
282## Please note that we will do option filtering during FDO build.
283## i.e. Os->O2, remove -fno-early-inline and -finline-limit.
284##################################################################
285my_fdo_build :=
286ifneq ($(filter true always, $(LOCAL_FDO_SUPPORT)),)
287  ifeq ($(BUILD_FDO_INSTRUMENT),true)
288    my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_CFLAGS)
289    my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_LDFLAGS)
290    my_fdo_build := true
291  else ifneq ($(filter true,$(BUILD_FDO_OPTIMIZE))$(filter always,$(LOCAL_FDO_SUPPORT)),)
292    my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_OPTIMIZE_CFLAGS)
293    my_fdo_build := true
294  endif
295  # Disable ccache (or other compiler wrapper) except gomacc, which
296  # can handle -fprofile-use properly.
297  my_cc_wrapper := $(filter $(GOMA_CC),$(my_cc_wrapper))
298  my_cxx_wrapper := $(filter $(GOMA_CC),$(my_cxx_wrapper))
299endif
300
301###########################################################
302## Explicitly declare assembly-only __ASSEMBLY__ macro for
303## assembly source
304###########################################################
305my_asflags += -D__ASSEMBLY__
306
307
308###########################################################
309## Define PRIVATE_ variables from global vars
310###########################################################
311ifndef LOCAL_IS_HOST_MODULE
312ifdef LOCAL_SDK_VERSION
313my_target_project_includes :=
314my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_sysroot_include)
315my_target_global_cppflags := $(my_ndk_stl_cppflags)
316else
317my_target_project_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PROJECT_INCLUDES)
318my_target_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_C_INCLUDES)
319my_target_global_cppflags :=
320endif # LOCAL_SDK_VERSION
321
322ifeq ($(my_clang),true)
323my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CFLAGS)
324my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CONLYFLAGS)
325my_target_global_cppflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CPPFLAGS)
326my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_LDFLAGS)
327else
328my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CFLAGS)
329my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CONLYFLAGS)
330my_target_global_cppflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CPPFLAGS)
331my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LDFLAGS)
332endif # my_clang
333
334$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes)
335$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes)
336$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
337$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CONLYFLAGS := $(my_target_global_conlyflags)
338$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags)
339$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
340
341else # LOCAL_IS_HOST_MODULE
342
343ifeq ($(my_clang),true)
344my_host_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CFLAGS)
345my_host_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CONLYFLAGS)
346my_host_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CPPFLAGS)
347my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LDFLAGS)
348my_host_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
349else
350my_host_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)GLOBAL_CFLAGS)
351my_host_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)GLOBAL_CONLYFLAGS)
352my_host_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)GLOBAL_CPPFLAGS)
353my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)GLOBAL_LDFLAGS)
354my_host_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
355endif # my_clang
356
357$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_C_INCLUDES := $(my_host_c_includes)
358$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CFLAGS := $(my_host_global_cflags)
359$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CONLYFLAGS := $(my_host_global_conlyflags)
360$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CPPFLAGS := $(my_host_global_cppflags)
361$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_LDFLAGS := $(my_host_global_ldflags)
362endif # LOCAL_IS_HOST_MODULE
363
364# To enable coverage for a given module, set LOCAL_NATIVE_COVERAGE=true and
365# build with NATIVE_COVERAGE=true in your enviornment. Note that the build
366# system is not sensitive to changes to NATIVE_COVERAGE, so you should do a
367# clean build of your module after toggling it.
368ifeq ($(NATIVE_COVERAGE),true)
369    ifeq ($(my_native_coverage),true)
370        # Note that clang coverage doesn't play nicely with acov out of the box.
371        # Clang apparently generates .gcno files that aren't compatible with
372        # gcov-4.8.  This can be solved by installing gcc-4.6 and invoking lcov
373        # with `--gcov-tool /usr/bin/gcov-4.6`.
374        #
375        # http://stackoverflow.com/questions/17758126/clang-code-coverage-invalid-output
376        my_cflags += --coverage -O0
377        my_ldflags += --coverage
378    endif
379else
380    my_native_coverage := false
381endif
382
383ifeq ($(my_clang),true)
384    my_coverage_lib := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBPROFILE_RT)
385else
386    my_coverage_lib := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBGCOV)
387endif
388
389$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_COVERAGE_LIB := $(my_coverage_lib)
390
391###########################################################
392## Define PRIVATE_ variables used by multiple module types
393###########################################################
394$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
395    $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
396
397ifeq ($(strip $(WITH_SYNTAX_CHECK)),)
398  LOCAL_NO_SYNTAX_CHECK := true
399endif
400
401ifeq ($(strip $(WITH_STATIC_ANALYZER)),)
402  LOCAL_NO_STATIC_ANALYZER := true
403endif
404
405ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
406  my_syntax_arch := host
407else
408  my_syntax_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
409endif
410
411ifeq ($(strip $(my_cc)),)
412  ifeq ($(my_clang),true)
413    my_cc := $(CLANG)
414  else
415    my_cc := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)CC)
416  endif
417  my_cc := $(my_cc_wrapper) $(my_cc)
418endif
419ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
420  my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer $(my_syntax_arch) "$(my_cc)"
421else
422ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
423  my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-syntax $(my_syntax_arch) "$(my_cc)"
424endif
425endif
426$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(my_cc)
427
428ifeq ($(strip $(my_cxx)),)
429  ifeq ($(my_clang),true)
430    my_cxx := $(CLANG_CXX)
431  else
432    my_cxx := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)CXX)
433  endif
434  my_cxx := $(my_cxx_wrapper) $(my_cxx)
435endif
436ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
437  my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-analyzer $(my_syntax_arch) "$(my_cxx)"
438else
439ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
440  my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-syntax $(my_syntax_arch) "$(my_cxx)"
441endif
442endif
443$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LINKER := $(my_linker)
444$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(my_cxx)
445$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLANG := $(my_clang)
446
447# TODO: support a mix of standard extensions so that this isn't necessary
448LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
449ifeq ($(LOCAL_CPP_EXTENSION),)
450  LOCAL_CPP_EXTENSION := .cpp
451endif
452
453# Certain modules like libdl have to have symbols resolved at runtime and blow
454# up if --no-undefined is passed to the linker.
455ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
456ifeq ($(my_allow_undefined_symbols),)
457  my_ldflags +=  $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)NO_UNDEFINED_LDFLAGS)
458endif
459endif
460
461ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES))
462$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true
463else
464$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES :=
465endif
466
467###########################################################
468## Define arm-vs-thumb-mode flags.
469###########################################################
470LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
471ifeq ($($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH),arm)
472arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
473normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
474
475# Read the values from something like TARGET_arm_CFLAGS or
476# TARGET_thumb_CFLAGS.  HOST_(arm|thumb)_CFLAGS values aren't
477# actually used (although they are usually empty).
478arm_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(arm_objects_mode)_CFLAGS)
479normal_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(normal_objects_mode)_CFLAGS)
480ifeq ($(my_clang),true)
481arm_objects_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(arm_objects_cflags))
482normal_objects_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(normal_objects_cflags))
483endif
484
485else
486arm_objects_mode :=
487normal_objects_mode :=
488arm_objects_cflags :=
489normal_objects_cflags :=
490endif
491
492###########################################################
493## Define per-module debugging flags.  Users can turn on
494## debugging for a particular module by setting DEBUG_MODULE_ModuleName
495## to a non-empty value in their environment or buildspec.mk,
496## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
497## debug flags that they want to use.
498###########################################################
499ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
500  debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
501else
502  debug_cflags :=
503endif
504
505####################################################
506## Keep track of src -> obj mapping
507####################################################
508
509my_tracked_gen_files :=
510my_tracked_src_files :=
511
512###########################################################
513## Stuff source generated from one-off tools
514###########################################################
515$(my_generated_sources): PRIVATE_MODULE := $(my_register_name)
516
517my_gen_sources_copy := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(filter $(generated_sources_dir)/%,$(my_generated_sources)))
518
519$(my_gen_sources_copy): $(intermediates)/% : $(generated_sources_dir)/% | $(ACP)
520	@echo "Copy: $@"
521	$(copy-file-to-target)
522
523my_generated_sources := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(my_generated_sources))
524
525# Generated sources that will actually produce object files.
526# Other files (like headers) are allowed in LOCAL_GENERATED_SOURCES,
527# since other compiled sources may depend on them, and we set up
528# the dependencies.
529my_gen_src_files := $(filter %.c %$(LOCAL_CPP_EXTENSION) %.S %.s %.o,$(my_generated_sources))
530
531ALL_GENERATED_SOURCES += $(my_generated_sources)
532
533####################################################
534## Compile RenderScript with reflected C++
535####################################################
536
537renderscript_sources := $(filter %.rs %.fs,$(my_src_files))
538
539ifneq (,$(renderscript_sources))
540
541renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
542RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp
543renderscript_intermediate := $(intermediates)/renderscript
544
545renderscript_target_api :=
546
547ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
548renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
549else
550ifneq (,$(LOCAL_SDK_VERSION))
551# Set target-api for LOCAL_SDK_VERSIONs other than current.
552ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION)))
553renderscript_target_api := $(LOCAL_SDK_VERSION)
554endif
555endif  # LOCAL_SDK_VERSION is set
556endif  # LOCAL_RENDERSCRIPT_TARGET_API is set
557
558
559ifeq ($(LOCAL_RENDERSCRIPT_CC),)
560LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
561endif
562
563# Turn on all warnings and warnings as errors for RS compiles.
564# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
565renderscript_flags := -Wall -Werror
566renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
567# -m32 or -m64
568renderscript_flags += -m$(my_32_64_bit_suffix)
569
570renderscript_includes := \
571    $(TOPDIR)external/clang/lib/Headers \
572    $(TOPDIR)frameworks/rs/scriptc \
573    $(LOCAL_RENDERSCRIPT_INCLUDES)
574
575ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
576renderscript_includes := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
577endif
578
579bc_dep_files := $(addprefix $(renderscript_intermediate)/, \
580    $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources)))))
581
582$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(renderscript_includes)
583$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
584$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
585$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
586$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate)
587$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(renderscript_target_api)
588$(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files)
589$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
590	$(transform-renderscripts-to-cpp-and-bc)
591
592# include the dependency files (.d/.P) generated by llvm-rs-cc.
593$(call include-depfile,$(RenderScript_file_stamp).P,$(RenderScript_file_stamp))
594
595LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
596
597rs_generated_cpps := $(addprefix \
598    $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rs,%.cpp, \
599    $(notdir $(renderscript_sources)))))
600
601$(call track-src-file-gen,$(renderscript_sources),$(rs_generated_cpps))
602
603# This is just a dummy rule to make sure gmake doesn't skip updating the dependents.
604$(rs_generated_cpps) : $(RenderScript_file_stamp)
605	@echo "Updated RS generated cpp file $@."
606	$(hide) touch $@
607
608my_c_includes += $(renderscript_intermediate)
609my_generated_sources += $(rs_generated_cpps)
610
611endif
612
613
614###########################################################
615## Compile the .proto files to .cc (or .c) and then to .o
616###########################################################
617proto_sources := $(filter %.proto,$(my_src_files))
618proto_generated_objects :=
619proto_generated_headers :=
620ifneq ($(proto_sources),)
621proto_generated_sources_dir := $(generated_sources_dir)/proto
622proto_generated_obj_dir := $(intermediates)/proto
623
624ifneq (,$(filter nanopb-c nanopb-c-enable_malloc, $(LOCAL_PROTOC_OPTIMIZE_TYPE)))
625my_proto_source_suffix := .c
626my_proto_c_includes := external/nanopb-c
627my_protoc_flags := --nanopb_out=$(proto_generated_sources_dir) \
628    --plugin=external/nanopb-c/generator/protoc-gen-nanopb
629else
630my_proto_source_suffix := .cc
631my_proto_c_includes := external/protobuf/src
632my_cflags += -DGOOGLE_PROTOBUF_NO_RTTI
633my_protoc_flags := --cpp_out=$(proto_generated_sources_dir)
634endif
635my_proto_c_includes += $(proto_generated_sources_dir)
636
637proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
638proto_generated_sources := $(addprefix $(proto_generated_sources_dir)/, \
639    $(patsubst %.proto,%.pb$(my_proto_source_suffix),$(proto_sources_fullpath)))
640proto_generated_headers := $(patsubst %.pb$(my_proto_source_suffix),%.pb.h, $(proto_generated_sources))
641proto_generated_objects := $(addprefix $(proto_generated_obj_dir)/, \
642    $(patsubst %.proto,%.pb.o,$(proto_sources_fullpath)))
643$(call track-src-file-obj,$(proto_sources),$(proto_generated_objects))
644
645# Ensure the transform-proto-to-cc rule is only defined once in multilib build.
646ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined
647$(proto_generated_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
648$(proto_generated_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) $(my_protoc_flags)
649$(proto_generated_sources): $(proto_generated_sources_dir)/%.pb$(my_proto_source_suffix): %.proto $(PROTOC)
650	$(transform-proto-to-cc)
651
652# This is just a dummy rule to make sure gmake doesn't skip updating the dependents.
653$(proto_generated_headers): $(proto_generated_sources_dir)/%.pb.h: $(proto_generated_sources_dir)/%.pb$(my_proto_source_suffix)
654	@echo "Updated header file $@."
655	$(hide) touch $@
656
657$(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined := true
658endif  # transform-proto-to-cc rule included only once
659
660$(proto_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
661$(proto_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
662$(proto_generated_objects): $(proto_generated_obj_dir)/%.o: $(proto_generated_sources_dir)/%$(my_proto_source_suffix) $(proto_generated_headers)
663ifeq ($(my_proto_source_suffix),.c)
664	$(transform-$(PRIVATE_HOST)c-to-o)
665else
666	$(transform-$(PRIVATE_HOST)cpp-to-o)
667endif
668-include $(proto_generated_objects:%.o=%.P)
669
670my_c_includes += $(my_proto_c_includes)
671# Auto-export the generated proto source dir.
672my_export_c_include_dirs += $(my_proto_c_includes)
673
674ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc)
675    my_static_libraries += libprotobuf-c-nano-enable_malloc
676else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c)
677    my_static_libraries += libprotobuf-c-nano
678else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
679    ifdef LOCAL_SDK_VERSION
680        my_static_libraries += libprotobuf-cpp-full-ndk
681    else
682        my_shared_libraries += libprotobuf-cpp-full
683    endif
684else
685    ifdef LOCAL_SDK_VERSION
686        my_static_libraries += libprotobuf-cpp-lite-ndk
687    else
688        my_shared_libraries += libprotobuf-cpp-lite
689    endif
690endif
691endif  # $(proto_sources) non-empty
692
693###########################################################
694## Compile the .dbus-xml files to c++ headers
695###########################################################
696dbus_definitions := $(filter %.dbus-xml,$(my_src_files))
697dbus_generated_headers :=
698ifneq ($(dbus_definitions),)
699
700dbus_definition_paths := $(addprefix $(LOCAL_PATH)/,$(dbus_definitions))
701dbus_service_config := $(filter %dbus-service-config.json,$(my_src_files))
702dbus_service_config_path := $(addprefix $(LOCAL_PATH)/,$(dbus_service_config))
703
704# Mark these source files as not producing objects
705$(call track-src-file-obj,$(dbus_definitions) $(dbus_service_config),)
706
707dbus_gen_dir := $(generated_sources_dir)/dbus_bindings
708
709ifdef LOCAL_DBUS_PROXY_PREFIX
710dbus_header_dir := $(dbus_gen_dir)/include/$(LOCAL_DBUS_PROXY_PREFIX)
711dbus_headers := dbus-proxies.h
712else
713dbus_header_dir := $(dbus_gen_dir)
714dbus_headers := $(patsubst %.dbus-xml,%.h,$(dbus_definitions))
715endif
716dbus_generated_headers := $(addprefix $(dbus_header_dir)/,$(dbus_headers))
717
718# Ensure that we only define build rules once in multilib builds.
719ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_dbus_bindings_defined
720$(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_dbus_bindings_defined := true
721
722$(dbus_generated_headers): PRIVATE_MODULE := $(LOCAL_MODULE)
723$(dbus_generated_headers): PRIVATE_DBUS_SERVICE_CONFIG := $(dbus_service_config_path)
724$(dbus_generated_headers) : $(dbus_service_config_path) $(DBUS_GENERATOR)
725ifdef LOCAL_DBUS_PROXY_PREFIX
726$(dbus_generated_headers) : $(dbus_definition_paths)
727	$(generate-dbus-proxies)
728else
729$(dbus_generated_headers) : $(dbus_header_dir)/%.h : $(LOCAL_PATH)/%.dbus-xml
730	$(generate-dbus-adaptors)
731endif  # $(LOCAL_DBUS_PROXY_PREFIX)
732endif  # $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_dbus_bindings_defined
733
734ifdef LOCAL_DBUS_PROXY_PREFIX
735# Auto-export the generated dbus proxy directory.
736my_export_c_include_dirs += $(dbus_gen_dir)/include
737my_c_includes += $(dbus_gen_dir)/include
738else
739my_export_c_include_dirs += $(dbus_header_dir)
740my_c_includes += $(dbus_header_dir)
741endif  # $(LOCAL_DBUS_PROXY_PREFIX)
742
743my_generated_sources += $(dbus_generated_headers)
744
745endif  # $(dbus_definitions) non-empty
746
747
748###########################################################
749## AIDL: Compile .aidl files to .cpp and .h files
750###########################################################
751aidl_src := $(strip $(filter %.aidl,$(my_src_files)))
752aidl_gen_cpp :=
753ifneq ($(aidl_src),)
754
755# Use the intermediates directory to avoid writing our own .cpp -> .o rules.
756aidl_gen_cpp_root := $(intermediates)/aidl-generated/src
757aidl_gen_include_root := $(intermediates)/aidl-generated/include
758
759# Multi-architecture builds have distinct intermediates directories.
760# Thus we'll actually generate source for each architecture.
761$(foreach s,$(aidl_src),\
762    $(eval $(call define-aidl-cpp-rule,$(s),$(aidl_gen_cpp_root),aidl_gen_cpp)))
763$(foreach cpp,$(aidl_gen_cpp), \
764    $(call include-depfile,$(addsuffix .aidl.P,$(basename $(cpp))),$(cpp)))
765$(call track-src-file-gen,$(aidl_src),$(aidl_gen_cpp))
766
767$(aidl_gen_cpp) : PRIVATE_MODULE := $(LOCAL_MODULE)
768$(aidl_gen_cpp) : PRIVATE_HEADER_OUTPUT_DIR := $(aidl_gen_include_root)
769$(aidl_gen_cpp) : PRIVATE_AIDL_FLAGS := $(addprefix -I,$(LOCAL_AIDL_INCLUDES))
770
771# Add generated headers to include paths.
772my_c_includes += $(aidl_gen_include_root)
773my_export_c_include_dirs += $(aidl_gen_include_root)
774# Pick up the generated C++ files later for transformation to .o files.
775my_generated_sources += $(aidl_gen_cpp)
776
777endif  # $(aidl_src) non-empty
778
779###########################################################
780## YACC: Compile .y/.yy files to .c/.cpp and then to .o.
781###########################################################
782
783y_yacc_sources := $(filter %.y,$(my_src_files))
784y_yacc_cs := $(addprefix \
785    $(intermediates)/,$(y_yacc_sources:.y=.c))
786ifneq ($(y_yacc_cs),)
787$(y_yacc_cs): $(intermediates)/%.c: \
788    $(TOPDIR)$(LOCAL_PATH)/%.y \
789    $(my_additional_dependencies)
790	$(call transform-y-to-c-or-cpp)
791$(call track-src-file-gen,$(y_yacc_sources),$(y_yacc_cs))
792
793my_generated_sources += $(y_yacc_cs)
794endif
795
796yy_yacc_sources := $(filter %.yy,$(my_src_files))
797yy_yacc_cpps := $(addprefix \
798    $(intermediates)/,$(yy_yacc_sources:.yy=$(LOCAL_CPP_EXTENSION)))
799ifneq ($(yy_yacc_cpps),)
800$(yy_yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
801    $(TOPDIR)$(LOCAL_PATH)/%.yy \
802    $(my_additional_dependencies)
803	$(call transform-y-to-c-or-cpp)
804$(call track-src-file-gen,$(yy_yacc_sources),$(yy_yacc_cpps))
805
806my_generated_sources += $(yy_yacc_cpps)
807endif
808
809###########################################################
810## LEX: Compile .l/.ll files to .c/.cpp and then to .o.
811###########################################################
812
813l_lex_sources := $(filter %.l,$(my_src_files))
814l_lex_cs := $(addprefix \
815    $(intermediates)/,$(l_lex_sources:.l=.c))
816ifneq ($(l_lex_cs),)
817$(l_lex_cs): $(intermediates)/%.c: \
818    $(TOPDIR)$(LOCAL_PATH)/%.l
819	$(transform-l-to-c-or-cpp)
820$(call track-src-file-gen,$(l_lex_sources),$(l_lex_cs))
821
822my_generated_sources += $(l_lex_cs)
823endif
824
825ll_lex_sources := $(filter %.ll,$(my_src_files))
826ll_lex_cpps := $(addprefix \
827    $(intermediates)/,$(ll_lex_sources:.ll=$(LOCAL_CPP_EXTENSION)))
828ifneq ($(ll_lex_cpps),)
829$(ll_lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
830    $(TOPDIR)$(LOCAL_PATH)/%.ll
831	$(transform-l-to-c-or-cpp)
832$(call track-src-file-gen,$(ll_lex_sources),$(ll_lex_cpps))
833
834my_generated_sources += $(ll_lex_cpps)
835endif
836
837###########################################################
838## C++: Compile .cpp files to .o.
839###########################################################
840
841# we also do this on host modules, even though
842# it's not really arm, because there are files that are shared.
843cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(my_src_files)))
844dotdot_arm_sources := $(filter ../%,$(cpp_arm_sources))
845cpp_arm_sources := $(filter-out ../%,$(cpp_arm_sources))
846cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o))
847$(call track-src-file-obj,$(patsubst %,%.arm,$(cpp_arm_sources)),$(cpp_arm_objects))
848
849# For source files starting with ../, we remove all the ../ in the object file path,
850# to avoid object file escaping the intermediate directory.
851dotdot_arm_objects :=
852$(foreach s,$(dotdot_arm_sources),\
853  $(eval $(call compile-dotdot-cpp-file,$(s),\
854  $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\
855  dotdot_arm_objects)))
856$(call track-src-file-obj,$(patsubst %,%.arm,$(dotdot_arm_sources)),$(dotdot_arm_objects))
857
858dotdot_sources := $(filter ../%$(LOCAL_CPP_EXTENSION),$(my_src_files))
859dotdot_objects :=
860$(foreach s,$(dotdot_sources),\
861  $(eval $(call compile-dotdot-cpp-file,$(s),\
862    $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\
863    dotdot_objects)))
864$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects))
865
866cpp_normal_sources := $(filter-out ../%,$(filter %$(LOCAL_CPP_EXTENSION),$(my_src_files)))
867cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
868$(call track-src-file-obj,$(cpp_normal_sources),$(cpp_normal_objects))
869
870$(dotdot_arm_objects) $(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
871$(dotdot_arm_objects) $(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
872$(dotdot_objects) $(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
873$(dotdot_objects) $(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
874
875cpp_objects        := $(cpp_arm_objects) $(cpp_normal_objects)
876
877ifneq ($(strip $(cpp_objects)),)
878$(cpp_objects): $(intermediates)/%.o: \
879    $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
880    $(yacc_cpps) $(proto_generated_headers) \
881    $(my_additional_dependencies)
882	$(transform-$(PRIVATE_HOST)cpp-to-o)
883-include $(cpp_objects:%.o=%.P)
884endif
885
886cpp_objects += $(dotdot_arm_objects) $(dotdot_objects)
887
888###########################################################
889## C++: Compile generated .cpp files to .o.
890###########################################################
891
892gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(my_generated_sources))
893gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
894$(call track-gen-file-obj,$(gen_cpp_sources),$(gen_cpp_objects))
895
896ifneq ($(strip $(gen_cpp_objects)),)
897# Compile all generated files as thumb.
898# TODO: support compiling certain generated files as arm.
899$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
900$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
901$(gen_cpp_objects): $(intermediates)/%.o: \
902    $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) \
903    $(proto_generated_headers) \
904    $(my_additional_dependencies)
905	$(transform-$(PRIVATE_HOST)cpp-to-o)
906-include $(gen_cpp_objects:%.o=%.P)
907endif
908
909###########################################################
910## S: Compile generated .S and .s files to .o.
911###########################################################
912
913gen_S_sources := $(filter %.S,$(my_generated_sources))
914gen_S_objects := $(gen_S_sources:%.S=%.o)
915$(call track-gen-file-obj,$(gen_S_sources),$(gen_S_objects))
916
917ifneq ($(strip $(gen_S_sources)),)
918$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \
919    $(my_additional_dependencies)
920	$(transform-$(PRIVATE_HOST)s-to-o)
921-include $(gen_S_objects:%.o=%.P)
922endif
923
924gen_s_sources := $(filter %.s,$(my_generated_sources))
925gen_s_objects := $(gen_s_sources:%.s=%.o)
926$(call track-gen-file-obj,$(gen_s_sources),$(gen_s_objects))
927
928ifneq ($(strip $(gen_s_objects)),)
929$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \
930    $(my_additional_dependencies)
931	$(transform-$(PRIVATE_HOST)s-to-o-no-deps)
932-include $(gen_s_objects:%.o=%.P)
933endif
934
935gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
936$(gen_asm_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
937
938###########################################################
939## o: Include generated .o files in output.
940###########################################################
941
942gen_o_objects := $(filter %.o,$(my_generated_sources))
943
944###########################################################
945## C: Compile .c files to .o.
946###########################################################
947
948c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(my_src_files)))
949dotdot_arm_sources := $(filter ../%,$(c_arm_sources))
950c_arm_sources := $(filter-out ../%,$(c_arm_sources))
951c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o))
952$(call track-src-file-obj,$(patsubst %,%.arm,$(c_arm_sources)),$(c_arm_objects))
953
954# For source files starting with ../, we remove all the ../ in the object file path,
955# to avoid object file escaping the intermediate directory.
956dotdot_arm_objects :=
957$(foreach s,$(dotdot_arm_sources),\
958  $(eval $(call compile-dotdot-c-file,$(s),\
959    $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\
960    dotdot_arm_objects)))
961$(call track-src-file-obj,$(patsubst %,%.arm,$(dotdot_arm_sources)),$(dotdot_arm_objects))
962
963dotdot_sources := $(filter ../%.c, $(my_src_files))
964dotdot_objects :=
965$(foreach s, $(dotdot_sources),\
966  $(eval $(call compile-dotdot-c-file,$(s),\
967    $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\
968    dotdot_objects)))
969$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects))
970
971c_normal_sources := $(filter-out ../%,$(filter %.c,$(my_src_files)))
972c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
973$(call track-src-file-obj,$(c_normal_sources),$(c_normal_objects))
974
975$(dotdot_arm_objects) $(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
976$(dotdot_arm_objects) $(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
977$(dotdot_objects) $(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
978$(dotdot_objects) $(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
979
980c_objects        := $(c_arm_objects) $(c_normal_objects)
981
982ifneq ($(strip $(c_objects)),)
983$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \
984    $(my_additional_dependencies)
985	$(transform-$(PRIVATE_HOST)c-to-o)
986-include $(c_objects:%.o=%.P)
987endif
988
989c_objects += $(dotdot_arm_objects) $(dotdot_objects)
990
991###########################################################
992## C: Compile generated .c files to .o.
993###########################################################
994
995gen_c_sources := $(filter %.c,$(my_generated_sources))
996gen_c_objects := $(gen_c_sources:%.c=%.o)
997$(call track-gen-file-obj,$(gen_c_sources),$(gen_c_objects))
998
999ifneq ($(strip $(gen_c_objects)),)
1000# Compile all generated files as thumb.
1001# TODO: support compiling certain generated files as arm.
1002$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
1003$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
1004$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \
1005    $(my_additional_dependencies)
1006	$(transform-$(PRIVATE_HOST)c-to-o)
1007-include $(gen_c_objects:%.o=%.P)
1008endif
1009
1010###########################################################
1011## ObjC: Compile .m files to .o
1012###########################################################
1013
1014objc_sources := $(filter %.m,$(my_src_files))
1015objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
1016
1017ifneq ($(strip $(objc_objects)),)
1018$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) \
1019    $(my_additional_dependencies)
1020	$(transform-$(PRIVATE_HOST)m-to-o)
1021-include $(objc_objects:%.o=%.P)
1022endif
1023
1024###########################################################
1025## ObjC++: Compile .mm files to .o
1026###########################################################
1027
1028objcpp_sources := $(filter %.mm,$(my_src_files))
1029objcpp_objects := $(addprefix $(intermediates)/,$(objcpp_sources:.mm=.o))
1030
1031ifneq ($(strip $(objcpp_objects)),)
1032$(objcpp_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.mm $(yacc_cpps) $(proto_generated_headers) \
1033    $(my_additional_dependencies)
1034	$(transform-$(PRIVATE_HOST)mm-to-o)
1035-include $(objcpp_objects:%.o=%.P)
1036endif
1037
1038###########################################################
1039## AS: Compile .S files to .o.
1040###########################################################
1041
1042asm_sources_S := $(filter %.S,$(my_src_files))
1043dotdot_sources := $(filter ../%,$(asm_sources_S))
1044asm_sources_S := $(filter-out ../%,$(asm_sources_S))
1045asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
1046$(call track-src-file-obj,$(asm_sources_S),$(asm_objects_S))
1047
1048dotdot_objects_S :=
1049$(foreach s,$(dotdot_sources),\
1050  $(eval $(call compile-dotdot-s-file,$(s),\
1051    $(my_additional_dependencies),\
1052    dotdot_objects_S)))
1053$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects_S))
1054
1055ifneq ($(strip $(asm_objects_S)),)
1056$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \
1057    $(my_additional_dependencies)
1058	$(transform-$(PRIVATE_HOST)s-to-o)
1059-include $(asm_objects_S:%.o=%.P)
1060endif
1061
1062asm_sources_s := $(filter %.s,$(my_src_files))
1063dotdot_sources := $(filter ../%,$(asm_sources_s))
1064asm_sources_s := $(filter-out ../%,$(asm_sources_s))
1065asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
1066$(call track-src-file-obj,$(asm_sources_s),$(asm_objects_s))
1067
1068dotdot_objects_s :=
1069$(foreach s,$(dotdot_sources),\
1070  $(eval $(call compile-dotdot-s-file-no-deps,$(s),\
1071    $(my_additional_dependencies),\
1072    dotdot_objects_s)))
1073$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects_s))
1074
1075ifneq ($(strip $(asm_objects_s)),)
1076$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \
1077    $(my_additional_dependencies)
1078	$(transform-$(PRIVATE_HOST)s-to-o-no-deps)
1079endif
1080
1081asm_objects := $(dotdot_objects_S) $(dotdot_objects_s) $(asm_objects_S) $(asm_objects_s)
1082$(asm_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
1083
1084
1085# .asm for x86/x86_64 needs to be compiled with yasm.
1086asm_sources_asm := $(filter %.asm,$(my_src_files))
1087ifneq ($(strip $(asm_sources_asm)),)
1088asm_objects_asm := $(addprefix $(intermediates)/,$(asm_sources_asm:.asm=.o))
1089$(asm_objects_asm): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.asm \
1090    $(my_additional_dependencies)
1091	$(transform-asm-to-o)
1092$(call track-src-file-obj,$(asm_sources_asm),$(asm_objects_asm))
1093
1094asm_objects += $(asm_objects_asm)
1095endif
1096
1097
1098##########################################################
1099## Set up installed module dependency
1100## We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for
1101## they may cusomize their install path with LOCAL_MODULE_PATH
1102##########################################################
1103# Get the list of INSTALLED libraries as module names.
1104ifdef LOCAL_SDK_VERSION
1105  installed_shared_library_module_names := \
1106      $(my_shared_libraries)
1107else
1108  installed_shared_library_module_names := \
1109      $(my_shared_libraries) $(my_system_shared_libraries)
1110endif
1111
1112# The real dependency will be added after all Android.mks are loaded and the install paths
1113# of the shared libraries are determined.
1114ifdef LOCAL_INSTALLED_MODULE
1115ifdef installed_shared_library_module_names
1116$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
1117    $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(sort $(installed_shared_library_module_names)))
1118endif
1119endif
1120
1121
1122####################################################
1123## Import includes
1124####################################################
1125import_includes := $(intermediates)/import_includes
1126import_includes_deps := $(strip \
1127    $(foreach l, $(installed_shared_library_module_names), \
1128      $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes) \
1129    $(foreach l, $(my_static_libraries) $(my_whole_static_libraries), \
1130      $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
1131$(import_includes): PRIVATE_IMPORT_EXPORT_INCLUDES := $(import_includes_deps)
1132$(import_includes) : $(LOCAL_MODULE_MAKEFILE_DEP) $(import_includes_deps)
1133	@echo Import includes file: $@
1134	$(hide) mkdir -p $(dir $@) && rm -f $@
1135ifdef import_includes_deps
1136	$(hide) for f in $(PRIVATE_IMPORT_EXPORT_INCLUDES); do \
1137	  cat $$f >> $@; \
1138	done
1139else
1140	$(hide) touch $@
1141endif
1142
1143###########################################################
1144## Common object handling.
1145###########################################################
1146
1147my_unused_src_files := $(filter-out $(logtags_sources) $(my_tracked_src_files),$(my_src_files) $(my_gen_src_files))
1148ifneq ($(my_unused_src_files),)
1149  $(warning $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Unused source files: $(my_unused_src_files))
1150endif
1151
1152# some rules depend on asm_objects being first.  If your code depends on
1153# being first, it's reasonable to require it to be assembly
1154normal_objects := \
1155    $(asm_objects) \
1156    $(cpp_objects) \
1157    $(gen_cpp_objects) \
1158    $(gen_asm_objects) \
1159    $(c_objects) \
1160    $(gen_c_objects) \
1161    $(objc_objects) \
1162    $(objcpp_objects) \
1163    $(proto_generated_objects)
1164
1165new_order_normal_objects := $(foreach f,$(my_src_files),$(my_src_file_obj_$(f)))
1166new_order_normal_objects += $(foreach f,$(my_gen_src_files),$(my_src_file_obj_$(f)))
1167
1168ifneq ($(sort $(normal_objects)),$(sort $(new_order_normal_objects)))
1169$(warning $(LOCAL_MODULE_MAKEFILE) Internal build system warning: New object list does not match old)
1170$(info Only in old: $(filter-out $(new_order_normal_objects),$(sort $(normal_objects))))
1171$(info Only in new: $(filter-out $(normal_objects),$(sort $(new_order_normal_objects))))
1172endif
1173
1174ifeq ($(BINARY_OBJECTS_ORDER),soong)
1175normal_objects := $(new_order_normal_objects)
1176endif
1177
1178normal_objects += $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
1179
1180all_objects := $(normal_objects) $(gen_o_objects)
1181
1182# Cleanup file tracking
1183$(foreach f,$(my_tracked_gen_files),$(eval my_src_file_gen_$(s):=))
1184my_tracked_gen_files :=
1185$(foreach f,$(my_tracked_src_files),$(eval my_src_file_obj_$(s):=))
1186my_tracked_src_files :=
1187
1188my_c_includes += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(generated_sources_dir)
1189
1190ifndef LOCAL_SDK_VERSION
1191  my_c_includes += $(JNI_H_INCLUDE)
1192endif
1193
1194# all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES;
1195# use normal_objects here to avoid creating circular dependencies. This assumes
1196# that custom build rules which generate .o files don't consume other generated
1197# sources as input (or if they do they take care of that dependency themselves).
1198$(normal_objects) : | $(my_generated_sources)
1199ifeq ($(BUILDING_WITH_NINJA),true)
1200$(all_objects) : $(import_includes)
1201else
1202$(all_objects) : | $(import_includes)
1203endif
1204ALL_C_CPP_ETC_OBJECTS += $(all_objects)
1205
1206
1207###########################################################
1208# Standard library handling.
1209###########################################################
1210
1211###########################################################
1212# The list of libraries that this module will link against are in
1213# these variables.  Each is a list of bare module names like "libc libm".
1214#
1215# LOCAL_SHARED_LIBRARIES
1216# LOCAL_STATIC_LIBRARIES
1217# LOCAL_WHOLE_STATIC_LIBRARIES
1218#
1219# We need to convert the bare names into the dependencies that
1220# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
1221# LOCAL_BUILT_MODULE should depend on the BUILT versions of the
1222# libraries, so that simply building this module doesn't force
1223# an install of a library.  Similarly, LOCAL_INSTALLED_MODULE
1224# should depend on the INSTALLED versions of the libraries so
1225# that they get installed when this module does.
1226###########################################################
1227# NOTE:
1228# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
1229# module without leaving anything out, which is useful for turning
1230# a collection of .a files into a .so file.  Linking against a
1231# normal STATIC_LIBRARY will only pull in code/symbols that are
1232# referenced by the module. (see gcc/ld's --whole-archive option)
1233###########################################################
1234
1235# Get the list of BUILT libraries, which are under
1236# various intermediates directories.
1237so_suffix := $($(my_prefix)SHLIB_SUFFIX)
1238a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
1239
1240ifdef LOCAL_SDK_VERSION
1241built_shared_libraries := \
1242    $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
1243      $(addsuffix $(so_suffix), \
1244        $(my_shared_libraries)))
1245built_shared_library_deps := $(addsuffix .toc, $(built_shared_libraries))
1246
1247# Add the NDK libraries to the built module dependency
1248my_system_shared_libraries_fullpath := \
1249    $(my_ndk_stl_shared_lib_fullpath) \
1250    $(addprefix $(my_ndk_sysroot_lib)/, \
1251        $(addsuffix $(so_suffix), $(my_system_shared_libraries)))
1252
1253built_shared_libraries += $(my_system_shared_libraries_fullpath)
1254else
1255built_shared_libraries := \
1256    $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
1257      $(addsuffix $(so_suffix), \
1258        $(installed_shared_library_module_names)))
1259ifdef LOCAL_IS_HOST_MODULE
1260# Disable .toc optimization for host modules: we may run the host binaries during the build process
1261# and the libraries' implementation matters.
1262built_shared_library_deps := $(built_shared_libraries)
1263else
1264built_shared_library_deps := $(addsuffix .toc, $(built_shared_libraries))
1265endif
1266my_system_shared_libraries_fullpath :=
1267endif
1268
1269built_static_libraries := \
1270    $(foreach lib,$(my_static_libraries), \
1271      $(call intermediates-dir-for, \
1272        STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(a_suffix))
1273
1274ifdef LOCAL_SDK_VERSION
1275built_static_libraries += $(my_ndk_stl_static_lib)
1276endif
1277
1278built_whole_libraries := \
1279    $(foreach lib,$(my_whole_static_libraries), \
1280      $(call intermediates-dir-for, \
1281        STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(a_suffix))
1282
1283# We don't care about installed static libraries, since the
1284# libraries have already been linked into the module at that point.
1285# We do, however, care about the NOTICE files for any static
1286# libraries that we use. (see notice_files.mk)
1287
1288installed_static_library_notice_file_targets := \
1289    $(foreach lib,$(my_static_libraries) $(my_whole_static_libraries), \
1290      NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib))
1291
1292# Default is -fno-rtti.
1293ifeq ($(strip $(LOCAL_RTTI_FLAG)),)
1294LOCAL_RTTI_FLAG := -fno-rtti
1295endif
1296
1297###########################################################
1298# Rule-specific variable definitions
1299###########################################################
1300
1301ifeq ($(my_clang),true)
1302my_cflags += $(LOCAL_CLANG_CFLAGS)
1303my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS)
1304my_cppflags += $(LOCAL_CLANG_CPPFLAGS)
1305my_cflags_no_override += $(GLOBAL_CLANG_CFLAGS_NO_OVERRIDE)
1306my_cppflags_no_override += $(GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE)
1307my_asflags += $(LOCAL_CLANG_ASFLAGS)
1308my_ldflags += $(LOCAL_CLANG_LDFLAGS)
1309my_cflags += $(LOCAL_CLANG_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CFLAGS_$(my_32_64_bit_suffix))
1310my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CONLYFLAGS_$(my_32_64_bit_suffix))
1311my_cppflags += $(LOCAL_CLANG_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CPPFLAGS_$(my_32_64_bit_suffix))
1312my_ldflags += $(LOCAL_CLANG_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_LDFLAGS_$(my_32_64_bit_suffix))
1313my_asflags += $(LOCAL_CLANG_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_ASFLAGS_$(my_32_64_bit_suffix))
1314my_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_cflags))
1315my_cppflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_cppflags))
1316my_asflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_asflags))
1317my_ldflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_ldflags))
1318endif
1319
1320ifeq ($(my_fdo_build), true)
1321  my_cflags := $(patsubst -Os,-O2,$(my_cflags))
1322  fdo_incompatible_flags := -fno-early-inlining -finline-limit=%
1323  my_cflags := $(filter-out $(fdo_incompatible_flags),$(my_cflags))
1324endif
1325
1326# No one should ever use this flag. On GCC it's mere presence will disable all
1327# warnings, even those that are specified after it (contrary to typical warning
1328# flag behavior). This circumvents CFLAGS_NO_OVERRIDE from forcibly enabling the
1329# warnings that are *always* bugs.
1330my_illegal_flags := -w
1331my_cflags := $(filter-out $(my_illegal_flags),$(my_cflags))
1332my_cppflags := $(filter-out $(my_illegal_flags),$(my_cppflags))
1333my_conlyflags := $(filter-out $(my_illegal_flags),$(my_conlyflags))
1334
1335$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
1336$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(my_asflags)
1337$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(my_conlyflags)
1338$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(my_cflags)
1339$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(my_cppflags)
1340$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS_NO_OVERRIDE := $(my_cflags_no_override)
1341$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS_NO_OVERRIDE := $(my_cppflags_no_override)
1342$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
1343$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
1344$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(my_c_includes)
1345$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes)
1346$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(my_ldflags)
1347$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(my_ldlibs)
1348
1349# this is really the way to get the files onto the command line instead
1350# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
1351$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
1352$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
1353$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
1354$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects)
1355
1356###########################################################
1357# Define library dependencies.
1358###########################################################
1359# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
1360all_libraries := \
1361    $(built_shared_library_deps) \
1362    $(my_system_shared_libraries_fullpath) \
1363    $(built_static_libraries) \
1364    $(built_whole_libraries)
1365
1366# Also depend on the notice files for any static libraries that
1367# are linked into this module.  This will force them to be installed
1368# when this module is.
1369$(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets)
1370
1371###########################################################
1372# Export includes
1373###########################################################
1374export_includes := $(intermediates)/export_includes
1375$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(my_export_c_include_dirs)
1376# Make sure .pb.h are already generated before any dependent source files get compiled.
1377# Similarly, the generated DBus headers need to exist before we export their location.
1378# People are not going to consume the aidl generated cpp file, but the cpp file is
1379# generated after the headers, so this is a convenient way to ensure the headers exist.
1380$(export_includes) : $(LOCAL_MODULE_MAKEFILE_DEP) $(proto_generated_headers) $(dbus_generated_headers) $(aidl_gen_cpp)
1381	@echo Export includes file: $< -- $@
1382	$(hide) mkdir -p $(dir $@) && rm -f $@.tmp
1383ifdef my_export_c_include_dirs
1384	$(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \
1385	        echo "-I $$d" >> $@.tmp; \
1386	        done
1387else
1388	$(hide) touch $@.tmp
1389endif
1390ifeq ($(BUILDING_WITH_NINJA),true)
1391	$(hide) if cmp -s $@.tmp $@ ; then \
1392	  rm $@.tmp ; \
1393	else \
1394	  mv $@.tmp $@ ; \
1395	fi
1396else
1397	mv $@.tmp $@ ;
1398endif
1399
1400# Kati adds restat=1 to ninja. GNU make does nothing for this.
1401.KATI_RESTAT: $(export_includes)
1402
1403# Make sure export_includes gets generated when you are running mm/mmm
1404$(LOCAL_BUILT_MODULE) : | $(export_includes)
1405