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