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