binary.mk revision 7fff9a1a560b822be79f47566f43b76111d7aecf
1###########################################################
2## Standard rules for building binary object files from
3## asm/c/cpp/yacc/lex source files.
4##
5## The list of object files is exported in $(all_objects).
6###########################################################
7
8my_ndk_version_root :=
9ifdef LOCAL_SDK_VERSION
10  ifdef LOCAL_NDK_VERSION
11    $(error $(LOCAL_PATH): LOCAL_NDK_VERSION is now retired.)
12  endif
13  ifdef LOCAL_IS_HOST_MODULE
14    $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
15  endif
16  my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources
17  my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_ARCH)
18
19  # Set up the NDK stl variant. Starting from NDK-r5 the c++ stl resides in a separate location.
20  # See ndk/docs/CPLUSPLUS-SUPPORT.html
21  my_ndk_stl_include_path :=
22  my_ndk_stl_shared_lib_fullpath :=
23  my_ndk_stl_shared_lib :=
24  my_ndk_stl_static_lib :=
25  ifeq (,$(LOCAL_NDK_STL_VARIANT))
26    LOCAL_NDK_STL_VARIANT := system
27  endif
28  ifneq (1,$(words $(filter system stlport_static stlport_shared gnustl_static, $(LOCAL_NDK_STL_VARIANT))))
29    $(error $(LOCAL_PATH): Unknown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT))
30  endif
31  ifeq (system,$(LOCAL_NDK_STL_VARIANT))
32    my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/system/include
33    # for "system" variant, the shared library exists in the system library and -lstdc++ is added by default.
34  else # LOCAL_NDK_STL_VARIANT is not system
35  ifneq (,$(filter stlport_%, $(LOCAL_NDK_STL_VARIANT)))
36    my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/stlport/stlport
37    ifeq (stlport_static,$(LOCAL_NDK_STL_VARIANT))
38      my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(TARGET_CPU_ABI)/libstlport_static.a
39    else
40      my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(TARGET_CPU_ABI)/libstlport_shared.so
41      my_ndk_stl_shared_lib := -lstlport_shared
42    endif
43  else
44    # LOCAL_NDK_STL_VARIANT is gnustl_static
45    my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_CPU_ABI)/include \
46                               $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/include
47    my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_CPU_ABI)/libgnustl_static.a
48  endif
49  endif
50endif
51
52##################################################
53# Compute the dependency of the shared libraries
54##################################################
55# On the target, we compile with -nostdlib, so we must add in the
56# default system shared libraries, unless they have requested not
57# to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value.  One would
58# supply that, for example, when building libc itself.
59ifdef LOCAL_IS_HOST_MODULE
60  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
61      LOCAL_SYSTEM_SHARED_LIBRARIES :=
62  endif
63else
64  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
65      LOCAL_SYSTEM_SHARED_LIBRARIES := $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES)
66  endif
67endif
68
69ifdef LOCAL_SDK_VERSION
70  # Get the list of INSTALLED libraries as module names.
71  # We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for
72  # they may cusomize their install path with LOCAL_MODULE_PATH
73  installed_shared_library_module_names := \
74      $(LOCAL_SHARED_LIBRARIES)
75else
76  installed_shared_library_module_names := \
77      $(LOCAL_SYSTEM_SHARED_LIBRARIES) $(LOCAL_SHARED_LIBRARIES)
78endif
79installed_shared_library_module_names := $(sort $(installed_shared_library_module_names))
80
81#######################################
82include $(BUILD_SYSTEM)/base_rules.mk
83#######################################
84
85# The real dependency will be added after all Android.mks are loaded and the install paths
86# of the shared libraries are determined.
87ifdef LOCAL_INSTALLED_MODULE
88ifdef installed_shared_library_module_names
89$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += $(LOCAL_MODULE):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(installed_shared_library_module_names))
90endif
91endif
92
93# Add static HAL libraries
94ifdef LOCAL_HAL_STATIC_LIBRARIES
95$(foreach lib, $(LOCAL_HAL_STATIC_LIBRARIES), \
96    $(eval b_lib := $(filter $(lib).%,$(BOARD_HAL_STATIC_LIBRARIES)))\
97    $(if $(b_lib), $(eval LOCAL_STATIC_LIBRARIES += $(b_lib)),\
98                   $(eval LOCAL_STATIC_LIBRARIES += $(lib).default)))
99b_lib :=
100endif
101
102ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),true)
103  LOCAL_CLANG := true
104  LOCAL_CFLAGS += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS)
105  LOCAL_LDFLAGS += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS)
106  LOCAL_SHARED_LIBRARIES += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES)
107  LOCAL_STATIC_LIBRARIES += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES)
108endif
109
110ifeq ($(strip $(WITHOUT_CLANG)),true)
111  LOCAL_CLANG :=
112endif
113
114# Add in libcompiler_rt for all regular device builds
115ifeq (,$(LOCAL_SDK_VERSION)$(LOCAL_IS_HOST_MODULE)$(WITHOUT_LIBCOMPILER_RT))
116  LOCAL_STATIC_LIBRARIES += $(COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES)
117endif
118
119my_compiler_dependencies :=
120ifeq ($(strip $(LOCAL_CLANG)),true)
121  my_compiler_dependencies := $(CLANG) $(CLANG_CXX)
122endif
123
124####################################################
125## Add FDO flags if FDO is turned on and supported
126####################################################
127ifneq ($(strip $(LOCAL_FDO_SUPPORT)),)
128  ifeq ($(strip $(LOCAL_IS_HOST_MODULE)),)
129    LOCAL_CFLAGS += $(TARGET_FDO_CFLAGS)
130    LOCAL_CPPFLAGS += $(TARGET_FDO_CFLAGS)
131    LOCAL_LDFLAGS += $(TARGET_FDO_CFLAGS)
132  endif
133endif
134
135####################################################
136## Add profiling flags if aprof is turned on
137####################################################
138ifeq ($(strip $(LOCAL_ENABLE_APROF)),true)
139  # -ffunction-sections and -fomit-frame-pointer are conflict with -pg
140  LOCAL_CFLAGS += -fno-omit-frame-pointer -fno-function-sections -pg
141  LOCAL_CPPFLAGS += -fno-omit-frame-pointer -fno-function-sections -pg
142endif
143
144###########################################################
145## Explicitly declare assembly-only __ASSEMBLY__ macro for
146## assembly source
147###########################################################
148LOCAL_ASFLAGS += -D__ASSEMBLY__
149
150###########################################################
151## Define PRIVATE_ variables from global vars
152###########################################################
153ifndef LOCAL_IS_HOST_MODULE
154ifdef LOCAL_SDK_VERSION
155my_target_project_includes :=
156my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_version_root)/usr/include
157else
158my_target_project_includes := $(TARGET_PROJECT_INCLUDES)
159my_target_c_includes := $(TARGET_C_INCLUDES)
160endif # LOCAL_SDK_VERSION
161
162ifeq ($(LOCAL_CLANG),true)
163my_target_global_cflags := $(CLANG_TARGET_GLOBAL_CFLAGS)
164my_target_global_cppflags := $(CLANG_TARGET_GLOBAL_CPPFLAGS)
165my_target_global_ldflags := $(CLANG_TARGET_GLOBAL_LDFLAGS)
166my_target_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES)
167else
168my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS)
169my_target_global_cppflags := $(TARGET_GLOBAL_CPPFLAGS)
170my_target_global_ldflags := $(TARGET_GLOBAL_LDFLAGS)
171endif # LOCAL_CLANG
172
173$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes)
174$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes)
175$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
176$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags)
177$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
178
179else # LOCAL_IS_HOST_MODULE
180
181ifeq ($(LOCAL_CLANG),true)
182my_host_global_cflags := $(CLANG_HOST_GLOBAL_CFLAGS)
183my_host_global_cppflags := $(CLANG_HOST_GLOBAL_CPPFLAGS)
184my_host_global_ldflags := $(CLANG_HOST_GLOBAL_LDFLAGS)
185my_host_c_includes := $(HOST_C_INCLUDES) $(CLANG_CONFIG_EXTRA_HOST_C_INCLUDES)
186else
187my_host_global_cflags := $(HOST_GLOBAL_CFLAGS)
188my_host_global_cppflags := $(HOST_GLOBAL_CPPFLAGS)
189my_host_global_ldflags := $(HOST_GLOBAL_LDFLAGS)
190my_host_c_includes := $(HOST_C_INCLUDES)
191endif # LOCAL_CLANG
192
193$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_C_INCLUDES := $(my_host_c_includes)
194$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CFLAGS := $(my_host_global_cflags)
195$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CPPFLAGS := $(my_host_global_cppflags)
196$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_LDFLAGS := $(my_host_global_ldflags)
197endif # LOCAL_IS_HOST_MODULE
198
199###########################################################
200## Define PRIVATE_ variables used by multiple module types
201###########################################################
202$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
203    $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
204
205ifeq ($(strip $(WITH_SYNTAX_CHECK)),)
206  LOCAL_NO_SYNTAX_CHECK := true
207endif
208
209ifeq ($(strip $(WITH_STATIC_ANALYZER)),)
210  LOCAL_NO_STATIC_ANALYZER := true
211endif
212
213ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
214  my_syntax_arch := host
215else
216  my_syntax_arch := $(TARGET_ARCH)
217endif
218
219ifeq ($(strip $(LOCAL_CC)),)
220  ifeq ($(strip $(LOCAL_CLANG)),true)
221    LOCAL_CC := $(CLANG)
222  else
223    LOCAL_CC := $($(my_prefix)CC)
224  endif
225endif
226ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
227  LOCAL_CC := $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer $(my_syntax_arch) "$(LOCAL_CC)"
228else
229ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
230  LOCAL_CC := $(SYNTAX_TOOLS_PREFIX)/ccc-syntax $(my_syntax_arch) "$(LOCAL_CC)"
231endif
232endif
233$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(LOCAL_CC)
234
235ifeq ($(strip $(LOCAL_CXX)),)
236  ifeq ($(strip $(LOCAL_CLANG)),true)
237    LOCAL_CXX := $(CLANG_CXX)
238  else
239    LOCAL_CXX := $($(my_prefix)CXX)
240  endif
241endif
242ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
243  LOCAL_CXX := $(SYNTAX_TOOLS_PREFIX)/cxx-analyzer $(my_syntax_arch) "$(LOCAL_CXX)"
244else
245ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
246  LOCAL_CXX := $(SYNTAX_TOOLS_PREFIX)/cxx-syntax $(my_syntax_arch) "$(LOCAL_CXX)"
247endif
248endif
249$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(LOCAL_CXX)
250
251# TODO: support a mix of standard extensions so that this isn't necessary
252LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
253ifeq ($(LOCAL_CPP_EXTENSION),)
254  LOCAL_CPP_EXTENSION := .cpp
255endif
256$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION)
257
258# Certain modules like libdl have to have symbols resolved at runtime and blow
259# up if --no-undefined is passed to the linker.
260ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
261ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),)
262  LOCAL_LDFLAGS := $(LOCAL_LDFLAGS) $($(my_prefix)NO_UNDEFINED_LDFLAGS)
263endif
264endif
265
266ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES))
267$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true
268else
269$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES :=
270endif
271
272###########################################################
273## Define arm-vs-thumb-mode flags.
274###########################################################
275LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
276ifeq ($(TARGET_ARCH),arm)
277arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
278normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
279
280# Read the values from something like TARGET_arm_CFLAGS or
281# TARGET_thumb_CFLAGS.  HOST_(arm|thumb)_CFLAGS values aren't
282# actually used (although they are usually empty).
283arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CFLAGS)
284normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_CFLAGS)
285ifeq ($(strip $(LOCAL_CLANG)),true)
286arm_objects_cflags := $(call convert-to-$(my_host)clang-flags,$(arm_objects_cflags))
287normal_objects_cflags := $(call convert-to-$(my_host)clang-flags,$(normal_objects_cflags))
288endif
289
290else
291arm_objects_mode :=
292normal_objects_mode :=
293arm_objects_cflags :=
294normal_objects_cflags :=
295endif
296
297###########################################################
298## Define per-module debugging flags.  Users can turn on
299## debugging for a particular module by setting DEBUG_MODULE_ModuleName
300## to a non-empty value in their environment or buildspec.mk,
301## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
302## debug flags that they want to use.
303###########################################################
304ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
305  debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
306else
307  debug_cflags :=
308endif
309
310####################################################
311## Compile RenderScript with reflected C++
312####################################################
313
314renderscript_sources := $(filter %.rs %.fs,$(LOCAL_SRC_FILES))
315
316ifneq (,$(renderscript_sources))
317
318renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
319RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp
320renderscript_intermediate := $(intermediates)/renderscript
321
322ifeq ($(LOCAL_RENDERSCRIPT_CC),)
323LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
324endif
325
326# Turn on all warnings and warnings as errors for RS compiles.
327# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
328renderscript_flags := -Wall -Werror
329renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
330
331LOCAL_RENDERSCRIPT_INCLUDES := \
332    $(TOPDIR)external/clang/lib/Headers \
333    $(TOPDIR)frameworks/rs/scriptc \
334    $(LOCAL_RENDERSCRIPT_INCLUDES)
335
336ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
337LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
338endif
339
340$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES)
341$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
342$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
343$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
344$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate)
345$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
346	$(transform-renderscripts-to-cpp-and-bc)
347
348# include the dependency files (.d) generated by llvm-rs-cc.
349renderscript_generated_dep_files := $(addprefix $(renderscript_intermediate)/, \
350    $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources)))))
351-include $(renderscript_generated_dep_files)
352
353LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
354
355rs_generated_cpps := $(addprefix \
356    $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rs,%.cpp, \
357    $(notdir $(renderscript_sources)))))
358
359$(rs_generated_cpps) : $(RenderScript_file_stamp)
360
361LOCAL_C_INCLUDES += $(renderscript_intermediate)
362LOCAL_GENERATED_SOURCES += $(rs_generated_cpps)
363
364endif
365
366
367###########################################################
368## Stuff source generated from one-off tools
369###########################################################
370$(LOCAL_GENERATED_SOURCES): PRIVATE_MODULE := $(LOCAL_MODULE)
371
372ALL_GENERATED_SOURCES += $(LOCAL_GENERATED_SOURCES)
373
374
375###########################################################
376## Compile the .proto files to .cc and then to .o
377###########################################################
378proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
379proto_generated_objects :=
380proto_generated_headers :=
381ifneq ($(proto_sources),)
382proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
383proto_generated_cc_sources_dir := $(intermediates)/proto
384proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \
385    $(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath)))
386proto_generated_objects := $(patsubst %.cc,%.o, $(proto_generated_cc_sources))
387
388$(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
389$(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir)
390$(proto_generated_cc_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
391$(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC)
392	$(transform-proto-to-cc)
393
394proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources))
395$(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc
396
397$(proto_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
398$(proto_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
399$(proto_generated_objects): $(proto_generated_cc_sources_dir)/%.o: $(proto_generated_cc_sources_dir)/%.cc $(proto_generated_headers)
400	$(transform-$(PRIVATE_HOST)cpp-to-o)
401-include $(proto_generated_objects:%.o=%.P)
402
403LOCAL_C_INCLUDES += external/protobuf/src $(proto_generated_cc_sources_dir)
404LOCAL_CFLAGS += -DGOOGLE_PROTOBUF_NO_RTTI
405ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
406LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-full
407else
408LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-lite
409endif
410endif
411
412
413###########################################################
414## YACC: Compile .y files to .cpp and the to .o.
415###########################################################
416
417yacc_sources := $(filter %.y,$(LOCAL_SRC_FILES))
418yacc_cpps := $(addprefix \
419    $(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION)))
420yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h)
421yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o)
422
423ifneq ($(strip $(yacc_cpps)),)
424$(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
425    $(TOPDIR)$(LOCAL_PATH)/%.y \
426    $(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
427	$(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
428$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
429
430$(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
431$(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
432$(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
433	$(transform-$(PRIVATE_HOST)cpp-to-o)
434endif
435
436###########################################################
437## LEX: Compile .l files to .cpp and then to .o.
438###########################################################
439
440lex_sources := $(filter %.l,$(LOCAL_SRC_FILES))
441lex_cpps := $(addprefix \
442    $(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION)))
443lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o)
444
445ifneq ($(strip $(lex_cpps)),)
446$(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
447    $(TOPDIR)$(LOCAL_PATH)/%.l
448	$(transform-l-to-cpp)
449
450$(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
451$(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
452$(lex_objects): $(intermediates)/%.o: \
453    $(intermediates)/%$(LOCAL_CPP_EXTENSION) \
454    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
455    $(yacc_headers)
456	$(transform-$(PRIVATE_HOST)cpp-to-o)
457endif
458
459###########################################################
460## C++: Compile .cpp files to .o.
461###########################################################
462
463# we also do this on host modules, even though
464# it's not really arm, because there are files that are shared.
465cpp_arm_sources    := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(LOCAL_SRC_FILES)))
466cpp_arm_objects    := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o))
467
468cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES))
469cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
470
471$(cpp_arm_objects):    PRIVATE_ARM_MODE := $(arm_objects_mode)
472$(cpp_arm_objects):    PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
473$(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
474$(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
475
476cpp_objects        := $(cpp_arm_objects) $(cpp_normal_objects)
477
478ifneq ($(strip $(cpp_objects)),)
479$(cpp_objects): $(intermediates)/%.o: \
480    $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
481    $(yacc_cpps) $(proto_generated_headers) \
482    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
483    | $(my_compiler_dependencies)
484	$(transform-$(PRIVATE_HOST)cpp-to-o)
485-include $(cpp_objects:%.o=%.P)
486endif
487
488###########################################################
489## C++: Compile generated .cpp files to .o.
490###########################################################
491
492gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_GENERATED_SOURCES))
493gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
494
495ifneq ($(strip $(gen_cpp_objects)),)
496# Compile all generated files as thumb.
497# TODO: support compiling certain generated files as arm.
498$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
499$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
500$(gen_cpp_objects): $(intermediates)/%.o: \
501    $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) \
502    $(proto_generated_headers) \
503    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
504    | $(my_compiler_dependencies)
505	$(transform-$(PRIVATE_HOST)cpp-to-o)
506-include $(gen_cpp_objects:%.o=%.P)
507endif
508
509###########################################################
510## S: Compile generated .S and .s files to .o.
511###########################################################
512
513gen_S_sources := $(filter %.S,$(LOCAL_GENERATED_SOURCES))
514gen_S_objects := $(gen_S_sources:%.S=%.o)
515
516ifneq ($(strip $(gen_S_sources)),)
517$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \
518    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
519    | $(my_compiler_dependencies)
520	$(transform-$(PRIVATE_HOST)s-to-o)
521-include $(gen_S_objects:%.o=%.P)
522endif
523
524gen_s_sources := $(filter %.s,$(LOCAL_GENERATED_SOURCES))
525gen_s_objects := $(gen_s_sources:%.s=%.o)
526
527ifneq ($(strip $(gen_s_objects)),)
528$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \
529    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
530    | $(my_compiler_dependencies)
531	$(transform-$(PRIVATE_HOST)s-to-o-no-deps)
532-include $(gen_s_objects:%.o=%.P)
533endif
534
535gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
536
537###########################################################
538## o: Include generated .o files in output.
539###########################################################
540
541gen_o_objects := $(filter %.o,$(LOCAL_GENERATED_SOURCES))
542
543###########################################################
544## C: Compile .c files to .o.
545###########################################################
546
547c_arm_sources    := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(LOCAL_SRC_FILES)))
548c_arm_objects    := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o))
549
550c_normal_sources := $(filter %.c,$(LOCAL_SRC_FILES))
551c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
552
553$(c_arm_objects):    PRIVATE_ARM_MODE := $(arm_objects_mode)
554$(c_arm_objects):    PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
555$(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
556$(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
557
558c_objects        := $(c_arm_objects) $(c_normal_objects)
559
560ifneq ($(strip $(c_objects)),)
561$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \
562    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
563    | $(my_compiler_dependencies)
564	$(transform-$(PRIVATE_HOST)c-to-o)
565-include $(c_objects:%.o=%.P)
566endif
567
568###########################################################
569## C: Compile generated .c files to .o.
570###########################################################
571
572gen_c_sources := $(filter %.c,$(LOCAL_GENERATED_SOURCES))
573gen_c_objects := $(gen_c_sources:%.c=%.o)
574
575ifneq ($(strip $(gen_c_objects)),)
576# Compile all generated files as thumb.
577# TODO: support compiling certain generated files as arm.
578$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
579$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
580$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \
581    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
582    | $(my_compiler_dependencies)
583	$(transform-$(PRIVATE_HOST)c-to-o)
584-include $(gen_c_objects:%.o=%.P)
585endif
586
587###########################################################
588## ObjC: Compile .m files to .o
589###########################################################
590
591objc_sources := $(filter %.m,$(LOCAL_SRC_FILES))
592objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
593
594ifneq ($(strip $(objc_objects)),)
595$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) \
596    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
597    | $(my_compiler_dependencies)
598	$(transform-$(PRIVATE_HOST)m-to-o)
599-include $(objc_objects:%.o=%.P)
600endif
601
602###########################################################
603## AS: Compile .S files to .o.
604###########################################################
605
606asm_sources_S := $(filter %.S,$(LOCAL_SRC_FILES))
607asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
608
609ifneq ($(strip $(asm_objects_S)),)
610$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \
611    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
612    | $(my_compiler_dependencies)
613	$(transform-$(PRIVATE_HOST)s-to-o)
614-include $(asm_objects_S:%.o=%.P)
615endif
616
617asm_sources_s := $(filter %.s,$(LOCAL_SRC_FILES))
618asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
619
620ifneq ($(strip $(asm_objects_s)),)
621$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \
622    $(LOCAL_ADDITIONAL_DEPENDENCIES) \
623    | $(my_compiler_dependencies)
624	$(transform-$(PRIVATE_HOST)s-to-o-no-deps)
625-include $(asm_objects_s:%.o=%.P)
626endif
627
628asm_objects := $(asm_objects_S) $(asm_objects_s)
629
630
631####################################################
632## Import includes
633####################################################
634import_includes := $(intermediates)/import_includes
635import_includes_deps := $(strip \
636    $(foreach l, $(installed_shared_library_module_names), \
637      $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE))/export_includes) \
638    $(foreach l, $(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
639      $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE))/export_includes))
640$(import_includes) : $(import_includes_deps)
641	@echo Import includes file: $@
642	$(hide) mkdir -p $(dir $@) && rm -f $@
643ifdef import_includes_deps
644	$(hide) for f in $^; do \
645	  cat $$f >> $@; \
646	done
647else
648	$(hide) touch $@
649endif
650
651###########################################################
652## Common object handling.
653###########################################################
654
655# some rules depend on asm_objects being first.  If your code depends on
656# being first, it's reasonable to require it to be assembly
657normal_objects := \
658    $(asm_objects) \
659    $(cpp_objects) \
660    $(gen_cpp_objects) \
661    $(gen_asm_objects) \
662    $(c_objects) \
663    $(gen_c_objects) \
664    $(objc_objects) \
665    $(yacc_objects) \
666    $(lex_objects) \
667    $(proto_generated_objects) \
668    $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
669
670all_objects := $(normal_objects) $(gen_o_objects)
671
672LOCAL_C_INCLUDES += $(TOPDIR)$(LOCAL_PATH) $(intermediates)
673
674ifndef LOCAL_SDK_VERSION
675  LOCAL_C_INCLUDES += $(JNI_H_INCLUDE)
676endif
677
678# all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES;
679# use normal_objects here to avoid creating circular dependencies. This assumes
680# that custom build rules which generate .o files don't consume other generated
681# sources as input (or if they do they take care of that dependency themselves).
682$(normal_objects) : | $(LOCAL_GENERATED_SOURCES)
683$(all_objects) : | $(import_includes)
684ALL_C_CPP_ETC_OBJECTS += $(all_objects)
685
686###########################################################
687## Copy headers to the install tree
688###########################################################
689include $(BUILD_COPY_HEADERS)
690
691###########################################################
692# Standard library handling.
693###########################################################
694
695###########################################################
696# The list of libraries that this module will link against are in
697# these variables.  Each is a list of bare module names like "libc libm".
698#
699# LOCAL_SHARED_LIBRARIES
700# LOCAL_STATIC_LIBRARIES
701# LOCAL_WHOLE_STATIC_LIBRARIES
702#
703# We need to convert the bare names into the dependencies that
704# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
705# LOCAL_BUILT_MODULE should depend on the BUILT versions of the
706# libraries, so that simply building this module doesn't force
707# an install of a library.  Similarly, LOCAL_INSTALLED_MODULE
708# should depend on the INSTALLED versions of the libraries so
709# that they get installed when this module does.
710###########################################################
711# NOTE:
712# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
713# module without leaving anything out, which is useful for turning
714# a collection of .a files into a .so file.  Linking against a
715# normal STATIC_LIBRARY will only pull in code/symbols that are
716# referenced by the module. (see gcc/ld's --whole-archive option)
717###########################################################
718
719# Get the list of BUILT libraries, which are under
720# various intermediates directories.
721so_suffix := $($(my_prefix)SHLIB_SUFFIX)
722a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
723
724ifdef LOCAL_SDK_VERSION
725built_shared_libraries := \
726    $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
727      $(addsuffix $(so_suffix), \
728        $(LOCAL_SHARED_LIBRARIES)))
729
730my_system_shared_libraries_fullpath := \
731    $(my_ndk_stl_shared_lib_fullpath) \
732    $(addprefix $(my_ndk_version_root)/usr/lib/, \
733        $(addsuffix $(so_suffix), $(LOCAL_SYSTEM_SHARED_LIBRARIES)))
734
735built_shared_libraries += $(my_system_shared_libraries_fullpath)
736LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
737else
738LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
739built_shared_libraries := \
740    $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
741      $(addsuffix $(so_suffix), \
742        $(LOCAL_SHARED_LIBRARIES)))
743endif
744
745built_static_libraries := \
746    $(foreach lib,$(LOCAL_STATIC_LIBRARIES), \
747      $(call intermediates-dir-for, \
748        STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
749
750ifdef LOCAL_SDK_VERSION
751built_static_libraries += $(my_ndk_stl_static_lib)
752endif
753
754built_whole_libraries := \
755    $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \
756      $(call intermediates-dir-for, \
757        STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
758
759# We don't care about installed static libraries, since the
760# libraries have already been linked into the module at that point.
761# We do, however, care about the NOTICE files for any static
762# libraries that we use. (see notice_files.mk)
763
764installed_static_library_notice_file_targets := \
765    $(foreach lib,$(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
766      NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib))
767
768# Default is -fno-rtti.
769ifeq ($(strip $(LOCAL_RTTI_FLAG)),)
770LOCAL_RTTI_FLAG := -fno-rtti
771endif
772
773###########################################################
774# Rule-specific variable definitions
775###########################################################
776
777ifeq ($(LOCAL_CLANG),true)
778LOCAL_CFLAGS := $(call convert-to-$(my_host)clang-flags,$(LOCAL_CFLAGS))
779LOCAL_CPPFLAGS := $(call convert-to-$(my_host)clang-flags,$(LOCAL_CPPFLAGS))
780LOCAL_ASFLAGS := $(call convert-to-$(my_host)clang-flags,$(LOCAL_ASFLAGS))
781LOCAL_LDFLAGS := $(call convert-to-$(my_host)clang-flags,$(LOCAL_LDFLAGS))
782endif
783
784$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
785$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS)
786$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(LOCAL_CONLYFLAGS)
787$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS)
788$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS)
789$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
790$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
791$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(LOCAL_C_INCLUDES)
792$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes)
793$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(LOCAL_LDFLAGS)
794$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS)
795$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_CRT := $(LOCAL_NO_CRT)
796
797# this is really the way to get the files onto the command line instead
798# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
799$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
800$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
801$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
802$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects)
803
804###########################################################
805# Define library dependencies.
806###########################################################
807# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
808all_libraries := \
809    $(built_shared_libraries) \
810    $(built_static_libraries) \
811    $(built_whole_libraries)
812
813# Also depend on the notice files for any static libraries that
814# are linked into this module.  This will force them to be installed
815# when this module is.
816$(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets)
817
818###########################################################
819# Export includes
820###########################################################
821export_includes := $(intermediates)/export_includes
822$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
823$(export_includes) : $(LOCAL_MODULE_MAKEFILE)
824	@echo Export includes file: $< -- $@
825	$(hide) mkdir -p $(dir $@) && rm -f $@
826ifdef LOCAL_EXPORT_C_INCLUDE_DIRS
827	$(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \
828	        echo "-I $$d" >> $@; \
829	        done
830else
831	$(hide) touch $@
832endif
833
834# Make sure export_includes gets generated when you are running mm/mmm
835$(LOCAL_BUILT_MODULE) : | $(export_includes)
836