1 ###########################################################
2 ## Standard rules for building binary object files from
3 ## asm/c/cpp/yacc/lex source files.
5 ## The list of object files is exported in $(all_objects).
6 ###########################################################
9 ifdef LOCAL_SDK_VERSION
10 ifdef LOCAL_NDK_VERSION
11 $(error $(LOCAL_PATH): LOCAL_NDK_VERSION is now retired.)
13 ifdef LOCAL_IS_HOST_MODULE
14 $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
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)
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
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))
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
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
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
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 :=
64 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
65 LOCAL_SYSTEM_SHARED_LIBRARIES := $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES)
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
74 # TODO: remove this hack and change all modules to use liblog
77 $(if $(filter liblog,$(1)),$(1), \
78 $(if $(filter libcutils,$(1)), \
79 $(patsubst libcutils,liblog libcutils,$(1)) \
81 $(patsubst libutils,liblog libutils,$(1)) \
85 ifneq (,$(filter libcutils libutils,$(LOCAL_SHARED_LIBRARIES)))
86 LOCAL_SHARED_LIBRARIES := $(call insert-liblog,$(LOCAL_SHARED_LIBRARIES))
88 ifneq (,$(filter libcutils libutils,$(LOCAL_STATIC_LIBRARIES)))
89 LOCAL_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_STATIC_LIBRARIES))
91 ifneq (,$(filter libcutils libutils,$(LOCAL_WHOLE_STATIC_LIBRARIES)))
92 LOCAL_WHOLE_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_WHOLE_STATIC_LIBRARIES))
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)
102 installed_shared_library_module_names := \
103 $(LOCAL_SYSTEM_SHARED_LIBRARIES) $(LOCAL_SHARED_LIBRARIES)
105 installed_shared_library_module_names := $(sort $(installed_shared_library_module_names))
107 #######################################
108 include $(BUILD_SYSTEM)/base_rules.mk
109 #######################################
111 # The real dependency will be added after all Android.mks are loaded and the install paths
112 # of the shared libraries are determined.
113 ifdef LOCAL_INSTALLED_MODULE
114 ifdef installed_shared_library_module_names
115 $(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += $(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(installed_shared_library_module_names))
119 ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),true)
121 LOCAL_CFLAGS += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS)
122 LOCAL_LDFLAGS += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS)
123 LOCAL_SHARED_LIBRARIES += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES)
124 LOCAL_STATIC_LIBRARIES += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES)
127 # Add in libcompiler_rt for all regular device builds
128 ifeq (,$(LOCAL_SDK_VERSION)$(LOCAL_IS_HOST_MODULE)$(WITHOUT_LIBCOMPILER_RT))
129 LOCAL_STATIC_LIBRARIES += $(COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES)
132 my_compiler_dependencies :=
133 ifeq ($(strip $(LOCAL_CLANG)),true)
134 LOCAL_CFLAGS += $(CLANG_CONFIG_EXTRA_CFLAGS)
135 LOCAL_ASFLAGS += $(CLANG_CONFIG_EXTRA_ASFLAGS)
136 LOCAL_LDFLAGS += $(CLANG_CONFIG_EXTRA_LDFLAGS)
137 my_compiler_dependencies := $(CLANG) $(CLANG_CXX)
140 ####################################################
141 ## Add FDO flags if FDO is turned on and supported
142 ####################################################
143 ifeq ($(strip $(LOCAL_NO_FDO_SUPPORT)),)
144 LOCAL_CFLAGS += $(TARGET_FDO_CFLAGS)
145 LOCAL_CPPFLAGS += $(TARGET_FDO_CFLAGS)
146 LOCAL_LDFLAGS += $(TARGET_FDO_CFLAGS)
149 ####################################################
150 ## Add profiling flags if aprof is turned on
151 ####################################################
152 ifeq ($(strip $(LOCAL_ENABLE_APROF)),true)
153 # -ffunction-sections and -fomit-frame-pointer are conflict with -pg
154 LOCAL_CFLAGS += -fno-omit-frame-pointer -fno-function-sections -pg
155 LOCAL_CPPFLAGS += -fno-omit-frame-pointer -fno-function-sections -pg
158 ###########################################################
159 ## Explicitly declare assembly-only __ASSEMBLY__ macro for
161 ###########################################################
162 LOCAL_ASFLAGS += -D__ASSEMBLY__
164 ###########################################################
165 ## Define PRIVATE_ variables from global vars
166 ###########################################################
167 ifdef LOCAL_SDK_VERSION
168 my_target_project_includes :=
169 my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_version_root)/usr/include
171 # filter out including of AndroidConfig.h in system/core.
172 TARGET_GLOBAL_CFLAGS_NO_ANDCONF ?= $(subst $(TARGET_ANDROID_CONFIG_CFLAGS),,\
173 $(TARGET_GLOBAL_CFLAGS))
174 my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS_NO_ANDCONF)
176 my_target_project_includes := $(TARGET_PROJECT_INCLUDES)
177 my_target_c_includes := $(TARGET_C_INCLUDES)
178 ifeq ($(strip $(LOCAL_CLANG)),true)
179 my_target_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES)
180 my_target_global_cflags := $(TARGET_GLOBAL_CLANG_FLAGS)
182 my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS)
184 endif # LOCAL_SDK_VERSION
186 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes)
187 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes)
188 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
189 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(TARGET_GLOBAL_CPPFLAGS)
191 ###########################################################
192 ## Define PRIVATE_ variables used by multiple module types
193 ###########################################################
194 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
195 $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
197 ifeq ($(strip $(LOCAL_CC)),)
198 ifeq ($(strip $(LOCAL_CLANG)),true)
201 LOCAL_CC := $($(my_prefix)CC)
204 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(LOCAL_CC)
206 ifeq ($(strip $(LOCAL_CXX)),)
207 ifeq ($(strip $(LOCAL_CLANG)),true)
208 LOCAL_CXX := $(CLANG_CXX)
210 LOCAL_CXX := $($(my_prefix)CXX)
213 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(LOCAL_CXX)
215 # TODO: support a mix of standard extensions so that this isn't necessary
216 LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
217 ifeq ($(LOCAL_CPP_EXTENSION),)
218 LOCAL_CPP_EXTENSION := .cpp
220 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION)
222 # Certain modules like libdl have to have symbols resolved at runtime and blow
223 # up if --no-undefined is passed to the linker.
224 ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
225 ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),)
226 LOCAL_LDFLAGS := $(LOCAL_LDFLAGS) $($(my_prefix)NO_UNDEFINED_LDFLAGS)
230 ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES))
231 $(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true
233 $(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES :=
236 ###########################################################
237 ## Define arm-vs-thumb-mode flags.
238 ###########################################################
239 LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
240 ifeq ($(TARGET_ARCH),arm)
241 arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
242 normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
244 # Read the values from something like TARGET_arm_CFLAGS or
245 # TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't
246 # actually used (although they are usually empty).
247 ifeq ($(strip $(LOCAL_CLANG)),true)
248 arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CLANG_CFLAGS)
249 normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_CLANG_CFLAGS)
251 arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CFLAGS)
252 normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_CFLAGS)
257 normal_objects_mode :=
258 arm_objects_cflags :=
259 normal_objects_cflags :=
262 ###########################################################
263 ## Define per-module debugging flags. Users can turn on
264 ## debugging for a particular module by setting DEBUG_MODULE_ModuleName
265 ## to a non-empty value in their environment or buildspec.mk,
266 ## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
267 ## debug flags that they want to use.
268 ###########################################################
269 ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
270 debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
275 ####################################################
276 ## Compile RenderScript with reflected C++
277 ####################################################
279 renderscript_sources := $(filter %.rs %.fs,$(LOCAL_SRC_FILES))
281 ifneq (,$(renderscript_sources))
283 renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
284 RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp
285 renderscript_intermediate := $(intermediates)/renderscript
287 ifeq ($(LOCAL_RENDERSCRIPT_CC),)
288 LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
291 # Turn on all warnings and warnings as errors for RS compiles.
292 # This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
293 renderscript_flags := -Wall -Werror
294 renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
296 LOCAL_RENDERSCRIPT_INCLUDES := \
297 $(TOPDIR)external/clang/lib/Headers \
298 $(TOPDIR)frameworks/rs/scriptc \
299 $(LOCAL_RENDERSCRIPT_INCLUDES)
301 ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
302 LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
305 $(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES)
306 $(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
307 $(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
308 $(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
309 $(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate)
310 $(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
311 $(transform-renderscripts-to-cpp-and-bc)
313 # include the dependency files (.d) generated by llvm-rs-cc.
314 renderscript_generated_dep_files := $(addprefix $(renderscript_intermediate)/, \
315 $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources)))))
316 -include $(renderscript_generated_dep_files)
318 LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
320 rs_generated_cpps := $(addprefix \
321 $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rs,%.cpp, \
322 $(notdir $(renderscript_sources)))))
324 $(rs_generated_cpps) : $(RenderScript_file_stamp)
326 LOCAL_C_INCLUDES += $(renderscript_intermediate)
327 LOCAL_GENERATED_SOURCES += $(rs_generated_cpps)
332 ###########################################################
333 ## Stuff source generated from one-off tools
334 ###########################################################
335 $(LOCAL_GENERATED_SOURCES): PRIVATE_MODULE := $(LOCAL_MODULE)
337 ALL_GENERATED_SOURCES += $(LOCAL_GENERATED_SOURCES)
340 ###########################################################
341 ## Compile the .proto files to .cc and then to .o
342 ###########################################################
343 proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
344 proto_generated_objects :=
345 proto_generated_headers :=
346 ifneq ($(proto_sources),)
347 proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
348 proto_generated_cc_sources_dir := $(intermediates)/proto
349 proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \
350 $(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath)))
351 proto_generated_objects := $(patsubst %.cc,%.o, $(proto_generated_cc_sources))
353 $(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
354 $(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir)
355 $(proto_generated_cc_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
356 $(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC)
357 $(transform-proto-to-cc)
359 proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources))
360 $(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc
362 $(proto_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
363 $(proto_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
364 $(proto_generated_objects): $(proto_generated_cc_sources_dir)/%.o: $(proto_generated_cc_sources_dir)/%.cc $(proto_generated_headers)
365 $(transform-$(PRIVATE_HOST)cpp-to-o)
366 -include $(proto_generated_objects:%.o=%.P)
368 LOCAL_C_INCLUDES += external/protobuf/src $(proto_generated_cc_sources_dir)
369 LOCAL_CFLAGS += -DGOOGLE_PROTOBUF_NO_RTTI
370 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
371 LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-full
373 LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-lite
378 ###########################################################
379 ## YACC: Compile .y files to .cpp and the to .o.
380 ###########################################################
382 yacc_sources := $(filter %.y,$(LOCAL_SRC_FILES))
383 yacc_cpps := $(addprefix \
384 $(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION)))
385 yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h)
386 yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o)
388 ifneq ($(strip $(yacc_cpps)),)
389 $(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
390 $(TOPDIR)$(LOCAL_PATH)/%.y \
391 $(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
392 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
393 $(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
395 $(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
396 $(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
397 $(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
398 $(transform-$(PRIVATE_HOST)cpp-to-o)
401 ###########################################################
402 ## LEX: Compile .l files to .cpp and then to .o.
403 ###########################################################
405 lex_sources := $(filter %.l,$(LOCAL_SRC_FILES))
406 lex_cpps := $(addprefix \
407 $(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION)))
408 lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o)
410 ifneq ($(strip $(lex_cpps)),)
411 $(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
412 $(TOPDIR)$(LOCAL_PATH)/%.l
413 $(transform-l-to-cpp)
415 $(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
416 $(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
417 $(lex_objects): $(intermediates)/%.o: \
418 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \
419 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
421 $(transform-$(PRIVATE_HOST)cpp-to-o)
424 ###########################################################
425 ## C++: Compile .cpp files to .o.
426 ###########################################################
428 # we also do this on host modules, even though
429 # it's not really arm, because there are files that are shared.
430 cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(LOCAL_SRC_FILES)))
431 cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o))
433 cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES))
434 cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
436 $(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
437 $(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
438 $(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
439 $(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
441 cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects)
443 ifneq ($(strip $(cpp_objects)),)
444 $(cpp_objects): $(intermediates)/%.o: \
445 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
446 $(yacc_cpps) $(proto_generated_headers) \
447 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
448 | $(my_compiler_dependencies)
449 $(transform-$(PRIVATE_HOST)cpp-to-o)
450 -include $(cpp_objects:%.o=%.P)
453 ###########################################################
454 ## C++: Compile generated .cpp files to .o.
455 ###########################################################
457 gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_GENERATED_SOURCES))
458 gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
460 ifneq ($(strip $(gen_cpp_objects)),)
461 # Compile all generated files as thumb.
462 # TODO: support compiling certain generated files as arm.
463 $(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
464 $(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
465 $(gen_cpp_objects): $(intermediates)/%.o: \
466 $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) \
467 $(proto_generated_headers) \
468 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
469 | $(my_compiler_dependencies)
470 $(transform-$(PRIVATE_HOST)cpp-to-o)
471 -include $(gen_cpp_objects:%.o=%.P)
474 ###########################################################
475 ## S: Compile generated .S and .s files to .o.
476 ###########################################################
478 gen_S_sources := $(filter %.S,$(LOCAL_GENERATED_SOURCES))
479 gen_S_objects := $(gen_S_sources:%.S=%.o)
481 ifneq ($(strip $(gen_S_sources)),)
482 $(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \
483 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
484 | $(my_compiler_dependencies)
485 $(transform-$(PRIVATE_HOST)s-to-o)
486 -include $(gen_S_objects:%.o=%.P)
489 gen_s_sources := $(filter %.s,$(LOCAL_GENERATED_SOURCES))
490 gen_s_objects := $(gen_s_sources:%.s=%.o)
492 ifneq ($(strip $(gen_s_objects)),)
493 $(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \
494 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
495 | $(my_compiler_dependencies)
496 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
497 -include $(gen_s_objects:%.o=%.P)
500 gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
502 ###########################################################
503 ## o: Include generated .o files in output.
504 ###########################################################
506 gen_o_objects := $(filter %.o,$(LOCAL_GENERATED_SOURCES))
508 ###########################################################
509 ## C: Compile .c files to .o.
510 ###########################################################
512 c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(LOCAL_SRC_FILES)))
513 c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o))
515 c_normal_sources := $(filter %.c,$(LOCAL_SRC_FILES))
516 c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
518 $(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
519 $(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
520 $(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
521 $(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
523 c_objects := $(c_arm_objects) $(c_normal_objects)
525 ifneq ($(strip $(c_objects)),)
526 $(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \
527 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
528 | $(my_compiler_dependencies)
529 $(transform-$(PRIVATE_HOST)c-to-o)
530 -include $(c_objects:%.o=%.P)
533 ###########################################################
534 ## C: Compile generated .c files to .o.
535 ###########################################################
537 gen_c_sources := $(filter %.c,$(LOCAL_GENERATED_SOURCES))
538 gen_c_objects := $(gen_c_sources:%.c=%.o)
540 ifneq ($(strip $(gen_c_objects)),)
541 # Compile all generated files as thumb.
542 # TODO: support compiling certain generated files as arm.
543 $(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
544 $(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
545 $(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \
546 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
547 | $(my_compiler_dependencies)
548 $(transform-$(PRIVATE_HOST)c-to-o)
549 -include $(gen_c_objects:%.o=%.P)
552 ###########################################################
553 ## ObjC: Compile .m files to .o
554 ###########################################################
556 objc_sources := $(filter %.m,$(LOCAL_SRC_FILES))
557 objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
559 ifneq ($(strip $(objc_objects)),)
560 $(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) \
561 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
562 | $(my_compiler_dependencies)
563 $(transform-$(PRIVATE_HOST)m-to-o)
564 -include $(objc_objects:%.o=%.P)
567 ###########################################################
568 ## AS: Compile .S files to .o.
569 ###########################################################
571 asm_sources_S := $(filter %.S,$(LOCAL_SRC_FILES))
572 asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
574 ifneq ($(strip $(asm_objects_S)),)
575 $(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \
576 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
577 | $(my_compiler_dependencies)
578 $(transform-$(PRIVATE_HOST)s-to-o)
579 -include $(asm_objects_S:%.o=%.P)
582 asm_sources_s := $(filter %.s,$(LOCAL_SRC_FILES))
583 asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
585 ifneq ($(strip $(asm_objects_s)),)
586 $(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \
587 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
588 | $(my_compiler_dependencies)
589 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
590 -include $(asm_objects_s:%.o=%.P)
593 asm_objects := $(asm_objects_S) $(asm_objects_s)
596 ####################################################
598 ####################################################
599 import_includes := $(intermediates)/import_includes
600 import_includes_deps := $(strip \
601 $(foreach l, $(installed_shared_library_module_names), \
602 $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE))/export_includes) \
603 $(foreach l, $(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
604 $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE))/export_includes))
605 $(import_includes) : $(import_includes_deps)
606 @echo Import includes file: $@
607 $(hide) mkdir -p $(dir $@) && rm -f $@
608 ifdef import_includes_deps
609 $(hide) for f in $^; do \
616 ###########################################################
617 ## Common object handling.
618 ###########################################################
620 # some rules depend on asm_objects being first. If your code depends on
621 # being first, it's reasonable to require it to be assembly
632 $(proto_generated_objects) \
633 $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES)) \
636 LOCAL_C_INCLUDES += $(TOPDIR)$(LOCAL_PATH) $(intermediates)
638 ifndef LOCAL_SDK_VERSION
639 LOCAL_C_INCLUDES += $(JNI_H_INCLUDE)
642 # .o files need to be filtered out of LOCAL_GENERATED_SOURCES
643 # to avoid creating circular dependencies.
644 $(all_objects) : | $(filter-out %.o,$(LOCAL_GENERATED_SOURCES)) $(import_includes)
645 ALL_C_CPP_ETC_OBJECTS += $(all_objects)
647 ###########################################################
648 ## Copy headers to the install tree
649 ###########################################################
650 include $(BUILD_COPY_HEADERS)
652 ###########################################################
653 # Standard library handling.
654 ###########################################################
656 ###########################################################
657 # The list of libraries that this module will link against are in
658 # these variables. Each is a list of bare module names like "libc libm".
660 # LOCAL_SHARED_LIBRARIES
661 # LOCAL_STATIC_LIBRARIES
662 # LOCAL_WHOLE_STATIC_LIBRARIES
664 # We need to convert the bare names into the dependencies that
665 # we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
666 # LOCAL_BUILT_MODULE should depend on the BUILT versions of the
667 # libraries, so that simply building this module doesn't force
668 # an install of a library. Similarly, LOCAL_INSTALLED_MODULE
669 # should depend on the INSTALLED versions of the libraries so
670 # that they get installed when this module does.
671 ###########################################################
673 # WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
674 # module without leaving anything out, which is useful for turning
675 # a collection of .a files into a .so file. Linking against a
676 # normal STATIC_LIBRARY will only pull in code/symbols that are
677 # referenced by the module. (see gcc/ld's --whole-archive option)
678 ###########################################################
680 # Get the list of BUILT libraries, which are under
681 # various intermediates directories.
682 so_suffix := $($(my_prefix)SHLIB_SUFFIX)
683 a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
685 ifdef LOCAL_SDK_VERSION
686 built_shared_libraries := \
687 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
688 $(addsuffix $(so_suffix), \
689 $(LOCAL_SHARED_LIBRARIES)))
691 my_system_shared_libraries_fullpath := \
692 $(my_ndk_stl_shared_lib_fullpath) \
693 $(addprefix $(my_ndk_version_root)/usr/lib/, \
694 $(addsuffix $(so_suffix), $(LOCAL_SYSTEM_SHARED_LIBRARIES)))
696 built_shared_libraries += $(my_system_shared_libraries_fullpath)
697 LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
699 LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
700 built_shared_libraries := \
701 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
702 $(addsuffix $(so_suffix), \
703 $(LOCAL_SHARED_LIBRARIES)))
706 built_static_libraries := \
707 $(foreach lib,$(LOCAL_STATIC_LIBRARIES), \
708 $(call intermediates-dir-for, \
709 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
711 ifdef LOCAL_SDK_VERSION
712 built_static_libraries += $(my_ndk_stl_static_lib)
715 built_whole_libraries := \
716 $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \
717 $(call intermediates-dir-for, \
718 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
720 # We don't care about installed static libraries, since the
721 # libraries have already been linked into the module at that point.
722 # We do, however, care about the NOTICE files for any static
723 # libraries that we use. (see notice_files.mk)
725 installed_static_library_notice_file_targets := \
726 $(foreach lib,$(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
727 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib))
729 # Default is -fno-rtti.
730 ifeq ($(strip $(LOCAL_RTTI_FLAG)),)
731 LOCAL_RTTI_FLAG := -fno-rtti
734 ###########################################################
735 # Rule-specific variable definitions
736 ###########################################################
737 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
738 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS)
739 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(LOCAL_CONLYFLAGS)
740 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS)
741 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS)
742 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
743 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
744 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(LOCAL_C_INCLUDES)
745 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes)
746 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(LOCAL_LDFLAGS)
747 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS)
748 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_CRT := $(LOCAL_NO_CRT)
750 # this is really the way to get the files onto the command line instead
751 # of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
752 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
753 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
754 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
755 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects)
757 ###########################################################
758 # Define library dependencies.
759 ###########################################################
760 # all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
762 $(built_shared_libraries) \
763 $(built_static_libraries) \
764 $(built_whole_libraries)
766 # Also depend on the notice files for any static libraries that
767 # are linked into this module. This will force them to be installed
768 # when this module is.
769 $(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets)
771 ###########################################################
773 ###########################################################
774 export_includes := $(intermediates)/export_includes
775 $(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
776 $(export_includes) : $(LOCAL_MODULE_MAKEFILE)
777 @echo Export includes file: $< -- $@
778 $(hide) mkdir -p $(dir $@) && rm -f $@
779 ifdef LOCAL_EXPORT_C_INCLUDE_DIRS
780 $(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \
781 echo "-I $$d" >> $@; \
787 # Make sure export_includes gets generated when you are running mm/mmm
788 $(LOCAL_BUILT_MODULE) : | $(export_includes)