binary.mk revision e3c3c6d4fecf12e725dbf0f5bb9967787149c457
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
140ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES))
141$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true
142else
143$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES :=
144endif
145
146###########################################################
147## Define arm-vs-thumb-mode flags.
148###########################################################
149LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
150ifeq ($(TARGET_ARCH),arm)
151arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
152normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
153
154# Read the values from something like TARGET_arm_CFLAGS or
155# TARGET_thumb_CFLAGS.  HOST_(arm|thumb)_CFLAGS values aren't
156# actually used (although they are usually empty).
157arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CFLAGS)
158normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_CFLAGS)
159else
160arm_objects_mode :=
161normal_objects_mode :=
162arm_objects_cflags :=
163normal_objects_cflags :=
164endif
165
166###########################################################
167## Define per-module debugging flags.  Users can turn on
168## debugging for a particular module by setting DEBUG_MODULE_ModuleName
169## to a non-empty value in their environment or buildspec.mk,
170## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
171## debug flags that they want to use.
172###########################################################
173ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
174  debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
175else
176  debug_cflags :=
177endif
178
179###########################################################
180## Stuff source generated from one-off tools
181###########################################################
182$(LOCAL_GENERATED_SOURCES): PRIVATE_MODULE := $(LOCAL_MODULE)
183
184ALL_GENERATED_SOURCES += $(LOCAL_GENERATED_SOURCES)
185
186
187###########################################################
188## Compile the .proto files to .cc and then to .o
189###########################################################
190proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
191proto_generated_objects :=
192proto_generated_headers :=
193ifneq ($(proto_sources),)
194proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
195proto_generated_cc_sources_dir := $(intermediates)/proto
196proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \
197	$(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath)))
198proto_generated_objects := $(patsubst %.cc,%.o, $(proto_generated_cc_sources))
199
200$(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
201$(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir)
202$(proto_generated_cc_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
203$(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC)
204	$(transform-proto-to-cc)
205
206proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources))
207$(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc
208
209$(proto_generated_cc_sources): PRIVATE_ARM_MODE := $(normal_objects_mode)
210$(proto_generated_cc_sources): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
211$(proto_generated_objects): $(proto_generated_cc_sources_dir)/%.o: $(proto_generated_cc_sources_dir)/%.cc
212	$(transform-$(PRIVATE_HOST)cpp-to-o)
213-include $(proto_generated_objects:%.o=%.P)
214
215LOCAL_C_INCLUDES += external/protobuf/src $(proto_generated_cc_sources_dir)
216LOCAL_CFLAGS += -DGOOGLE_PROTOBUF_NO_RTTI
217ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
218LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-full
219else
220LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-lite
221endif
222endif
223
224
225###########################################################
226## YACC: Compile .y files to .cpp and the to .o.
227###########################################################
228
229yacc_sources := $(filter %.y,$(LOCAL_SRC_FILES))
230yacc_cpps := $(addprefix \
231	$(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION)))
232yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h)
233yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o)
234
235ifneq ($(strip $(yacc_cpps)),)
236$(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
237		$(TOPDIR)$(LOCAL_PATH)/%.y \
238		$(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
239	$(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
240$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
241
242$(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
243$(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
244$(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
245	$(transform-$(PRIVATE_HOST)cpp-to-o)
246endif
247
248###########################################################
249## LEX: Compile .l files to .cpp and then to .o.
250###########################################################
251
252lex_sources := $(filter %.l,$(LOCAL_SRC_FILES))
253lex_cpps := $(addprefix \
254	$(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION)))
255lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o)
256
257ifneq ($(strip $(lex_cpps)),)
258$(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
259		$(TOPDIR)$(LOCAL_PATH)/%.l
260	$(transform-l-to-cpp)
261
262$(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
263$(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
264$(lex_objects): $(intermediates)/%.o: \
265		$(intermediates)/%$(LOCAL_CPP_EXTENSION) \
266		$(LOCAL_ADDITIONAL_DEPENDENCIES) \
267		$(yacc_headers)
268	$(transform-$(PRIVATE_HOST)cpp-to-o)
269endif
270
271###########################################################
272## C++: Compile .cpp files to .o.
273###########################################################
274
275# we also do this on host modules and sim builds, even though
276# it's not really arm, because there are files that are shared.
277cpp_arm_sources    := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(LOCAL_SRC_FILES)))
278cpp_arm_objects    := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o))
279
280cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES))
281cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
282
283$(cpp_arm_objects):    PRIVATE_ARM_MODE := $(arm_objects_mode)
284$(cpp_arm_objects):    PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
285$(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
286$(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
287
288cpp_objects        := $(cpp_arm_objects) $(cpp_normal_objects)
289
290ifneq ($(strip $(cpp_objects)),)
291$(cpp_objects): $(intermediates)/%.o: \
292		$(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
293		$(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES)
294	$(transform-$(PRIVATE_HOST)cpp-to-o)
295-include $(cpp_objects:%.o=%.P)
296endif
297
298###########################################################
299## C++: Compile generated .cpp files to .o.
300###########################################################
301
302gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_GENERATED_SOURCES))
303gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
304
305ifneq ($(strip $(gen_cpp_objects)),)
306# Compile all generated files as thumb.
307# TODO: support compiling certain generated files as arm.
308$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
309$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
310$(gen_cpp_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES)
311	$(transform-$(PRIVATE_HOST)cpp-to-o)
312-include $(gen_cpp_objects:%.o=%.P)
313endif
314
315###########################################################
316## S: Compile generated .S and .s files to .o.
317###########################################################
318
319gen_S_sources := $(filter %.S,$(LOCAL_GENERATED_SOURCES))
320gen_S_objects := $(gen_S_sources:%.S=%.o)
321
322ifneq ($(strip $(gen_S_sources)),)
323$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S $(LOCAL_ADDITIONAL_DEPENDENCIES)
324	$(transform-$(PRIVATE_HOST)s-to-o)
325-include $(gen_S_objects:%.o=%.P)
326endif
327
328gen_s_sources := $(filter %.s,$(LOCAL_GENERATED_SOURCES))
329gen_s_objects := $(gen_s_sources:%.s=%.o)
330
331ifneq ($(strip $(gen_s_objects)),)
332$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s $(LOCAL_ADDITIONAL_DEPENDENCIES)
333	$(transform-$(PRIVATE_HOST)s-to-o-no-deps)
334-include $(gen_s_objects:%.o=%.P)
335endif
336
337gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
338
339###########################################################
340## C: Compile .c files to .o.
341###########################################################
342
343c_arm_sources    := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(LOCAL_SRC_FILES)))
344c_arm_objects    := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o))
345
346c_normal_sources := $(filter %.c,$(LOCAL_SRC_FILES))
347c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
348
349$(c_arm_objects):    PRIVATE_ARM_MODE := $(arm_objects_mode)
350$(c_arm_objects):    PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
351$(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
352$(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
353
354c_objects        := $(c_arm_objects) $(c_normal_objects)
355
356ifneq ($(strip $(c_objects)),)
357$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES)
358	$(transform-$(PRIVATE_HOST)c-to-o)
359-include $(c_objects:%.o=%.P)
360endif
361
362###########################################################
363## C: Compile generated .c files to .o.
364###########################################################
365
366gen_c_sources := $(filter %.c,$(LOCAL_GENERATED_SOURCES))
367gen_c_objects := $(gen_c_sources:%.c=%.o)
368
369ifneq ($(strip $(gen_c_objects)),)
370# Compile all generated files as thumb.
371# TODO: support compiling certain generated files as arm.
372$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
373$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
374$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES)
375	$(transform-$(PRIVATE_HOST)c-to-o)
376-include $(gen_c_objects:%.o=%.P)
377endif
378
379###########################################################
380## ObjC: Compile .m files to .o
381###########################################################
382
383objc_sources := $(filter %.m,$(LOCAL_SRC_FILES))
384objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
385
386ifneq ($(strip $(objc_objects)),)
387$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
388	$(transform-$(PRIVATE_HOST)m-to-o)
389-include $(objc_objects:%.o=%.P)
390endif
391
392###########################################################
393## AS: Compile .S files to .o.
394###########################################################
395
396asm_sources_S := $(filter %.S,$(LOCAL_SRC_FILES))
397asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
398
399ifneq ($(strip $(asm_objects_S)),)
400$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S $(LOCAL_ADDITIONAL_DEPENDENCIES)
401	$(transform-$(PRIVATE_HOST)s-to-o)
402-include $(asm_objects_S:%.o=%.P)
403endif
404
405asm_sources_s := $(filter %.s,$(LOCAL_SRC_FILES))
406asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
407
408ifneq ($(strip $(asm_objects_s)),)
409$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s $(LOCAL_ADDITIONAL_DEPENDENCIES)
410	$(transform-$(PRIVATE_HOST)s-to-o-no-deps)
411-include $(asm_objects_s:%.o=%.P)
412endif
413
414asm_objects := $(asm_objects_S) $(asm_objects_s)
415
416
417###########################################################
418## Common object handling.
419###########################################################
420
421# some rules depend on asm_objects being first.  If your code depends on
422# being first, it's reasonable to require it to be assembly
423all_objects := \
424	$(asm_objects) \
425	$(cpp_objects) \
426	$(gen_cpp_objects) \
427	$(gen_asm_objects) \
428	$(c_objects) \
429	$(gen_c_objects) \
430	$(objc_objects) \
431	$(yacc_objects) \
432	$(lex_objects) \
433	$(proto_generated_objects) \
434	$(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
435
436LOCAL_C_INCLUDES += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(base_intermediates)
437
438ifndef LOCAL_NDK_VERSION
439  LOCAL_C_INCLUDES += $(JNI_H_INCLUDE)
440endif
441
442$(all_objects) : | $(LOCAL_GENERATED_SOURCES)
443ALL_C_CPP_ETC_OBJECTS += $(all_objects)
444
445###########################################################
446## Copy headers to the install tree
447###########################################################
448include $(BUILD_COPY_HEADERS)
449
450###########################################################
451# Standard library handling.
452#
453# On the target, we compile with -nostdlib, so we must add in the
454# default system shared libraries, unless they have requested not
455# to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value.  One would
456# supply that, for example, when building libc itself.
457###########################################################
458ifdef LOCAL_IS_HOST_MODULE
459  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
460    LOCAL_SYSTEM_SHARED_LIBRARIES :=
461  endif
462else
463  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
464    LOCAL_SYSTEM_SHARED_LIBRARIES := $($(my_prefix)DEFAULT_SYSTEM_SHARED_LIBRARIES)
465  endif
466endif
467
468# Logging used to be part of libcutils (target) and libutils (sim);
469# hack modules that use those other libs to also include liblog.
470# All of this complexity is to make sure that liblog only appears
471# once, and appears just before libcutils or libutils on the link
472# line.
473# TODO: remove this hack and change all modules to use liblog
474# when necessary.
475define insert-liblog
476  $(if $(filter liblog,$(1)),$(1), \
477    $(if $(filter libcutils,$(1)), \
478      $(patsubst libcutils,liblog libcutils,$(1)) \
479     , \
480      $(patsubst libutils,liblog libutils,$(1)) \
481     ) \
482   )
483endef
484ifneq (,$(filter libcutils libutils,$(LOCAL_SHARED_LIBRARIES)))
485  LOCAL_SHARED_LIBRARIES := $(call insert-liblog,$(LOCAL_SHARED_LIBRARIES))
486endif
487ifneq (,$(filter libcutils libutils,$(LOCAL_STATIC_LIBRARIES)))
488  LOCAL_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_STATIC_LIBRARIES))
489endif
490ifneq (,$(filter libcutils libutils,$(LOCAL_WHOLE_STATIC_LIBRARIES)))
491  LOCAL_WHOLE_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_WHOLE_STATIC_LIBRARIES))
492endif
493
494###########################################################
495# The list of libraries that this module will link against are in
496# these variables.  Each is a list of bare module names like "libc libm".
497#
498# LOCAL_SHARED_LIBRARIES
499# LOCAL_STATIC_LIBRARIES
500# LOCAL_WHOLE_STATIC_LIBRARIES
501#
502# We need to convert the bare names into the dependencies that
503# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
504# LOCAL_BUILT_MODULE should depend on the BUILT versions of the
505# libraries, so that simply building this module doesn't force
506# an install of a library.  Similarly, LOCAL_INSTALLED_MODULE
507# should depend on the INSTALLED versions of the libraries so
508# that they get installed when this module does.
509###########################################################
510# NOTE:
511# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
512# module without leaving anything out, which is useful for turning
513# a collection of .a files into a .so file.  Linking against a
514# normal STATIC_LIBRARY will only pull in code/symbols that are
515# referenced by the module. (see gcc/ld's --whole-archive option)
516###########################################################
517
518# Get the list of BUILT libraries, which are under
519# various intermediates directories.
520so_suffix := $($(my_prefix)SHLIB_SUFFIX)
521a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
522
523ifdef LOCAL_NDK_VERSION
524built_shared_libraries := \
525    $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
526      $(addsuffix $(so_suffix), \
527        $(LOCAL_SHARED_LIBRARIES)))
528
529# Get the list of INSTALLED libraries.  Strip off the various
530# intermediates directories and point to the common lib dirs.
531installed_shared_libraries := \
532    $(addprefix $($(my_prefix)OUT_SHARED_LIBRARIES)/, \
533      $(notdir $(built_shared_libraries)))
534
535my_system_shared_libraries_fullpath := \
536    $(my_ndk_stl_shared_lib_fullpath) \
537    $(addprefix $(my_ndk_version_root)/usr/lib/, \
538        $(addsuffix $(so_suffix), $(LOCAL_SYSTEM_SHARED_LIBRARIES)))
539
540built_shared_libraries += $(my_system_shared_libraries_fullpath)
541LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
542else
543LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
544built_shared_libraries := \
545    $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
546      $(addsuffix $(so_suffix), \
547        $(LOCAL_SHARED_LIBRARIES)))
548
549installed_shared_libraries := \
550    $(addprefix $($(my_prefix)OUT_SHARED_LIBRARIES)/, \
551      $(notdir $(built_shared_libraries)))
552endif
553
554built_static_libraries := \
555    $(foreach lib,$(LOCAL_STATIC_LIBRARIES), \
556      $(call intermediates-dir-for, \
557        STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
558
559ifdef LOCAL_NDK_VERSION
560built_static_libraries += $(my_ndk_stl_static_lib)
561endif
562
563built_whole_libraries := \
564    $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \
565      $(call intermediates-dir-for, \
566        STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
567
568# We don't care about installed static libraries, since the
569# libraries have already been linked into the module at that point.
570# We do, however, care about the NOTICE files for any static
571# libraries that we use. (see notice_files.make)
572
573installed_static_library_notice_file_targets := \
574    $(foreach lib,$(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
575      NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib))
576
577# Default is -fno-rtti.
578ifeq ($(strip $(LOCAL_RTTI_FLAG)),)
579LOCAL_RTTI_FLAG := -fno-rtti
580endif
581
582###########################################################
583# Rule-specific variable definitions
584###########################################################
585$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
586$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS)
587$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS)
588$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS)
589$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
590$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
591$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(LOCAL_C_INCLUDES)
592$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(LOCAL_LDFLAGS)
593$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS)
594$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_CRT := $(LOCAL_NO_CRT)
595
596# this is really the way to get the files onto the command line instead
597# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
598$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
599$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
600$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
601$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects)
602
603###########################################################
604# Define library dependencies.
605###########################################################
606# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
607all_libraries := \
608    $(built_shared_libraries) \
609    $(built_static_libraries) \
610    $(built_whole_libraries)
611
612# Make LOCAL_INSTALLED_MODULE depend on the installed versions of the
613# libraries so they get installed along with it.  We don't need to
614# rebuild it when installing it, though, so this can be an order-only
615# dependency.
616$(LOCAL_INSTALLED_MODULE): | $(installed_shared_libraries)
617
618# Also depend on the notice files for any static libraries that
619# are linked into this module.  This will force them to be installed
620# when this module is.
621$(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets)
622