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