blob: adc2f44661d7dc85cce2263a0b32b238b93dac05 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001###########################################################
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
Ying Wang1a081002010-07-13 14:55:47 -07008my_ndk_version_root :=
Ying Wang848020f2012-08-14 10:13:16 -07009ifdef LOCAL_SDK_VERSION
Ying Wangfe1bfe72012-08-14 11:08:03 -070010 ifdef LOCAL_NDK_VERSION
11 $(error $(LOCAL_PATH): LOCAL_NDK_VERSION is now retired.)
12 endif
Ying Wang1a081002010-07-13 14:55:47 -070013 ifdef LOCAL_IS_HOST_MODULE
Ian Rogers76a6dc32012-10-01 16:36:23 -070014 $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
Ying Wang1a081002010-07-13 14:55:47 -070015 endif
Ying Wang848020f2012-08-14 10:13:16 -070016 my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources
Ying Wang6ef65192014-01-15 16:02:16 -080017 my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
Ying Wangcce4c972011-03-03 18:53:53 -080018
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))))
Ying Wang848020f2012-08-14 10:13:16 -070029 $(error $(LOCAL_PATH): Unknown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT))
Ying Wangcce4c972011-03-03 18:53:53 -080030 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))
Ying Wang6ef65192014-01-15 16:02:16 -080038 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libstlport_static.a
Ying Wangcce4c972011-03-03 18:53:53 -080039 else
Ying Wang6ef65192014-01-15 16:02:16 -080040 my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libstlport_shared.so
Ying Wangcce4c972011-03-03 18:53:53 -080041 my_ndk_stl_shared_lib := -lstlport_shared
42 endif
43 else
44 # LOCAL_NDK_STL_VARIANT is gnustl_static
Ying Wang6ef65192014-01-15 16:02:16 -080045 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/include \
Ying Wangd9020c22011-09-07 14:31:47 -070046 $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/include
Ying Wang6ef65192014-01-15 16:02:16 -080047 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libgnustl_static.a
Ying Wangcce4c972011-03-03 18:53:53 -080048 endif
49 endif
Ying Wang1a081002010-07-13 14:55:47 -070050endif
51
Ying Wang704c0c92011-09-15 13:50:52 -070052##################################################
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.
59ifdef LOCAL_IS_HOST_MODULE
60 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
61 LOCAL_SYSTEM_SHARED_LIBRARIES :=
62 endif
63else
64 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
65 LOCAL_SYSTEM_SHARED_LIBRARIES := $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES)
66 endif
67endif
68
Ying Wang848020f2012-08-14 10:13:16 -070069ifdef LOCAL_SDK_VERSION
Ying Wang704c0c92011-09-15 13:50:52 -070070 # Get the list of INSTALLED libraries as module names.
Ian Rogers76a6dc32012-10-01 16:36:23 -070071 # We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for
Ying Wang704c0c92011-09-15 13:50:52 -070072 # they may cusomize their install path with LOCAL_MODULE_PATH
73 installed_shared_library_module_names := \
74 $(LOCAL_SHARED_LIBRARIES)
75else
76 installed_shared_library_module_names := \
77 $(LOCAL_SYSTEM_SHARED_LIBRARIES) $(LOCAL_SHARED_LIBRARIES)
78endif
Ying Wang9485a572013-02-22 14:32:30 -080079installed_shared_library_module_names := $(sort $(installed_shared_library_module_names))
Ying Wang704c0c92011-09-15 13:50:52 -070080
The Android Open Source Project88b60792009-03-03 19:28:42 -080081#######################################
82include $(BUILD_SYSTEM)/base_rules.mk
83#######################################
Evgeniy Stepanov6cc9c062012-03-30 12:15:12 +040084
Ying Wang6ef65192014-01-15 16:02:16 -080085# The following LOCAL_ variables will be modified in this file.
86# Because the same LOCAL_ variables may be used to define modules for both 1st arch and 2nd arch,
87# we can't modify them in place.
Ying Wangb8e01852014-01-23 15:09:04 -080088my_src_files := $(LOCAL_SRC_FILES) $(LOCAL_SRC_FILES_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
Ying Wang6ef65192014-01-15 16:02:16 -080089my_static_libraries := $(LOCAL_STATIC_LIBRARIES)
90my_shared_libraries := $(LOCAL_SHARED_LIBRARIES)
Ying Wangb8e01852014-01-23 15:09:04 -080091my_cflags := $(LOCAL_CFLAGS) $(LOCAL_CFLAGS_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
Ying Wang6ef65192014-01-15 16:02:16 -080092my_cppflags := $(LOCAL_CPPFLAGS)
Ying Wangb8e01852014-01-23 15:09:04 -080093my_ldflags := $(LOCAL_LDFLAGS) $(LOCAL_LDFLAGS_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
94my_asflags := $(LOCAL_ASFLAGS) $(LOCAL_ASFLAGS_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
Ying Wang6ef65192014-01-15 16:02:16 -080095my_cc := $(LOCAL_CC)
96my_cxx := $(LOCAL_CXX)
Ying Wangdbdafdb2014-01-27 10:27:19 -080097my_c_includes := $(LOCAL_C_INCLUDES) $(LOCAL_C_INCLUDES_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
Ying Wang6ef65192014-01-15 16:02:16 -080098my_generated_sources := $(LOCAL_GENERATED_SOURCES)
99
Colin Cross8f47fc32014-01-27 17:34:21 -0800100my_cflags := $(filter-out $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_UNSUPPORTED_CFLAGS),$(my_cflags))
Ying Wang6ef65192014-01-15 16:02:16 -0800101
Ying Wang9485a572013-02-22 14:32:30 -0800102# The real dependency will be added after all Android.mks are loaded and the install paths
103# of the shared libraries are determined.
104ifdef LOCAL_INSTALLED_MODULE
105ifdef installed_shared_library_module_names
Ying Wang6ef65192014-01-15 16:02:16 -0800106$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
107 $(LOCAL_MODULE):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(installed_shared_library_module_names))
Ying Wang9485a572013-02-22 14:32:30 -0800108endif
109endif
110
Ying Wang285045b2013-08-13 12:35:10 -0700111# Add static HAL libraries
112ifdef LOCAL_HAL_STATIC_LIBRARIES
113$(foreach lib, $(LOCAL_HAL_STATIC_LIBRARIES), \
114 $(eval b_lib := $(filter $(lib).%,$(BOARD_HAL_STATIC_LIBRARIES)))\
Ying Wang6ef65192014-01-15 16:02:16 -0800115 $(if $(b_lib), $(eval my_static_libraries += $(b_lib)),\
116 $(eval my_static_libraries += $(lib).default)))
Ying Wang285045b2013-08-13 12:35:10 -0700117b_lib :=
118endif
119
Evgeniy Stepanov6cc9c062012-03-30 12:15:12 +0400120ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),true)
121 LOCAL_CLANG := true
Ying Wang6ef65192014-01-15 16:02:16 -0800122 my_cflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS)
123 my_ldflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS)
124 my_shared_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES)
125 my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES)
Evgeniy Stepanov6cc9c062012-03-30 12:15:12 +0400126endif
127
Mike Lockwood051a1742013-06-14 10:52:50 -0700128ifeq ($(strip $(WITHOUT_CLANG)),true)
129 LOCAL_CLANG :=
130endif
131
Shih-wei Liaoc8dfc162013-01-27 01:45:59 -0800132# Add in libcompiler_rt for all regular device builds
Mike Lockwooddaf5e222012-10-18 10:17:47 -0700133ifeq (,$(LOCAL_SDK_VERSION)$(LOCAL_IS_HOST_MODULE)$(WITHOUT_LIBCOMPILER_RT))
Ying Wang6ef65192014-01-15 16:02:16 -0800134 my_static_libraries += $(COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES)
Stephen Hinesc72f3962012-06-11 14:53:34 -0700135endif
136
Ying Wangdfbe79b2012-03-22 11:26:22 -0700137my_compiler_dependencies :=
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400138ifeq ($(strip $(LOCAL_CLANG)),true)
Ying Wangdfbe79b2012-03-22 11:26:22 -0700139 my_compiler_dependencies := $(CLANG) $(CLANG_CXX)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400140endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800141
Jing Yu2dcc8062009-09-21 16:31:50 -0700142####################################################
143## Add FDO flags if FDO is turned on and supported
144####################################################
synergydev7c467422013-08-13 17:41:52 -0700145ifneq ($(strip $(LOCAL_FDO_SUPPORT)),)
synergydev4a605762013-08-05 02:44:37 -0700146 ifeq ($(strip $(LOCAL_IS_HOST_MODULE)),)
Ying Wang6ef65192014-01-15 16:02:16 -0800147 my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_CFLAGS)
148 my_cppflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_CFLAGS)
149 my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_CFLAGS)
synergydev4a605762013-08-05 02:44:37 -0700150 endif
Jing Yu2dcc8062009-09-21 16:31:50 -0700151endif
152
The Android Open Source Project88b60792009-03-03 19:28:42 -0800153###########################################################
Jim Huang20d1ba62010-10-14 16:15:56 +0800154## Explicitly declare assembly-only __ASSEMBLY__ macro for
155## assembly source
156###########################################################
Ying Wang6ef65192014-01-15 16:02:16 -0800157my_asflags += -D__ASSEMBLY__
Jim Huang20d1ba62010-10-14 16:15:56 +0800158
159###########################################################
Ying Wang1a081002010-07-13 14:55:47 -0700160## Define PRIVATE_ variables from global vars
161###########################################################
Ying Wang7fff9a12014-01-09 14:39:41 -0800162ifndef LOCAL_IS_HOST_MODULE
Ying Wang848020f2012-08-14 10:13:16 -0700163ifdef LOCAL_SDK_VERSION
Ying Wang1a081002010-07-13 14:55:47 -0700164my_target_project_includes :=
Evgeniy Stepanova7095e92012-03-30 12:18:52 +0400165my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_version_root)/usr/include
Ying Wang1a081002010-07-13 14:55:47 -0700166else
Ying Wang6ef65192014-01-15 16:02:16 -0800167my_target_project_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PROJECT_INCLUDES)
168my_target_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_C_INCLUDES)
Ying Wangf4723fa2013-08-15 11:01:10 -0700169endif # LOCAL_SDK_VERSION
170
171ifeq ($(LOCAL_CLANG),true)
Logan Chiene6f65432013-12-10 19:07:41 +0800172my_target_global_cflags := $(CLANG_TARGET_GLOBAL_CFLAGS)
173my_target_global_cppflags := $(CLANG_TARGET_GLOBAL_CPPFLAGS)
174my_target_global_ldflags := $(CLANG_TARGET_GLOBAL_LDFLAGS)
Ying Wangf4723fa2013-08-15 11:01:10 -0700175my_target_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES)
Ying Wangda4bf422012-08-16 16:45:01 -0700176else
Ying Wang6ef65192014-01-15 16:02:16 -0800177my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CFLAGS)
178my_target_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CPPFLAGS)
179my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LDFLAGS)
Ying Wangda4bf422012-08-16 16:45:01 -0700180endif # LOCAL_CLANG
Ying Wangda4bf422012-08-16 16:45:01 -0700181
Ying Wang1a081002010-07-13 14:55:47 -0700182$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes)
Evgeniy Stepanova7095e92012-03-30 12:18:52 +0400183$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes)
Ying Wang1a081002010-07-13 14:55:47 -0700184$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
Logan Chiene6f65432013-12-10 19:07:41 +0800185$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags)
186$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
187
Ying Wang7fff9a12014-01-09 14:39:41 -0800188else # LOCAL_IS_HOST_MODULE
189
Logan Chiene6f65432013-12-10 19:07:41 +0800190ifeq ($(LOCAL_CLANG),true)
191my_host_global_cflags := $(CLANG_HOST_GLOBAL_CFLAGS)
192my_host_global_cppflags := $(CLANG_HOST_GLOBAL_CPPFLAGS)
193my_host_global_ldflags := $(CLANG_HOST_GLOBAL_LDFLAGS)
194my_host_c_includes := $(HOST_C_INCLUDES) $(CLANG_CONFIG_EXTRA_HOST_C_INCLUDES)
195else
196my_host_global_cflags := $(HOST_GLOBAL_CFLAGS)
197my_host_global_cppflags := $(HOST_GLOBAL_CPPFLAGS)
198my_host_global_ldflags := $(HOST_GLOBAL_LDFLAGS)
199my_host_c_includes := $(HOST_C_INCLUDES)
200endif # LOCAL_CLANG
201
202$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_C_INCLUDES := $(my_host_c_includes)
203$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CFLAGS := $(my_host_global_cflags)
204$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CPPFLAGS := $(my_host_global_cppflags)
205$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_LDFLAGS := $(my_host_global_ldflags)
206endif # LOCAL_IS_HOST_MODULE
Ying Wang1a081002010-07-13 14:55:47 -0700207
208###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800209## Define PRIVATE_ variables used by multiple module types
210###########################################################
211$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700212 $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800213
Andrew Hsieh6cea59a2013-08-27 17:33:06 +0800214ifeq ($(strip $(WITH_SYNTAX_CHECK)),)
215 LOCAL_NO_SYNTAX_CHECK := true
216endif
217
Andrew Hsieh906cb782013-09-10 17:37:14 +0800218ifeq ($(strip $(WITH_STATIC_ANALYZER)),)
219 LOCAL_NO_STATIC_ANALYZER := true
220endif
221
Andrew Hsieh6cea59a2013-08-27 17:33:06 +0800222ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
223 my_syntax_arch := host
224else
Ying Wang6ef65192014-01-15 16:02:16 -0800225 my_syntax_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
Andrew Hsieh6cea59a2013-08-27 17:33:06 +0800226endif
227
Ying Wang6ef65192014-01-15 16:02:16 -0800228ifeq ($(strip $(my_cc)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400229 ifeq ($(strip $(LOCAL_CLANG)),true)
Ying Wang6ef65192014-01-15 16:02:16 -0800230 my_cc := $(CLANG)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400231 else
Ying Wang6ef65192014-01-15 16:02:16 -0800232 my_cc := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)CC)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400233 endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800234endif
Andrew Hsieh906cb782013-09-10 17:37:14 +0800235ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
Ying Wang6ef65192014-01-15 16:02:16 -0800236 my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer $(my_syntax_arch) "$(my_cc)"
Andrew Hsieh906cb782013-09-10 17:37:14 +0800237else
Andrew Hsieh6cea59a2013-08-27 17:33:06 +0800238ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
Ying Wang6ef65192014-01-15 16:02:16 -0800239 my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-syntax $(my_syntax_arch) "$(my_cc)"
Andrew Hsieh6cea59a2013-08-27 17:33:06 +0800240endif
Andrew Hsieh906cb782013-09-10 17:37:14 +0800241endif
Ying Wang6ef65192014-01-15 16:02:16 -0800242$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(my_cc)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800243
Ying Wang6ef65192014-01-15 16:02:16 -0800244ifeq ($(strip $(my_cxx)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400245 ifeq ($(strip $(LOCAL_CLANG)),true)
Ying Wang6ef65192014-01-15 16:02:16 -0800246 my_cxx := $(CLANG_CXX)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400247 else
Ying Wang6ef65192014-01-15 16:02:16 -0800248 my_cxx := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)CXX)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400249 endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800250endif
Andrew Hsieh906cb782013-09-10 17:37:14 +0800251ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
Ying Wang6ef65192014-01-15 16:02:16 -0800252 my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-analyzer $(my_syntax_arch) "$(my_cxx)"
Andrew Hsieh906cb782013-09-10 17:37:14 +0800253else
Andrew Hsieh6cea59a2013-08-27 17:33:06 +0800254ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
Ying Wang6ef65192014-01-15 16:02:16 -0800255 my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-syntax $(my_syntax_arch) "$(my_cxx)"
Andrew Hsieh6cea59a2013-08-27 17:33:06 +0800256endif
Andrew Hsieh906cb782013-09-10 17:37:14 +0800257endif
Ying Wang6ef65192014-01-15 16:02:16 -0800258$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(my_cxx)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800259
260# TODO: support a mix of standard extensions so that this isn't necessary
261LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
262ifeq ($(LOCAL_CPP_EXTENSION),)
263 LOCAL_CPP_EXTENSION := .cpp
264endif
265$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION)
266
267# Certain modules like libdl have to have symbols resolved at runtime and blow
268# up if --no-undefined is passed to the linker.
269ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
270ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),)
Ying Wang6ef65192014-01-15 16:02:16 -0800271 my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)NO_UNDEFINED_LDFLAGS)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800272endif
273endif
274
Ying Wangfcdabd42011-04-25 14:22:41 -0700275ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES))
276$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true
277else
278$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES :=
279endif
280
The Android Open Source Project88b60792009-03-03 19:28:42 -0800281###########################################################
282## Define arm-vs-thumb-mode flags.
283###########################################################
284LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
Colin Cross6e087a32014-01-22 17:36:05 -0800285ifeq ($(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH),arm)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800286arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
287normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
288
Dave Bort95282482009-04-23 18:44:55 -0700289# Read the values from something like TARGET_arm_CFLAGS or
290# TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't
291# actually used (although they are usually empty).
Ying Wang6ef65192014-01-15 16:02:16 -0800292arm_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(arm_objects_mode)_CFLAGS)
293normal_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(normal_objects_mode)_CFLAGS)
Logan Chiene6f65432013-12-10 19:07:41 +0800294ifeq ($(strip $(LOCAL_CLANG)),true)
295arm_objects_cflags := $(call convert-to-$(my_host)clang-flags,$(arm_objects_cflags))
296normal_objects_cflags := $(call convert-to-$(my_host)clang-flags,$(normal_objects_cflags))
Evgeniy Stepanovf50f4c52012-04-05 11:44:37 +0400297endif
298
Chih-Wei Huang0d09e582010-07-09 10:07:52 +0800299else
300arm_objects_mode :=
301normal_objects_mode :=
302arm_objects_cflags :=
303normal_objects_cflags :=
304endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800305
306###########################################################
307## Define per-module debugging flags. Users can turn on
308## debugging for a particular module by setting DEBUG_MODULE_ModuleName
309## to a non-empty value in their environment or buildspec.mk,
310## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
311## debug flags that they want to use.
312###########################################################
313ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
314 debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
315else
316 debug_cflags :=
317endif
318
Tim Murraya7aa8002012-10-29 16:06:00 -0700319####################################################
320## Compile RenderScript with reflected C++
321####################################################
322
Ying Wangb8e01852014-01-23 15:09:04 -0800323renderscript_sources := $(filter %.rs %.fs,$(my_src_files))
Tim Murraya7aa8002012-10-29 16:06:00 -0700324
325ifneq (,$(renderscript_sources))
326
327renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
328RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp
329renderscript_intermediate := $(intermediates)/renderscript
330
331ifeq ($(LOCAL_RENDERSCRIPT_CC),)
332LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
333endif
334
335# Turn on all warnings and warnings as errors for RS compiles.
336# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
337renderscript_flags := -Wall -Werror
338renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
339
Ying Wang6ef65192014-01-15 16:02:16 -0800340renderscript_includes := \
Tim Murraya7aa8002012-10-29 16:06:00 -0700341 $(TOPDIR)external/clang/lib/Headers \
342 $(TOPDIR)frameworks/rs/scriptc \
343 $(LOCAL_RENDERSCRIPT_INCLUDES)
344
345ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
Ying Wang6ef65192014-01-15 16:02:16 -0800346renderscript_includes := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
Tim Murraya7aa8002012-10-29 16:06:00 -0700347endif
348
Ying Wang6ef65192014-01-15 16:02:16 -0800349$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(renderscript_includes)
Tim Murraya7aa8002012-10-29 16:06:00 -0700350$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
351$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
352$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
353$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate)
354$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
355 $(transform-renderscripts-to-cpp-and-bc)
356
357# include the dependency files (.d) generated by llvm-rs-cc.
358renderscript_generated_dep_files := $(addprefix $(renderscript_intermediate)/, \
359 $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources)))))
360-include $(renderscript_generated_dep_files)
361
362LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
363
364rs_generated_cpps := $(addprefix \
365 $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rs,%.cpp, \
366 $(notdir $(renderscript_sources)))))
367
368$(rs_generated_cpps) : $(RenderScript_file_stamp)
369
Ying Wang6ef65192014-01-15 16:02:16 -0800370my_c_includes += $(renderscript_intermediate)
371my_generated_sources += $(rs_generated_cpps)
Tim Murraya7aa8002012-10-29 16:06:00 -0700372
373endif
374
375
The Android Open Source Project88b60792009-03-03 19:28:42 -0800376###########################################################
377## Stuff source generated from one-off tools
378###########################################################
Ying Wang6ef65192014-01-15 16:02:16 -0800379$(my_generated_sources): PRIVATE_MODULE := $(my_register_name)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800380
Colin Crossd8262642014-01-24 23:17:21 -0800381my_gen_sources_copy := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(filter $(generated_sources_dir)/%,$(my_generated_sources)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800382
Colin Crossd8262642014-01-24 23:17:21 -0800383$(my_gen_sources_copy): $(intermediates)/% : $(generated_sources_dir)/% | $(ACP)
384 @echo "Copy: $@"
385 $(copy-file-to-target)
386
387my_generated_sources := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(my_generated_sources))
388
389ALL_GENERATED_SOURCES += $(my_generated_sources)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800390
391###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700392## Compile the .proto files to .cc and then to .o
393###########################################################
Ying Wangb8e01852014-01-23 15:09:04 -0800394proto_sources := $(filter %.proto,$(my_src_files))
Ying Wanga5fc87a2010-11-02 18:43:16 -0700395proto_generated_objects :=
396proto_generated_headers :=
397ifneq ($(proto_sources),)
398proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
399proto_generated_cc_sources_dir := $(intermediates)/proto
400proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700401 $(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath)))
Ying Wanga5fc87a2010-11-02 18:43:16 -0700402proto_generated_objects := $(patsubst %.cc,%.o, $(proto_generated_cc_sources))
403
404$(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
405$(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir)
Ying Wang33c0d952010-11-05 11:30:58 -0700406$(proto_generated_cc_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
Ying Wanga5fc87a2010-11-02 18:43:16 -0700407$(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC)
408 $(transform-proto-to-cc)
409
410proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources))
411$(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc
412
Ying Wang022a7b32012-06-13 11:38:10 -0700413$(proto_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
414$(proto_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
Narayan Kamath21094872012-04-02 18:19:31 +0100415$(proto_generated_objects): $(proto_generated_cc_sources_dir)/%.o: $(proto_generated_cc_sources_dir)/%.cc $(proto_generated_headers)
Ying Wanga5fc87a2010-11-02 18:43:16 -0700416 $(transform-$(PRIVATE_HOST)cpp-to-o)
417-include $(proto_generated_objects:%.o=%.P)
418
Ying Wang6ef65192014-01-15 16:02:16 -0800419my_c_includes += external/protobuf/src $(proto_generated_cc_sources_dir)
420my_cflags += -DGOOGLE_PROTOBUF_NO_RTTI
Ying Wanga5fc87a2010-11-02 18:43:16 -0700421ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
Ying Wang6ef65192014-01-15 16:02:16 -0800422my_static_libraries += libprotobuf-cpp-2.3.0-full
Ying Wanga5fc87a2010-11-02 18:43:16 -0700423else
Ying Wang6ef65192014-01-15 16:02:16 -0800424my_static_libraries += libprotobuf-cpp-2.3.0-lite
Ying Wanga5fc87a2010-11-02 18:43:16 -0700425endif
426endif
427
428
429###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800430## YACC: Compile .y files to .cpp and the to .o.
431###########################################################
432
Ying Wangb8e01852014-01-23 15:09:04 -0800433yacc_sources := $(filter %.y,$(my_src_files))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800434yacc_cpps := $(addprefix \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700435 $(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800436yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h)
437yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o)
438
439ifneq ($(strip $(yacc_cpps)),)
440$(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700441 $(TOPDIR)$(LOCAL_PATH)/%.y \
442 $(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800443 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
444$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
445
446$(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
447$(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
448$(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
449 $(transform-$(PRIVATE_HOST)cpp-to-o)
450endif
451
452###########################################################
453## LEX: Compile .l files to .cpp and then to .o.
454###########################################################
455
Ying Wangb8e01852014-01-23 15:09:04 -0800456lex_sources := $(filter %.l,$(my_src_files))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800457lex_cpps := $(addprefix \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700458 $(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800459lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o)
460
461ifneq ($(strip $(lex_cpps)),)
462$(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700463 $(TOPDIR)$(LOCAL_PATH)/%.l
The Android Open Source Project88b60792009-03-03 19:28:42 -0800464 $(transform-l-to-cpp)
465
466$(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
467$(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
468$(lex_objects): $(intermediates)/%.o: \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700469 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \
470 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
471 $(yacc_headers)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800472 $(transform-$(PRIVATE_HOST)cpp-to-o)
473endif
474
475###########################################################
476## C++: Compile .cpp files to .o.
477###########################################################
478
Jeff Browne33ba4c2011-07-11 22:11:46 -0700479# we also do this on host modules, even though
The Android Open Source Project88b60792009-03-03 19:28:42 -0800480# it's not really arm, because there are files that are shared.
Ying Wangb8e01852014-01-23 15:09:04 -0800481cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(my_src_files)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800482cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o))
483
Ying Wangb8e01852014-01-23 15:09:04 -0800484cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(my_src_files))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800485cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
486
487$(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
488$(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
489$(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
490$(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
491
492cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects)
493
494ifneq ($(strip $(cpp_objects)),)
495$(cpp_objects): $(intermediates)/%.o: \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700496 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
Ying Wang9c3aa052013-02-20 13:34:05 -0800497 $(yacc_cpps) $(proto_generated_headers) \
498 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
499 | $(my_compiler_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800500 $(transform-$(PRIVATE_HOST)cpp-to-o)
501-include $(cpp_objects:%.o=%.P)
502endif
503
504###########################################################
505## C++: Compile generated .cpp files to .o.
506###########################################################
507
Ying Wangec6d6262014-01-16 16:21:03 -0800508gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(my_generated_sources))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800509gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
510
511ifneq ($(strip $(gen_cpp_objects)),)
512# Compile all generated files as thumb.
513# TODO: support compiling certain generated files as arm.
514$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
515$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400516$(gen_cpp_objects): $(intermediates)/%.o: \
517 $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) \
Ying Wang9c3aa052013-02-20 13:34:05 -0800518 $(proto_generated_headers) \
519 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
520 | $(my_compiler_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800521 $(transform-$(PRIVATE_HOST)cpp-to-o)
522-include $(gen_cpp_objects:%.o=%.P)
523endif
524
525###########################################################
526## S: Compile generated .S and .s files to .o.
527###########################################################
528
Ying Wangec6d6262014-01-16 16:21:03 -0800529gen_S_sources := $(filter %.S,$(my_generated_sources))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800530gen_S_objects := $(gen_S_sources:%.S=%.o)
531
532ifneq ($(strip $(gen_S_sources)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400533$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \
Ying Wang9c3aa052013-02-20 13:34:05 -0800534 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
535 | $(my_compiler_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800536 $(transform-$(PRIVATE_HOST)s-to-o)
537-include $(gen_S_objects:%.o=%.P)
538endif
539
Ying Wangec6d6262014-01-16 16:21:03 -0800540gen_s_sources := $(filter %.s,$(my_generated_sources))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800541gen_s_objects := $(gen_s_sources:%.s=%.o)
542
543ifneq ($(strip $(gen_s_objects)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400544$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \
Ying Wang9c3aa052013-02-20 13:34:05 -0800545 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
546 | $(my_compiler_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800547 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
548-include $(gen_s_objects:%.o=%.P)
549endif
550
551gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
552
553###########################################################
Torne (Richard Coles)aace2022013-02-21 14:01:35 +0000554## o: Include generated .o files in output.
555###########################################################
556
Ying Wangec6d6262014-01-16 16:21:03 -0800557gen_o_objects := $(filter %.o,$(my_generated_sources))
Torne (Richard Coles)aace2022013-02-21 14:01:35 +0000558
559###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800560## C: Compile .c files to .o.
561###########################################################
562
Ying Wangb8e01852014-01-23 15:09:04 -0800563c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(my_src_files)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800564c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o))
565
Ying Wangb8e01852014-01-23 15:09:04 -0800566c_normal_sources := $(filter %.c,$(my_src_files))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800567c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
568
569$(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
570$(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
571$(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
572$(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
573
574c_objects := $(c_arm_objects) $(c_normal_objects)
575
576ifneq ($(strip $(c_objects)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400577$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \
Ying Wang9c3aa052013-02-20 13:34:05 -0800578 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
579 | $(my_compiler_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800580 $(transform-$(PRIVATE_HOST)c-to-o)
581-include $(c_objects:%.o=%.P)
582endif
583
584###########################################################
Jack Paleviche7b3e2c2009-05-04 14:32:44 -0700585## C: Compile generated .c files to .o.
586###########################################################
587
Ying Wangec6d6262014-01-16 16:21:03 -0800588gen_c_sources := $(filter %.c,$(my_generated_sources))
Jack Paleviche7b3e2c2009-05-04 14:32:44 -0700589gen_c_objects := $(gen_c_sources:%.c=%.o)
590
591ifneq ($(strip $(gen_c_objects)),)
592# Compile all generated files as thumb.
593# TODO: support compiling certain generated files as arm.
594$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
595$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400596$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \
Ying Wang9c3aa052013-02-20 13:34:05 -0800597 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
598 | $(my_compiler_dependencies)
Jack Paleviche7b3e2c2009-05-04 14:32:44 -0700599 $(transform-$(PRIVATE_HOST)c-to-o)
600-include $(gen_c_objects:%.o=%.P)
601endif
602
603###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200604## ObjC: Compile .m files to .o
605###########################################################
606
Ying Wangb8e01852014-01-23 15:09:04 -0800607objc_sources := $(filter %.m,$(my_src_files))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200608objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
609
610ifneq ($(strip $(objc_objects)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400611$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) \
Ying Wang9c3aa052013-02-20 13:34:05 -0800612 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
613 | $(my_compiler_dependencies)
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200614 $(transform-$(PRIVATE_HOST)m-to-o)
615-include $(objc_objects:%.o=%.P)
616endif
617
618###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800619## AS: Compile .S files to .o.
620###########################################################
621
Ying Wangb8e01852014-01-23 15:09:04 -0800622asm_sources_S := $(filter %.S,$(my_src_files))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800623asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
624
625ifneq ($(strip $(asm_objects_S)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400626$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \
Ying Wang9c3aa052013-02-20 13:34:05 -0800627 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
628 | $(my_compiler_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800629 $(transform-$(PRIVATE_HOST)s-to-o)
630-include $(asm_objects_S:%.o=%.P)
631endif
632
Ying Wangb8e01852014-01-23 15:09:04 -0800633asm_sources_s := $(filter %.s,$(my_src_files))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800634asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
635
636ifneq ($(strip $(asm_objects_s)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400637$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \
Ying Wang9c3aa052013-02-20 13:34:05 -0800638 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
639 | $(my_compiler_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800640 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
641-include $(asm_objects_s:%.o=%.P)
642endif
643
644asm_objects := $(asm_objects_S) $(asm_objects_s)
645
646
Ying Wang5f074802011-11-08 09:31:21 -0800647####################################################
648## Import includes
649####################################################
650import_includes := $(intermediates)/import_includes
651import_includes_deps := $(strip \
652 $(foreach l, $(installed_shared_library_module_names), \
Ying Wang6ef65192014-01-15 16:02:16 -0800653 $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/export_includes) \
654 $(foreach l, $(my_static_libraries) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
655 $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/export_includes))
Ying Wang5f074802011-11-08 09:31:21 -0800656$(import_includes) : $(import_includes_deps)
657 @echo Import includes file: $@
658 $(hide) mkdir -p $(dir $@) && rm -f $@
659ifdef import_includes_deps
660 $(hide) for f in $^; do \
661 cat $$f >> $@; \
662 done
663else
664 $(hide) touch $@
665endif
666
The Android Open Source Project88b60792009-03-03 19:28:42 -0800667###########################################################
668## Common object handling.
669###########################################################
670
671# some rules depend on asm_objects being first. If your code depends on
672# being first, it's reasonable to require it to be assembly
Torne (Richard Coles)a5afbe82013-08-29 15:36:34 +0100673normal_objects := \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700674 $(asm_objects) \
675 $(cpp_objects) \
676 $(gen_cpp_objects) \
677 $(gen_asm_objects) \
678 $(c_objects) \
679 $(gen_c_objects) \
680 $(objc_objects) \
681 $(yacc_objects) \
682 $(lex_objects) \
683 $(proto_generated_objects) \
Torne (Richard Coles)a5afbe82013-08-29 15:36:34 +0100684 $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
685
686all_objects := $(normal_objects) $(gen_o_objects)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800687
Ying Wang6ef65192014-01-15 16:02:16 -0800688my_c_includes += $(TOPDIR)$(LOCAL_PATH) $(intermediates)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800689
Ying Wang848020f2012-08-14 10:13:16 -0700690ifndef LOCAL_SDK_VERSION
Ying Wang6ef65192014-01-15 16:02:16 -0800691 my_c_includes += $(JNI_H_INCLUDE)
Ying Wangbce4b752010-07-22 15:51:56 -0700692endif
693
Torne (Richard Coles)a5afbe82013-08-29 15:36:34 +0100694# all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES;
695# use normal_objects here to avoid creating circular dependencies. This assumes
696# that custom build rules which generate .o files don't consume other generated
697# sources as input (or if they do they take care of that dependency themselves).
Ying Wangec6d6262014-01-16 16:21:03 -0800698$(normal_objects) : | $(my_generated_sources)
Torne (Richard Coles)a5afbe82013-08-29 15:36:34 +0100699$(all_objects) : | $(import_includes)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800700ALL_C_CPP_ETC_OBJECTS += $(all_objects)
701
702###########################################################
703## Copy headers to the install tree
704###########################################################
Ying Wang6ef65192014-01-15 16:02:16 -0800705ifndef LOCAL_2ND_ARCH_VAR_PREFIX
The Android Open Source Project88b60792009-03-03 19:28:42 -0800706include $(BUILD_COPY_HEADERS)
Ying Wang6ef65192014-01-15 16:02:16 -0800707endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800708
709###########################################################
710# Standard library handling.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800711###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800712
713###########################################################
714# The list of libraries that this module will link against are in
715# these variables. Each is a list of bare module names like "libc libm".
716#
717# LOCAL_SHARED_LIBRARIES
718# LOCAL_STATIC_LIBRARIES
719# LOCAL_WHOLE_STATIC_LIBRARIES
720#
721# We need to convert the bare names into the dependencies that
722# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
723# LOCAL_BUILT_MODULE should depend on the BUILT versions of the
724# libraries, so that simply building this module doesn't force
725# an install of a library. Similarly, LOCAL_INSTALLED_MODULE
726# should depend on the INSTALLED versions of the libraries so
727# that they get installed when this module does.
728###########################################################
729# NOTE:
730# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
731# module without leaving anything out, which is useful for turning
732# a collection of .a files into a .so file. Linking against a
733# normal STATIC_LIBRARY will only pull in code/symbols that are
734# referenced by the module. (see gcc/ld's --whole-archive option)
735###########################################################
736
737# Get the list of BUILT libraries, which are under
738# various intermediates directories.
739so_suffix := $($(my_prefix)SHLIB_SUFFIX)
740a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
741
Ying Wang848020f2012-08-14 10:13:16 -0700742ifdef LOCAL_SDK_VERSION
The Android Open Source Project88b60792009-03-03 19:28:42 -0800743built_shared_libraries := \
Ying Wang6ef65192014-01-15 16:02:16 -0800744 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800745 $(addsuffix $(so_suffix), \
Ying Wang6ef65192014-01-15 16:02:16 -0800746 $(my_shared_libraries)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800747
Ying Wangcce4c972011-03-03 18:53:53 -0800748my_system_shared_libraries_fullpath := \
749 $(my_ndk_stl_shared_lib_fullpath) \
750 $(addprefix $(my_ndk_version_root)/usr/lib/, \
751 $(addsuffix $(so_suffix), $(LOCAL_SYSTEM_SHARED_LIBRARIES)))
Ying Wang1a081002010-07-13 14:55:47 -0700752
753built_shared_libraries += $(my_system_shared_libraries_fullpath)
Ying Wang6ef65192014-01-15 16:02:16 -0800754my_shared_libraries += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
Ying Wang1a081002010-07-13 14:55:47 -0700755else
Ying Wang6ef65192014-01-15 16:02:16 -0800756my_shared_libraries += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
Ying Wang1a081002010-07-13 14:55:47 -0700757built_shared_libraries := \
Ying Wang6ef65192014-01-15 16:02:16 -0800758 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
Ying Wang1a081002010-07-13 14:55:47 -0700759 $(addsuffix $(so_suffix), \
Ying Wang6ef65192014-01-15 16:02:16 -0800760 $(my_shared_libraries)))
Ying Wang1a081002010-07-13 14:55:47 -0700761endif
762
The Android Open Source Project88b60792009-03-03 19:28:42 -0800763built_static_libraries := \
Ying Wang6ef65192014-01-15 16:02:16 -0800764 $(foreach lib,$(my_static_libraries), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800765 $(call intermediates-dir-for, \
Ying Wang6ef65192014-01-15 16:02:16 -0800766 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/$(lib)$(a_suffix))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800767
Ying Wang848020f2012-08-14 10:13:16 -0700768ifdef LOCAL_SDK_VERSION
Ying Wangcce4c972011-03-03 18:53:53 -0800769built_static_libraries += $(my_ndk_stl_static_lib)
770endif
771
The Android Open Source Project88b60792009-03-03 19:28:42 -0800772built_whole_libraries := \
773 $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \
774 $(call intermediates-dir-for, \
Ying Wang6ef65192014-01-15 16:02:16 -0800775 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/$(lib)$(a_suffix))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800776
The Android Open Source Project88b60792009-03-03 19:28:42 -0800777# We don't care about installed static libraries, since the
778# libraries have already been linked into the module at that point.
779# We do, however, care about the NOTICE files for any static
Steve Blockd14d3b42012-03-01 11:34:41 +0000780# libraries that we use. (see notice_files.mk)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800781
782installed_static_library_notice_file_targets := \
Ying Wang6ef65192014-01-15 16:02:16 -0800783 $(foreach lib,$(my_static_libraries) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800784 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib))
785
Doug Kwan9a8ecf92011-05-10 21:50:58 -0700786# Default is -fno-rtti.
Doug Kwane3c3c6d2011-06-07 10:55:48 -0700787ifeq ($(strip $(LOCAL_RTTI_FLAG)),)
788LOCAL_RTTI_FLAG := -fno-rtti
789endif
Doug Kwan9a8ecf92011-05-10 21:50:58 -0700790
The Android Open Source Project88b60792009-03-03 19:28:42 -0800791###########################################################
792# Rule-specific variable definitions
793###########################################################
Logan Chiene6f65432013-12-10 19:07:41 +0800794
795ifeq ($(LOCAL_CLANG),true)
Ying Wang6ef65192014-01-15 16:02:16 -0800796my_cflags := $(call convert-to-$(my_host)clang-flags,$(my_cflags))
797my_cppflags := $(call convert-to-$(my_host)clang-flags,$(my_cppflags))
798my_asflags := $(call convert-to-$(my_host)clang-flags,$(my_asflags))
799my_ldflags := $(call convert-to-$(my_host)clang-flags,$(my_ldflags))
Logan Chiene6f65432013-12-10 19:07:41 +0800800endif
801
The Android Open Source Project88b60792009-03-03 19:28:42 -0800802$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
Ying Wang6ef65192014-01-15 16:02:16 -0800803$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(my_asflags)
Ying Wang7429e212012-08-15 10:59:10 -0700804$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(LOCAL_CONLYFLAGS)
Ying Wang6ef65192014-01-15 16:02:16 -0800805$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(my_cflags)
806$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(my_cppflags)
Doug Kwan9a8ecf92011-05-10 21:50:58 -0700807$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800808$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
Ying Wang6ef65192014-01-15 16:02:16 -0800809$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(my_c_includes)
Ying Wang5f074802011-11-08 09:31:21 -0800810$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes)
Ying Wang6ef65192014-01-15 16:02:16 -0800811$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(my_ldflags)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800812$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS)
Ying Wangb8e01852014-01-23 15:09:04 -0800813$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_CRT := $(strip $(LOCAL_NO_CRT) $(LOCAL_NO_CRT_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800814
815# this is really the way to get the files onto the command line instead
816# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
817$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
818$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
819$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
820$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects)
821
822###########################################################
823# Define library dependencies.
824###########################################################
825# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
826all_libraries := \
827 $(built_shared_libraries) \
828 $(built_static_libraries) \
829 $(built_whole_libraries)
830
The Android Open Source Project88b60792009-03-03 19:28:42 -0800831# Also depend on the notice files for any static libraries that
832# are linked into this module. This will force them to be installed
833# when this module is.
834$(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets)
Ying Wang5f074802011-11-08 09:31:21 -0800835
836###########################################################
837# Export includes
838###########################################################
839export_includes := $(intermediates)/export_includes
840$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
Ying Wang68f1c772012-04-23 21:29:18 -0700841$(export_includes) : $(LOCAL_MODULE_MAKEFILE)
Ying Wang5f074802011-11-08 09:31:21 -0800842 @echo Export includes file: $< -- $@
843 $(hide) mkdir -p $(dir $@) && rm -f $@
844ifdef LOCAL_EXPORT_C_INCLUDE_DIRS
845 $(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \
846 echo "-I $$d" >> $@; \
847 done
848else
849 $(hide) touch $@
850endif
Ying Wang616e5962012-04-18 17:35:55 -0700851
852# Make sure export_includes gets generated when you are running mm/mmm
853$(LOCAL_BUILT_MODULE) : | $(export_includes)