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