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