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