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