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