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