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