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