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