OSDN Git Service

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