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