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