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