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