OSDN Git Service

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