1 ###########################################################
2 ## Standard rules for building binary object files from
3 ## asm/c/cpp/yacc/lex/etc source files.
5 ## The list of object files is exported in $(all_objects).
6 ###########################################################
8 #######################################
9 include $(BUILD_SYSTEM)/base_rules.mk
10 #######################################
12 ##################################################
13 # Compute the dependency of the shared libraries
14 ##################################################
15 # On the target, we compile with -nostdlib, so we must add in the
16 # default system shared libraries, unless they have requested not
17 # to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value. One would
18 # supply that, for example, when building libc itself.
19 ifdef LOCAL_IS_HOST_MODULE
20 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
21 my_system_shared_libraries :=
23 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
26 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
27 my_system_shared_libraries := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES)
29 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
33 # The following LOCAL_ variables will be modified in this file.
34 # Because the same LOCAL_ variables may be used to define modules for both 1st arch and 2nd arch,
35 # we can't modify them in place.
36 my_src_files := $(LOCAL_SRC_FILES)
37 my_static_libraries := $(LOCAL_STATIC_LIBRARIES)
38 my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES)
39 my_shared_libraries := $(LOCAL_SHARED_LIBRARIES)
40 my_cflags := $(LOCAL_CFLAGS)
41 my_conlyflags := $(LOCAL_CONLYFLAGS)
42 my_cppflags := $(LOCAL_CPPFLAGS)
43 my_ldflags := $(LOCAL_LDFLAGS)
44 my_ldlibs := $(LOCAL_LDLIBS)
45 my_asflags := $(LOCAL_ASFLAGS)
47 my_cc_wrapper := $(CC_WRAPPER)
48 my_cxx := $(LOCAL_CXX)
49 my_cxx_wrapper := $(CXX_WRAPPER)
50 my_c_includes := $(LOCAL_C_INCLUDES)
51 my_generated_sources := $(LOCAL_GENERATED_SOURCES)
52 my_native_coverage := $(LOCAL_NATIVE_COVERAGE)
53 my_additional_dependencies := $(LOCAL_MODULE_MAKEFILE) $(LOCAL_ADDITIONAL_DEPENDENCIES)
54 my_export_c_include_dirs := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
56 ifdef LOCAL_IS_HOST_MODULE
57 my_allow_undefined_symbols := true
59 my_allow_undefined_symbols := $(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS))
63 my_ndk_sysroot_include :=
65 ifdef LOCAL_SDK_VERSION
66 ifdef LOCAL_NDK_VERSION
67 $(error $(LOCAL_PATH): LOCAL_NDK_VERSION is now retired.)
69 ifdef LOCAL_IS_HOST_MODULE
70 $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
72 my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources
73 my_ndk_sysroot := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
74 my_ndk_sysroot_include := $(my_ndk_sysroot)/usr/include
75 ifeq (x86_64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
76 my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/lib64
77 else ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
78 my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/libr6
80 my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/lib
83 # The bionic linker now has support for packed relocations and gnu style
84 # hashes (which are much faster!), but shipping to older devices requires
85 # the old style hash and disabling packed relocations.
86 #ifeq ($(shell expr $(LOCAL_SDK_VERSION) >= FIRST_SUPPORTED_VERSION),0)
87 my_ldflags += -Wl,--hash-style=sysv
88 LOCAL_PACK_MODULE_RELOCATIONS := false
91 # Set up the NDK stl variant. Starting from NDK-r5 the c++ stl resides in a separate location.
92 # See ndk/docs/CPLUSPLUS-SUPPORT.html
93 my_ndk_stl_include_path :=
94 my_ndk_stl_shared_lib_fullpath :=
95 my_ndk_stl_shared_lib :=
96 my_ndk_stl_static_lib :=
97 my_ndk_stl_cppflags :=
98 my_cpu_variant := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)
99 ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
100 my_cpu_variant := mips32r6
102 LOCAL_NDK_STL_VARIANT := $(strip $(LOCAL_NDK_STL_VARIANT))
103 ifeq (,$(LOCAL_NDK_STL_VARIANT))
104 LOCAL_NDK_STL_VARIANT := system
106 ifneq (1,$(words $(filter system stlport_static stlport_shared c++_static c++_shared gnustl_static, $(LOCAL_NDK_STL_VARIANT))))
107 $(error $(LOCAL_PATH): Unknown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT))
109 ifeq (system,$(LOCAL_NDK_STL_VARIANT))
110 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/system/include
111 # for "system" variant, the shared library exists in the system library and -lstdc++ is added by default.
112 else # LOCAL_NDK_STL_VARIANT is not system
113 ifneq (,$(filter stlport_%, $(LOCAL_NDK_STL_VARIANT)))
114 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/stlport/stlport
115 ifeq (stlport_static,$(LOCAL_NDK_STL_VARIANT))
116 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(my_cpu_variant)/libstlport_static.a
118 my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(my_cpu_variant)/libstlport_shared.so
119 my_ndk_stl_shared_lib := -lstlport_shared
121 else # LOCAL_NDK_STL_VARIANT is not stlport_* either
122 ifneq (,$(filter c++_%, $(LOCAL_NDK_STL_VARIANT)))
123 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/llvm-libc++/libcxx/include \
124 $(my_ndk_source_root)/cxx-stl/llvm-libc++/gabi++/include \
125 $(my_ndk_source_root)/android/support/include
126 ifeq (c++_static,$(LOCAL_NDK_STL_VARIANT))
127 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/llvm-libc++/libs/$(my_cpu_variant)/libc++_static.a
129 my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/llvm-libc++/libs/$(my_cpu_variant)/libc++_shared.so
130 my_ndk_stl_shared_lib := -lc++_shared
132 my_ndk_stl_cppflags := -std=c++11
134 # LOCAL_NDK_STL_VARIANT is gnustl_static
135 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/$($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_GCC_VERSION)/libs/$(my_cpu_variant)/include \
136 $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/$($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_GCC_VERSION)/include
137 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/$($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_GCC_VERSION)/libs/$(my_cpu_variant)/libgnustl_static.a
143 # MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
144 # all code is position independent, and then those warnings get promoted to
147 ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES)
154 my_src_files += $(LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SRC_FILES_$(my_32_64_bit_suffix))
155 my_shared_libraries += $(LOCAL_SHARED_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SHARED_LIBRARIES_$(my_32_64_bit_suffix))
156 my_cflags += $(LOCAL_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CFLAGS_$(my_32_64_bit_suffix))
157 my_cppflags += $(LOCAL_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CPPFLAGS_$(my_32_64_bit_suffix))
158 my_ldflags += $(LOCAL_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_LDFLAGS_$(my_32_64_bit_suffix))
159 my_asflags += $(LOCAL_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_ASFLAGS_$(my_32_64_bit_suffix))
160 my_c_includes += $(LOCAL_C_INCLUDES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_C_INCLUDES_$(my_32_64_bit_suffix))
161 my_generated_sources += $(LOCAL_GENERATED_SOURCES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_GENERATED_SOURCES_$(my_32_64_bit_suffix))
163 my_clang := $(strip $(LOCAL_CLANG))
164 ifdef LOCAL_CLANG_$(my_32_64_bit_suffix)
165 my_clang := $(strip $(LOCAL_CLANG_$(my_32_64_bit_suffix)))
167 ifdef LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
168 my_clang := $(strip $(LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
171 # clang is enabled by default for host builds
172 # enable it unless we've specifically disabled clang above
173 ifdef LOCAL_IS_HOST_MODULE
174 ifneq ($(HOST_OS),windows)
181 # Add option to make clang the default for device build
182 ifeq ($(USE_CLANG_PLATFORM_BUILD),true)
188 # arch-specific static libraries go first so that generic ones can depend on them
189 my_static_libraries := $(LOCAL_STATIC_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_STATIC_LIBRARIES_$(my_32_64_bit_suffix)) $(my_static_libraries)
190 my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_WHOLE_STATIC_LIBRARIES_$(my_32_64_bit_suffix)) $(my_whole_static_libraries)
192 my_cflags := $(filter-out $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)GLOBAL_UNSUPPORTED_CFLAGS),$(my_cflags))
194 include $(BUILD_SYSTEM)/cxx_stl_setup.mk
196 # Add static HAL libraries
197 ifdef LOCAL_HAL_STATIC_LIBRARIES
198 $(foreach lib, $(LOCAL_HAL_STATIC_LIBRARIES), \
199 $(eval b_lib := $(filter $(lib).%,$(BOARD_HAL_STATIC_LIBRARIES)))\
200 $(if $(b_lib), $(eval my_static_libraries += $(b_lib)),\
201 $(eval my_static_libraries += $(lib).default)))
205 include $(BUILD_SYSTEM)/config_sanitizers.mk
207 ifeq ($(strip $($(LOCAL_2ND_ARCH_VAR_PREFIX)WITHOUT_$(my_prefix)CLANG)),true)
211 # Add in libcompiler_rt for all regular device builds
212 ifeq (,$(LOCAL_SDK_VERSION)$(WITHOUT_LIBCOMPILER_RT))
213 my_static_libraries += $(COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES)
216 ####################################################
217 ## Add FDO flags if FDO is turned on and supported
218 ## Please note that we will do option filtering during FDO build.
219 ## i.e. Os->O2, remove -fno-early-inline and -finline-limit.
220 ##################################################################
222 ifneq ($(filter true always, $(LOCAL_FDO_SUPPORT)),)
223 ifeq ($(BUILD_FDO_INSTRUMENT),true)
224 my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_CFLAGS)
225 my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_LDFLAGS)
227 else ifneq ($(filter true,$(BUILD_FDO_OPTIMIZE))$(filter always,$(LOCAL_FDO_SUPPORT)),)
228 my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_OPTIMIZE_CFLAGS)
231 # Disable ccache (or other compiler wrapper).
236 ###########################################################
237 ## Explicitly declare assembly-only __ASSEMBLY__ macro for
239 ###########################################################
240 my_asflags += -D__ASSEMBLY__
243 ###########################################################
244 ## Define PRIVATE_ variables from global vars
245 ###########################################################
246 ifndef LOCAL_IS_HOST_MODULE
247 ifdef LOCAL_SDK_VERSION
248 my_target_project_includes :=
249 my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_sysroot_include)
250 my_target_global_cppflags := $(my_ndk_stl_cppflags)
252 my_target_project_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PROJECT_INCLUDES)
253 my_target_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_C_INCLUDES)
254 my_target_global_cppflags :=
255 endif # LOCAL_SDK_VERSION
257 ifeq ($(my_clang),true)
258 my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CFLAGS)
259 my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CONLYFLAGS)
260 my_target_global_cppflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CPPFLAGS)
261 my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_LDFLAGS)
263 my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CFLAGS)
264 my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CONLYFLAGS)
265 my_target_global_cppflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CPPFLAGS)
266 my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LDFLAGS)
269 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes)
270 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes)
271 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
272 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CONLYFLAGS := $(my_target_global_conlyflags)
273 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags)
274 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
276 else # LOCAL_IS_HOST_MODULE
278 ifeq ($(my_clang),true)
279 my_host_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_HOST_GLOBAL_CFLAGS)
280 my_host_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_HOST_GLOBAL_CONLYFLAGS)
281 my_host_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_HOST_GLOBAL_CPPFLAGS)
282 my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_HOST_GLOBAL_LDFLAGS)
283 my_host_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_C_INCLUDES)
285 my_host_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_CFLAGS)
286 my_host_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_CONLYFLAGS)
287 my_host_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_CPPFLAGS)
288 my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_LDFLAGS)
289 my_host_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_C_INCLUDES)
292 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_C_INCLUDES := $(my_host_c_includes)
293 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CFLAGS := $(my_host_global_cflags)
294 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CONLYFLAGS := $(my_host_global_conlyflags)
295 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CPPFLAGS := $(my_host_global_cppflags)
296 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_LDFLAGS := $(my_host_global_ldflags)
297 endif # LOCAL_IS_HOST_MODULE
299 # To enable coverage for a given module, set LOCAL_NATIVE_COVERAGE=true and
300 # build with NATIVE_COVERAGE=true in your enviornment. Note that the build
301 # system is not sensitive to changes to NATIVE_COVERAGE, so you should do a
302 # clean build of your module after toggling it.
303 ifeq ($(NATIVE_COVERAGE),true)
304 ifeq ($(my_native_coverage),true)
305 # Note that clang coverage doesn't play nicely with acov out of the box.
306 # Clang apparently generates .gcno files that aren't compatible with
307 # gcov-4.8. This can be solved by installing gcc-4.6 and invoking lcov
308 # with `--gcov-tool /usr/bin/gcov-4.6`.
310 # http://stackoverflow.com/questions/17758126/clang-code-coverage-invalid-output
311 my_cflags += --coverage -O0
312 my_ldflags += --coverage
315 my_native_coverage := false
318 ###########################################################
319 ## Define PRIVATE_ variables used by multiple module types
320 ###########################################################
321 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
322 $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
324 ifeq ($(strip $(WITH_SYNTAX_CHECK)),)
325 LOCAL_NO_SYNTAX_CHECK := true
328 ifeq ($(strip $(WITH_STATIC_ANALYZER)),)
329 LOCAL_NO_STATIC_ANALYZER := true
332 ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
333 my_syntax_arch := host
335 my_syntax_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
338 ifeq ($(strip $(my_cc)),)
339 ifeq ($(my_clang),true)
342 my_cc := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)CC)
344 my_cc := $(my_cc_wrapper) $(my_cc)
346 ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
347 my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer $(my_syntax_arch) "$(my_cc)"
349 ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
350 my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-syntax $(my_syntax_arch) "$(my_cc)"
353 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(my_cc)
355 ifeq ($(strip $(my_cxx)),)
356 ifeq ($(my_clang),true)
357 my_cxx := $(CLANG_CXX)
359 my_cxx := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)CXX)
361 my_cxx := $(my_cxx_wrapper) $(my_cxx)
363 ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
364 my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-analyzer $(my_syntax_arch) "$(my_cxx)"
366 ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
367 my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-syntax $(my_syntax_arch) "$(my_cxx)"
370 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(my_cxx)
371 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLANG := $(my_clang)
373 # TODO: support a mix of standard extensions so that this isn't necessary
374 LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
375 ifeq ($(LOCAL_CPP_EXTENSION),)
376 LOCAL_CPP_EXTENSION := .cpp
378 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION)
380 # Certain modules like libdl have to have symbols resolved at runtime and blow
381 # up if --no-undefined is passed to the linker.
382 ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
383 ifeq ($(my_allow_undefined_symbols),)
384 my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)NO_UNDEFINED_LDFLAGS)
388 ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES))
389 $(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true
391 $(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES :=
394 ###########################################################
395 ## Define arm-vs-thumb-mode flags.
396 ###########################################################
397 LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
398 ifeq ($($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH),arm)
399 arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
400 normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
402 # Read the values from something like TARGET_arm_CFLAGS or
403 # TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't
404 # actually used (although they are usually empty).
405 arm_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(arm_objects_mode)_CFLAGS)
406 normal_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(normal_objects_mode)_CFLAGS)
407 ifeq ($(my_clang),true)
408 arm_objects_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(arm_objects_cflags))
409 normal_objects_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(normal_objects_cflags))
414 normal_objects_mode :=
415 arm_objects_cflags :=
416 normal_objects_cflags :=
419 ###########################################################
420 ## Define per-module debugging flags. Users can turn on
421 ## debugging for a particular module by setting DEBUG_MODULE_ModuleName
422 ## to a non-empty value in their environment or buildspec.mk,
423 ## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
424 ## debug flags that they want to use.
425 ###########################################################
426 ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
427 debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
432 ####################################################
433 ## Compile RenderScript with reflected C++
434 ####################################################
436 renderscript_sources := $(filter %.rs %.fs,$(my_src_files))
438 ifneq (,$(renderscript_sources))
440 renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
441 RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp
442 renderscript_intermediate := $(intermediates)/renderscript
444 ifeq ($(LOCAL_RENDERSCRIPT_CC),)
445 LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
448 # Turn on all warnings and warnings as errors for RS compiles.
449 # This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
450 renderscript_flags := -Wall -Werror
451 renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
453 renderscript_flags += -m$(my_32_64_bit_suffix)
455 renderscript_includes := \
456 $(TOPDIR)external/clang/lib/Headers \
457 $(TOPDIR)frameworks/rs/scriptc \
458 $(LOCAL_RENDERSCRIPT_INCLUDES)
460 ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
461 renderscript_includes := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
464 bc_dep_files := $(addprefix $(renderscript_intermediate)/, \
465 $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources)))))
467 $(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(renderscript_includes)
468 $(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
469 $(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
470 $(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
471 $(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate)
472 $(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files)
473 $(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
474 $(transform-renderscripts-to-cpp-and-bc)
476 # include the dependency files (.d/.P) generated by llvm-rs-cc.
477 -include $(bc_dep_files:%.d=%.P)
479 LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
481 rs_generated_cpps := $(addprefix \
482 $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rs,%.cpp, \
483 $(notdir $(renderscript_sources)))))
485 # This is just a dummy rule to make sure gmake doesn't skip updating the dependents.
486 $(rs_generated_cpps) : $(RenderScript_file_stamp)
487 @echo "Updated RS generated cpp file $@."
490 my_c_includes += $(renderscript_intermediate)
491 my_generated_sources += $(rs_generated_cpps)
496 ###########################################################
497 ## Stuff source generated from one-off tools
498 ###########################################################
499 $(my_generated_sources): PRIVATE_MODULE := $(my_register_name)
501 my_gen_sources_copy := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(filter $(generated_sources_dir)/%,$(my_generated_sources)))
503 $(my_gen_sources_copy): $(intermediates)/% : $(generated_sources_dir)/% | $(ACP)
505 $(copy-file-to-target)
507 my_generated_sources := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(my_generated_sources))
509 ALL_GENERATED_SOURCES += $(my_generated_sources)
511 ###########################################################
512 ## Compile the .proto files to .cc (or .c) and then to .o
513 ###########################################################
514 proto_sources := $(filter %.proto,$(my_src_files))
515 proto_generated_objects :=
516 proto_generated_headers :=
517 ifneq ($(proto_sources),)
518 proto_generated_sources_dir := $(generated_sources_dir)/proto
519 proto_generated_obj_dir := $(intermediates)/proto
521 ifneq (,$(filter nanopb-c nanopb-c-enable_malloc, $(LOCAL_PROTOC_OPTIMIZE_TYPE)))
522 my_proto_source_suffix := .c
523 my_proto_c_includes := external/nanopb-c
524 my_protoc_flags := --nanopb_out=$(proto_generated_sources_dir) \
525 --plugin=external/nanopb-c/generator/protoc-gen-nanopb
527 my_proto_source_suffix := .cc
528 my_proto_c_includes := external/protobuf/src
529 my_cflags += -DGOOGLE_PROTOBUF_NO_RTTI
530 my_protoc_flags := --cpp_out=$(proto_generated_sources_dir)
532 my_proto_c_includes += $(proto_generated_sources_dir)
534 proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
535 proto_generated_sources := $(addprefix $(proto_generated_sources_dir)/, \
536 $(patsubst %.proto,%.pb$(my_proto_source_suffix),$(proto_sources_fullpath)))
537 proto_generated_headers := $(patsubst %.pb$(my_proto_source_suffix),%.pb.h, $(proto_generated_sources))
538 proto_generated_objects := $(addprefix $(proto_generated_obj_dir)/, \
539 $(patsubst %.proto,%.pb.o,$(proto_sources_fullpath)))
541 # Ensure the transform-proto-to-cc rule is only defined once in multilib build.
542 ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined
543 $(proto_generated_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
544 $(proto_generated_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) $(my_protoc_flags)
545 $(proto_generated_sources): $(proto_generated_sources_dir)/%.pb$(my_proto_source_suffix): %.proto $(PROTOC)
546 $(transform-proto-to-cc)
548 # This is just a dummy rule to make sure gmake doesn't skip updating the dependents.
549 $(proto_generated_headers): $(proto_generated_sources_dir)/%.pb.h: $(proto_generated_sources_dir)/%.pb$(my_proto_source_suffix)
550 @echo "Updated header file $@."
553 $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined := true
554 endif # transform-proto-to-cc rule included only once
556 $(proto_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
557 $(proto_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
558 $(proto_generated_objects): $(proto_generated_obj_dir)/%.o: $(proto_generated_sources_dir)/%$(my_proto_source_suffix) $(proto_generated_headers)
559 ifeq ($(my_proto_source_suffix),.c)
560 $(transform-$(PRIVATE_HOST)c-to-o)
562 $(transform-$(PRIVATE_HOST)cpp-to-o)
564 -include $(proto_generated_objects:%.o=%.P)
566 my_c_includes += $(my_proto_c_includes)
567 # Auto-export the generated proto source dir.
568 my_export_c_include_dirs += $(my_proto_c_includes)
570 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc)
571 my_static_libraries += libprotobuf-c-nano-enable_malloc
572 else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c)
573 my_static_libraries += libprotobuf-c-nano
574 else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
575 ifdef LOCAL_SDK_VERSION
576 my_static_libraries += libprotobuf-cpp-full
578 my_shared_libraries += libprotobuf-cpp-full
581 ifdef LOCAL_SDK_VERSION
582 my_static_libraries += libprotobuf-cpp-lite
584 my_shared_libraries += libprotobuf-cpp-lite
587 endif # $(proto_sources) non-empty
589 ###########################################################
590 ## YACC: Compile .y and .yy files to .cpp and the to .o.
591 ###########################################################
593 y_yacc_sources := $(filter %.y,$(my_src_files))
594 y_yacc_cpps := $(addprefix \
595 $(intermediates)/,$(y_yacc_sources:.y=$(LOCAL_CPP_EXTENSION)))
597 yy_yacc_sources := $(filter %.yy,$(my_src_files))
598 yy_yacc_cpps := $(addprefix \
599 $(intermediates)/,$(yy_yacc_sources:.yy=$(LOCAL_CPP_EXTENSION)))
601 yacc_cpps := $(y_yacc_cpps) $(yy_yacc_cpps)
602 yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h)
603 yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o)
605 ifneq ($(strip $(y_yacc_cpps)),)
606 $(y_yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
607 $(TOPDIR)$(LOCAL_PATH)/%.y \
608 $(lex_cpps) $(my_additional_dependencies)
609 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
610 $(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
613 ifneq ($(strip $(yy_yacc_cpps)),)
614 $(yy_yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
615 $(TOPDIR)$(LOCAL_PATH)/%.yy \
616 $(lex_cpps) $(my_additional_dependencies)
617 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
618 $(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
621 ifneq ($(strip $(yacc_cpps)),)
622 $(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
623 $(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
624 $(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
625 $(transform-$(PRIVATE_HOST)cpp-to-o)
628 ###########################################################
629 ## LEX: Compile .l and .ll files to .cpp and then to .o.
630 ###########################################################
632 l_lex_sources := $(filter %.l,$(my_src_files))
633 l_lex_cpps := $(addprefix \
634 $(intermediates)/,$(l_lex_sources:.l=$(LOCAL_CPP_EXTENSION)))
636 ll_lex_sources := $(filter %.ll,$(my_src_files))
637 ll_lex_cpps := $(addprefix \
638 $(intermediates)/,$(ll_lex_sources:.ll=$(LOCAL_CPP_EXTENSION)))
640 lex_cpps := $(l_lex_cpps) $(ll_lex_cpps)
641 lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o)
643 ifneq ($(strip $(l_lex_cpps)),)
644 $(l_lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
645 $(TOPDIR)$(LOCAL_PATH)/%.l
646 $(transform-l-to-cpp)
649 ifneq ($(strip $(ll_lex_cpps)),)
650 $(ll_lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
651 $(TOPDIR)$(LOCAL_PATH)/%.ll
652 $(transform-l-to-cpp)
655 ifneq ($(strip $(lex_cpps)),)
656 $(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
657 $(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
658 $(lex_objects): $(intermediates)/%.o: \
659 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \
660 $(my_additional_dependencies) \
662 $(transform-$(PRIVATE_HOST)cpp-to-o)
665 ###########################################################
666 ## C++: Compile .cpp files to .o.
667 ###########################################################
669 # we also do this on host modules, even though
670 # it's not really arm, because there are files that are shared.
671 cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(my_src_files)))
672 dotdot_arm_sources := $(filter ../%,$(cpp_arm_sources))
673 cpp_arm_sources := $(filter-out ../%,$(cpp_arm_sources))
674 cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o))
676 # For source files starting with ../, we remove all the ../ in the object file path,
677 # to avoid object file escaping the intermediate directory.
678 dotdot_arm_objects :=
679 $(foreach s,$(dotdot_arm_sources),\
680 $(eval $(call compile-dotdot-cpp-file,$(s),\
681 $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\
682 dotdot_arm_objects)))
684 dotdot_sources := $(filter ../%$(LOCAL_CPP_EXTENSION),$(my_src_files))
686 $(foreach s,$(dotdot_sources),\
687 $(eval $(call compile-dotdot-cpp-file,$(s),\
688 $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\
691 cpp_normal_sources := $(filter-out ../%,$(filter %$(LOCAL_CPP_EXTENSION),$(my_src_files)))
692 cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
694 $(dotdot_arm_objects) $(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
695 $(dotdot_arm_objects) $(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
696 $(dotdot_objects) $(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
697 $(dotdot_objects) $(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
699 cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects)
701 ifneq ($(strip $(cpp_objects)),)
702 $(cpp_objects): $(intermediates)/%.o: \
703 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
704 $(yacc_cpps) $(proto_generated_headers) \
705 $(my_additional_dependencies)
706 $(transform-$(PRIVATE_HOST)cpp-to-o)
707 -include $(cpp_objects:%.o=%.P)
710 cpp_objects += $(dotdot_arm_objects) $(dotdot_objects)
712 ###########################################################
713 ## C++: Compile generated .cpp files to .o.
714 ###########################################################
716 gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(my_generated_sources))
717 gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
719 ifneq ($(strip $(gen_cpp_objects)),)
720 # Compile all generated files as thumb.
721 # TODO: support compiling certain generated files as arm.
722 $(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
723 $(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
724 $(gen_cpp_objects): $(intermediates)/%.o: \
725 $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) \
726 $(proto_generated_headers) \
727 $(my_additional_dependencies)
728 $(transform-$(PRIVATE_HOST)cpp-to-o)
729 -include $(gen_cpp_objects:%.o=%.P)
732 ###########################################################
733 ## S: Compile generated .S and .s files to .o.
734 ###########################################################
736 gen_S_sources := $(filter %.S,$(my_generated_sources))
737 gen_S_objects := $(gen_S_sources:%.S=%.o)
739 ifneq ($(strip $(gen_S_sources)),)
740 $(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \
741 $(my_additional_dependencies)
742 $(transform-$(PRIVATE_HOST)s-to-o)
743 -include $(gen_S_objects:%.o=%.P)
746 gen_s_sources := $(filter %.s,$(my_generated_sources))
747 gen_s_objects := $(gen_s_sources:%.s=%.o)
749 ifneq ($(strip $(gen_s_objects)),)
750 $(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \
751 $(my_additional_dependencies)
752 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
753 -include $(gen_s_objects:%.o=%.P)
756 gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
758 ###########################################################
759 ## o: Include generated .o files in output.
760 ###########################################################
762 gen_o_objects := $(filter %.o,$(my_generated_sources))
764 ###########################################################
765 ## C: Compile .c files to .o.
766 ###########################################################
768 c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(my_src_files)))
769 dotdot_arm_sources := $(filter ../%,$(c_arm_sources))
770 c_arm_sources := $(filter-out ../%,$(c_arm_sources))
771 c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o))
773 # For source files starting with ../, we remove all the ../ in the object file path,
774 # to avoid object file escaping the intermediate directory.
775 dotdot_arm_objects :=
776 $(foreach s,$(dotdot_arm_sources),\
777 $(eval $(call compile-dotdot-c-file,$(s),\
778 $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\
779 dotdot_arm_objects)))
781 dotdot_sources := $(filter ../%.c, $(my_src_files))
783 $(foreach s, $(dotdot_sources),\
784 $(eval $(call compile-dotdot-c-file,$(s),\
785 $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\
788 c_normal_sources := $(filter-out ../%,$(filter %.c,$(my_src_files)))
789 c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
791 $(dotdot_arm_objects) $(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
792 $(dotdot_arm_objects) $(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
793 $(dotdot_objects) $(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
794 $(dotdot_objects) $(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
796 c_objects := $(c_arm_objects) $(c_normal_objects)
798 ifneq ($(strip $(c_objects)),)
799 $(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \
800 $(my_additional_dependencies)
801 $(transform-$(PRIVATE_HOST)c-to-o)
802 -include $(c_objects:%.o=%.P)
805 c_objects += $(dotdot_arm_objects) $(dotdot_objects)
807 ###########################################################
808 ## C: Compile generated .c files to .o.
809 ###########################################################
811 gen_c_sources := $(filter %.c,$(my_generated_sources))
812 gen_c_objects := $(gen_c_sources:%.c=%.o)
814 ifneq ($(strip $(gen_c_objects)),)
815 # Compile all generated files as thumb.
816 # TODO: support compiling certain generated files as arm.
817 $(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
818 $(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
819 $(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \
820 $(my_additional_dependencies)
821 $(transform-$(PRIVATE_HOST)c-to-o)
822 -include $(gen_c_objects:%.o=%.P)
825 ###########################################################
826 ## ObjC: Compile .m files to .o
827 ###########################################################
829 objc_sources := $(filter %.m,$(my_src_files))
830 objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
832 ifneq ($(strip $(objc_objects)),)
833 $(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) \
834 $(my_additional_dependencies)
835 $(transform-$(PRIVATE_HOST)m-to-o)
836 -include $(objc_objects:%.o=%.P)
839 ###########################################################
840 ## AS: Compile .S files to .o.
841 ###########################################################
843 asm_sources_S := $(filter %.S,$(my_src_files))
844 dotdot_sources := $(filter ../%,$(asm_sources_S))
845 asm_sources_S := $(filter-out ../%,$(asm_sources_S))
846 asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
849 $(foreach s,$(dotdot_sources),\
850 $(eval $(call compile-dotdot-s-file,$(s),\
851 $(my_additional_dependencies),\
854 ifneq ($(strip $(asm_objects_S)),)
855 $(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \
856 $(my_additional_dependencies)
857 $(transform-$(PRIVATE_HOST)s-to-o)
858 -include $(asm_objects_S:%.o=%.P)
861 asm_sources_s := $(filter %.s,$(my_src_files))
862 dotdot_sources := $(filter ../%,$(asm_sources_s))
863 asm_sources_s := $(filter-out ../%,$(asm_sources_s))
864 asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
867 $(foreach s,$(dotdot_sources),\
868 $(eval $(call compile-dotdot-s-file-no-deps,$(s),\
869 $(my_additional_dependencies),\
872 ifneq ($(strip $(asm_objects_s)),)
873 $(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \
874 $(my_additional_dependencies)
875 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
878 asm_objects := $(dotdot_objects_S) $(dotdot_objects_s) $(asm_objects_S) $(asm_objects_s)
881 # .asm for x86/x86_64 needs to be compiled with yasm.
882 asm_sources_asm := $(filter %.asm,$(my_src_files))
883 ifneq ($(strip $(asm_sources_asm)),)
884 asm_objects_asm := $(addprefix $(intermediates)/,$(asm_sources_asm:.asm=.o))
885 $(asm_objects_asm): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.asm \
886 $(my_additional_dependencies)
887 $(transform-asm-to-o)
889 asm_objects += $(asm_objects_asm)
893 ##########################################################
894 ## Set up installed module dependency
895 ## We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for
896 ## they may cusomize their install path with LOCAL_MODULE_PATH
897 ##########################################################
898 # Get the list of INSTALLED libraries as module names.
899 ifdef LOCAL_SDK_VERSION
900 installed_shared_library_module_names := \
901 $(my_shared_libraries)
903 installed_shared_library_module_names := \
904 $(my_shared_libraries) $(my_system_shared_libraries)
907 # The real dependency will be added after all Android.mks are loaded and the install paths
908 # of the shared libraries are determined.
909 ifdef LOCAL_INSTALLED_MODULE
910 ifdef installed_shared_library_module_names
911 $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
912 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(sort $(installed_shared_library_module_names)))
917 ####################################################
919 ####################################################
920 import_includes := $(intermediates)/import_includes
921 import_includes_deps := $(strip \
922 $(foreach l, $(installed_shared_library_module_names), \
923 $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/export_includes) \
924 $(foreach l, $(my_static_libraries) $(my_whole_static_libraries), \
925 $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/export_includes))
926 $(import_includes): PRIVATE_IMPORT_EXPORT_INCLUDES := $(import_includes_deps)
927 $(import_includes) : $(LOCAL_MODULE_MAKEFILE) $(import_includes_deps)
928 @echo Import includes file: $@
929 $(hide) mkdir -p $(dir $@) && rm -f $@
930 ifdef import_includes_deps
931 $(hide) for f in $(PRIVATE_IMPORT_EXPORT_INCLUDES); do \
938 ###########################################################
939 ## Common object handling.
940 ###########################################################
942 # some rules depend on asm_objects being first. If your code depends on
943 # being first, it's reasonable to require it to be assembly
954 $(proto_generated_objects) \
955 $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
957 all_objects := $(normal_objects) $(gen_o_objects)
959 my_c_includes += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(generated_sources_dir)
961 ifndef LOCAL_SDK_VERSION
962 my_c_includes += $(JNI_H_INCLUDE)
965 # all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES;
966 # use normal_objects here to avoid creating circular dependencies. This assumes
967 # that custom build rules which generate .o files don't consume other generated
968 # sources as input (or if they do they take care of that dependency themselves).
969 $(normal_objects) : | $(my_generated_sources)
970 $(all_objects) : | $(import_includes)
971 ALL_C_CPP_ETC_OBJECTS += $(all_objects)
974 ###########################################################
975 # Standard library handling.
976 ###########################################################
978 ###########################################################
979 # The list of libraries that this module will link against are in
980 # these variables. Each is a list of bare module names like "libc libm".
982 # LOCAL_SHARED_LIBRARIES
983 # LOCAL_STATIC_LIBRARIES
984 # LOCAL_WHOLE_STATIC_LIBRARIES
986 # We need to convert the bare names into the dependencies that
987 # we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
988 # LOCAL_BUILT_MODULE should depend on the BUILT versions of the
989 # libraries, so that simply building this module doesn't force
990 # an install of a library. Similarly, LOCAL_INSTALLED_MODULE
991 # should depend on the INSTALLED versions of the libraries so
992 # that they get installed when this module does.
993 ###########################################################
995 # WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
996 # module without leaving anything out, which is useful for turning
997 # a collection of .a files into a .so file. Linking against a
998 # normal STATIC_LIBRARY will only pull in code/symbols that are
999 # referenced by the module. (see gcc/ld's --whole-archive option)
1000 ###########################################################
1002 # Get the list of BUILT libraries, which are under
1003 # various intermediates directories.
1004 so_suffix := $($(my_prefix)SHLIB_SUFFIX)
1005 a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
1007 ifdef LOCAL_SDK_VERSION
1008 built_shared_libraries := \
1009 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
1010 $(addsuffix $(so_suffix), \
1011 $(my_shared_libraries)))
1013 # Add the NDK libraries to the built module dependency
1014 my_system_shared_libraries_fullpath := \
1015 $(my_ndk_stl_shared_lib_fullpath) \
1016 $(addprefix $(my_ndk_sysroot_lib)/, \
1017 $(addsuffix $(so_suffix), $(my_system_shared_libraries)))
1019 built_shared_libraries += $(my_system_shared_libraries_fullpath)
1021 built_shared_libraries := \
1022 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
1023 $(addsuffix $(so_suffix), \
1024 $(installed_shared_library_module_names)))
1027 built_static_libraries := \
1028 $(foreach lib,$(my_static_libraries), \
1029 $(call intermediates-dir-for, \
1030 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/$(lib)$(a_suffix))
1032 ifdef LOCAL_SDK_VERSION
1033 built_static_libraries += $(my_ndk_stl_static_lib)
1036 built_whole_libraries := \
1037 $(foreach lib,$(my_whole_static_libraries), \
1038 $(call intermediates-dir-for, \
1039 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/$(lib)$(a_suffix))
1041 # We don't care about installed static libraries, since the
1042 # libraries have already been linked into the module at that point.
1043 # We do, however, care about the NOTICE files for any static
1044 # libraries that we use. (see notice_files.mk)
1046 installed_static_library_notice_file_targets := \
1047 $(foreach lib,$(my_static_libraries) $(my_whole_static_libraries), \
1048 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib))
1050 # Default is -fno-rtti.
1051 ifeq ($(strip $(LOCAL_RTTI_FLAG)),)
1052 LOCAL_RTTI_FLAG := -fno-rtti
1055 ###########################################################
1056 # Rule-specific variable definitions
1057 ###########################################################
1059 ifeq ($(my_clang),true)
1060 my_cflags += $(LOCAL_CLANG_CFLAGS)
1061 my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS)
1062 my_cppflags += $(LOCAL_CLANG_CPPFLAGS)
1063 my_asflags += $(LOCAL_CLANG_ASFLAGS)
1064 my_ldflags += $(LOCAL_CLANG_LDFLAGS)
1065 my_cflags += $(LOCAL_CLANG_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CFLAGS_$(my_32_64_bit_suffix))
1066 my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CONLYFLAGS_$(my_32_64_bit_suffix))
1067 my_cppflags += $(LOCAL_CLANG_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CPPFLAGS_$(my_32_64_bit_suffix))
1068 my_ldflags += $(LOCAL_CLANG_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_LDFLAGS_$(my_32_64_bit_suffix))
1069 my_asflags += $(LOCAL_CLANG_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_ASFLAGS_$(my_32_64_bit_suffix))
1070 my_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_cflags))
1071 my_cppflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_cppflags))
1072 my_asflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_asflags))
1073 my_ldflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_ldflags))
1076 ifeq ($(my_fdo_build), true)
1077 my_cflags := $(patsubst -Os,-O2,$(my_cflags))
1078 fdo_incompatible_flags := -fno-early-inlining -finline-limit=%
1079 my_cflags := $(filter-out $(fdo_incompatible_flags),$(my_cflags))
1082 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
1083 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(my_asflags)
1084 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(my_conlyflags)
1085 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(my_cflags)
1086 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(my_cppflags)
1087 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
1088 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
1089 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(my_c_includes)
1090 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes)
1091 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(my_ldflags)
1092 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(my_ldlibs)
1093 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_CRT := $(strip $(LOCAL_NO_CRT) $(LOCAL_NO_CRT_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
1095 # this is really the way to get the files onto the command line instead
1096 # of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
1097 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
1098 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
1099 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
1100 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects)
1102 ###########################################################
1103 # Define library dependencies.
1104 ###########################################################
1105 # all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
1107 $(built_shared_libraries) \
1108 $(built_static_libraries) \
1109 $(built_whole_libraries)
1111 # Also depend on the notice files for any static libraries that
1112 # are linked into this module. This will force them to be installed
1113 # when this module is.
1114 $(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets)
1116 ###########################################################
1118 ###########################################################
1119 export_includes := $(intermediates)/export_includes
1120 $(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(my_export_c_include_dirs)
1121 # Make sure .pb.h are already generated before any dependent source files get compiled.
1122 $(export_includes) : $(LOCAL_MODULE_MAKEFILE) $(proto_generated_headers)
1123 @echo Export includes file: $< -- $@
1124 $(hide) mkdir -p $(dir $@) && rm -f $@
1125 ifdef my_export_c_include_dirs
1126 $(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \
1127 echo "-I $$d" >> $@; \
1133 # Make sure export_includes gets generated when you are running mm/mmm
1134 $(LOCAL_BUILT_MODULE) : | $(export_includes)