OSDN Git Service

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