blob: bba5711ab8998e8e7d65ee5acf8f4353482b11f8 [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 -07008######################################
9## Sanity check for LOCAL_NDK_VERSION
10######################################
11my_ndk_version_root :=
12ifdef LOCAL_NDK_VERSION
13 ifdef LOCAL_IS_HOST_MODULE
14 $(error $(LOCAL_PATH): LOCAL_NDK_VERSION can not be used in host module)
15 endif
16 ifneq ($(filter-out SHARED_LIBRARIES STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
17 $(error $(LOCAL_PATH): LOCAL_NDK_VERSION can only be used to build target shared/static libraries, \
18 while your module is of class $(LOCAL_MODULE_CLASS))
19 endif
20 ifeq ($(filter $(LOCAL_NDK_VERSION),$(TARGET_AVAILABLE_NDK_VERSIONS)),)
21 $(error $(LOCAL_PATH): Invalid LOCAL_NDK_VERSION '$(LOCAL_NDK_VERSION)' \
22 Choices are $(TARGET_AVAILABLE_NDK_VERSIONS))
23 endif
24 ifndef LOCAL_SDK_VERSION
25 $(error $(LOCAL_PATH): LOCAL_NDK_VERSION must be defined with LOCAL_SDK_VERSION)
26 endif
Ying Wang2f76c6d2011-02-23 10:07:03 -080027 my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/android-ndk-r$(LOCAL_NDK_VERSION)/sources
Ying Wang02c98132010-09-23 17:59:36 -070028 my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/android-ndk-r$(LOCAL_NDK_VERSION)/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_ARCH)
Ying Wang1a081002010-07-13 14:55:47 -070029 ifeq ($(wildcard $(my_ndk_version_root)),)
30 $(error $(LOCAL_PATH): ndk version root does not exist: $(my_ndk_version_root))
31 endif
Ying Wangcce4c972011-03-03 18:53:53 -080032
33 # Set up the NDK stl variant. Starting from NDK-r5 the c++ stl resides in a separate location.
34 # See ndk/docs/CPLUSPLUS-SUPPORT.html
35 my_ndk_stl_include_path :=
36 my_ndk_stl_shared_lib_fullpath :=
37 my_ndk_stl_shared_lib :=
38 my_ndk_stl_static_lib :=
39 ifeq (,$(LOCAL_NDK_STL_VARIANT))
40 LOCAL_NDK_STL_VARIANT := system
41 endif
42 ifneq (1,$(words $(filter system stlport_static stlport_shared gnustl_static, $(LOCAL_NDK_STL_VARIANT))))
43 $(error $(LOCAL_PATH): Unkown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT))
44 endif
45 ifeq (system,$(LOCAL_NDK_STL_VARIANT))
46 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/system/include
47 # for "system" variant, the shared library exists in the system library and -lstdc++ is added by default.
48 else # LOCAL_NDK_STL_VARIANT is not system
49 ifneq (,$(filter stlport_%, $(LOCAL_NDK_STL_VARIANT)))
50 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/stlport/stlport
51 ifeq (stlport_static,$(LOCAL_NDK_STL_VARIANT))
52 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(TARGET_CPU_ABI)/libstlport_static.a
53 else
54 my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(TARGET_CPU_ABI)/libstlport_shared.so
55 my_ndk_stl_shared_lib := -lstlport_shared
56 endif
57 else
58 # LOCAL_NDK_STL_VARIANT is gnustl_static
Ying Wangd9020c22011-09-07 14:31:47 -070059 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_CPU_ABI)/include \
60 $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/include
Ying Wangcce4c972011-03-03 18:53:53 -080061 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_CPU_ABI)/libstdc++.a
62 endif
63 endif
Ying Wang1a081002010-07-13 14:55:47 -070064endif
65
Ying Wang704c0c92011-09-15 13:50:52 -070066##################################################
67# Compute the dependency of the shared libraries
68##################################################
69# On the target, we compile with -nostdlib, so we must add in the
70# default system shared libraries, unless they have requested not
71# to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value. One would
72# supply that, for example, when building libc itself.
73ifdef LOCAL_IS_HOST_MODULE
74 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
75 LOCAL_SYSTEM_SHARED_LIBRARIES :=
76 endif
77else
78 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
79 LOCAL_SYSTEM_SHARED_LIBRARIES := $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES)
80 endif
81endif
82
83# Logging used to be part of libcutils (target) and libutils (sim);
84# hack modules that use those other libs to also include liblog.
85# All of this complexity is to make sure that liblog only appears
86# once, and appears just before libcutils or libutils on the link
87# line.
88# TODO: remove this hack and change all modules to use liblog
89# when necessary.
90define insert-liblog
91 $(if $(filter liblog,$(1)),$(1), \
92 $(if $(filter libcutils,$(1)), \
93 $(patsubst libcutils,liblog libcutils,$(1)) \
94 , \
95 $(patsubst libutils,liblog libutils,$(1)) \
96 ) \
97 )
98endef
99ifneq (,$(filter libcutils libutils,$(LOCAL_SHARED_LIBRARIES)))
100 LOCAL_SHARED_LIBRARIES := $(call insert-liblog,$(LOCAL_SHARED_LIBRARIES))
101endif
102ifneq (,$(filter libcutils libutils,$(LOCAL_STATIC_LIBRARIES)))
103 LOCAL_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_STATIC_LIBRARIES))
104endif
105ifneq (,$(filter libcutils libutils,$(LOCAL_WHOLE_STATIC_LIBRARIES)))
106 LOCAL_WHOLE_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_WHOLE_STATIC_LIBRARIES))
107endif
108
109ifdef LOCAL_NDK_VERSION
110 # Get the list of INSTALLED libraries as module names.
111 # We can not compute the full path of the LOCAL_SHARED_LIBRARIES for
112 # they may cusomize their install path with LOCAL_MODULE_PATH
113 installed_shared_library_module_names := \
114 $(LOCAL_SHARED_LIBRARIES)
115else
116 installed_shared_library_module_names := \
117 $(LOCAL_SYSTEM_SHARED_LIBRARIES) $(LOCAL_SHARED_LIBRARIES)
118endif
119# The real dependency will be added after all Android.mks are loaded and the install paths
120# of the shared libraries are determined.
121LOCAL_REQUIRED_MODULES += $(installed_shared_library_module_names)
122
The Android Open Source Project88b60792009-03-03 19:28:42 -0800123#######################################
124include $(BUILD_SYSTEM)/base_rules.mk
125#######################################
Ying Wangdfbe79b2012-03-22 11:26:22 -0700126my_compiler_dependencies :=
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400127ifeq ($(strip $(LOCAL_CLANG)),true)
128 LOCAL_CFLAGS += $(CLANG_CONFIG_EXTRA_CFLAGS)
129 LOCAL_LDFLAGS += $(CLANG_CONFIG_EXTRA_LDFLAGS)
Ying Wangdfbe79b2012-03-22 11:26:22 -0700130 my_compiler_dependencies := $(CLANG) $(CLANG_CXX)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400131endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800132
Jing Yu2dcc8062009-09-21 16:31:50 -0700133####################################################
134## Add FDO flags if FDO is turned on and supported
135####################################################
136ifeq ($(strip $(LOCAL_NO_FDO_SUPPORT)),)
137 LOCAL_CFLAGS += $(TARGET_FDO_CFLAGS)
138 LOCAL_CPPFLAGS += $(TARGET_FDO_CFLAGS)
139 LOCAL_LDFLAGS += $(TARGET_FDO_CFLAGS)
140endif
141
The Android Open Source Project88b60792009-03-03 19:28:42 -0800142###########################################################
Jim Huang20d1ba62010-10-14 16:15:56 +0800143## Explicitly declare assembly-only __ASSEMBLY__ macro for
144## assembly source
145###########################################################
146LOCAL_ASFLAGS += -D__ASSEMBLY__
147
148###########################################################
Ying Wang1a081002010-07-13 14:55:47 -0700149## Define PRIVATE_ variables from global vars
150###########################################################
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400151ifeq ($(strip $(LOCAL_CLANG)),true)
152my_target_global_cflags := $(TARGET_GLOBAL_CLANG_FLAGS)
153else
154my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS)
155endif
156
Ying Wang1a081002010-07-13 14:55:47 -0700157ifdef LOCAL_NDK_VERSION
158my_target_project_includes :=
Evgeniy Stepanova7095e92012-03-30 12:18:52 +0400159my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_version_root)/usr/include
Ying Wang1a081002010-07-13 14:55:47 -0700160# TODO: more reliable way to remove platform stuff.
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400161my_target_global_cflags := $(filter-out -include -I system/%, $(my_target_global_cflags))
Ying Wang1a081002010-07-13 14:55:47 -0700162my_target_global_cppflags := $(filter-out -include -I system/%, $(TARGET_GLOBAL_CPPFLAGS))
163else
164my_target_project_includes := $(TARGET_PROJECT_INCLUDES)
Evgeniy Stepanova7095e92012-03-30 12:18:52 +0400165my_target_c_includes := $(TARGET_C_INCLUDES)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400166my_target_global_cflags := $(my_target_global_cflags)
Ying Wang1a081002010-07-13 14:55:47 -0700167my_target_global_cppflags := $(TARGET_GLOBAL_CPPFLAGS)
Evgeniy Stepanova7095e92012-03-30 12:18:52 +0400168ifeq ($(strip $(LOCAL_CLANG)),true)
169 my_target_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES)
170endif
Ying Wang1a081002010-07-13 14:55:47 -0700171endif
172$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes)
Evgeniy Stepanova7095e92012-03-30 12:18:52 +0400173$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes)
Ying Wang1a081002010-07-13 14:55:47 -0700174$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
175$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags)
176
177###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800178## Define PRIVATE_ variables used by multiple module types
179###########################################################
180$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700181 $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800182
183ifeq ($(strip $(LOCAL_CC)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400184 ifeq ($(strip $(LOCAL_CLANG)),true)
185 LOCAL_CC := $(CLANG)
186 else
187 LOCAL_CC := $($(my_prefix)CC)
188 endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800189endif
190$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(LOCAL_CC)
191
192ifeq ($(strip $(LOCAL_CXX)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400193 ifeq ($(strip $(LOCAL_CLANG)),true)
194 LOCAL_CXX := $(CLANG_CXX)
195 else
196 LOCAL_CXX := $($(my_prefix)CXX)
197 endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800198endif
199$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(LOCAL_CXX)
200
201# TODO: support a mix of standard extensions so that this isn't necessary
202LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
203ifeq ($(LOCAL_CPP_EXTENSION),)
204 LOCAL_CPP_EXTENSION := .cpp
205endif
206$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION)
207
208# Certain modules like libdl have to have symbols resolved at runtime and blow
209# up if --no-undefined is passed to the linker.
210ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
211ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),)
212 LOCAL_LDFLAGS := $(LOCAL_LDFLAGS) $($(my_prefix)NO_UNDEFINED_LDFLAGS)
213endif
214endif
215
Ying Wangfcdabd42011-04-25 14:22:41 -0700216ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES))
217$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true
218else
219$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES :=
220endif
221
The Android Open Source Project88b60792009-03-03 19:28:42 -0800222###########################################################
223## Define arm-vs-thumb-mode flags.
224###########################################################
225LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
Chih-Wei Huang0d09e582010-07-09 10:07:52 +0800226ifeq ($(TARGET_ARCH),arm)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800227arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
228normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
229
Dave Bort95282482009-04-23 18:44:55 -0700230# Read the values from something like TARGET_arm_CFLAGS or
231# TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't
232# actually used (although they are usually empty).
233arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CFLAGS)
234normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_CFLAGS)
Chih-Wei Huang0d09e582010-07-09 10:07:52 +0800235else
236arm_objects_mode :=
237normal_objects_mode :=
238arm_objects_cflags :=
239normal_objects_cflags :=
240endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800241
242###########################################################
243## Define per-module debugging flags. Users can turn on
244## debugging for a particular module by setting DEBUG_MODULE_ModuleName
245## to a non-empty value in their environment or buildspec.mk,
246## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
247## debug flags that they want to use.
248###########################################################
249ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
250 debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
251else
252 debug_cflags :=
253endif
254
255###########################################################
256## Stuff source generated from one-off tools
257###########################################################
258$(LOCAL_GENERATED_SOURCES): PRIVATE_MODULE := $(LOCAL_MODULE)
259
260ALL_GENERATED_SOURCES += $(LOCAL_GENERATED_SOURCES)
261
262
263###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700264## Compile the .proto files to .cc and then to .o
265###########################################################
266proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
267proto_generated_objects :=
268proto_generated_headers :=
269ifneq ($(proto_sources),)
270proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
271proto_generated_cc_sources_dir := $(intermediates)/proto
272proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700273 $(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath)))
Ying Wanga5fc87a2010-11-02 18:43:16 -0700274proto_generated_objects := $(patsubst %.cc,%.o, $(proto_generated_cc_sources))
275
276$(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
277$(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir)
Ying Wang33c0d952010-11-05 11:30:58 -0700278$(proto_generated_cc_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
Ying Wanga5fc87a2010-11-02 18:43:16 -0700279$(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC)
280 $(transform-proto-to-cc)
281
282proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources))
283$(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc
284
285$(proto_generated_cc_sources): PRIVATE_ARM_MODE := $(normal_objects_mode)
286$(proto_generated_cc_sources): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
Narayan Kamath21094872012-04-02 18:19:31 +0100287$(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 -0700288 $(transform-$(PRIVATE_HOST)cpp-to-o)
289-include $(proto_generated_objects:%.o=%.P)
290
291LOCAL_C_INCLUDES += external/protobuf/src $(proto_generated_cc_sources_dir)
292LOCAL_CFLAGS += -DGOOGLE_PROTOBUF_NO_RTTI
293ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
294LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-full
295else
296LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-lite
297endif
298endif
299
300
301###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800302## YACC: Compile .y files to .cpp and the to .o.
303###########################################################
304
305yacc_sources := $(filter %.y,$(LOCAL_SRC_FILES))
306yacc_cpps := $(addprefix \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700307 $(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800308yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h)
309yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o)
310
311ifneq ($(strip $(yacc_cpps)),)
312$(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700313 $(TOPDIR)$(LOCAL_PATH)/%.y \
314 $(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800315 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
316$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
317
318$(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
319$(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
320$(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
321 $(transform-$(PRIVATE_HOST)cpp-to-o)
322endif
323
324###########################################################
325## LEX: Compile .l files to .cpp and then to .o.
326###########################################################
327
328lex_sources := $(filter %.l,$(LOCAL_SRC_FILES))
329lex_cpps := $(addprefix \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700330 $(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800331lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o)
332
333ifneq ($(strip $(lex_cpps)),)
334$(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700335 $(TOPDIR)$(LOCAL_PATH)/%.l
The Android Open Source Project88b60792009-03-03 19:28:42 -0800336 $(transform-l-to-cpp)
337
338$(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
339$(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
340$(lex_objects): $(intermediates)/%.o: \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700341 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \
342 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
343 $(yacc_headers)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800344 $(transform-$(PRIVATE_HOST)cpp-to-o)
345endif
346
347###########################################################
348## C++: Compile .cpp files to .o.
349###########################################################
350
Jeff Browne33ba4c2011-07-11 22:11:46 -0700351# we also do this on host modules, even though
The Android Open Source Project88b60792009-03-03 19:28:42 -0800352# it's not really arm, because there are files that are shared.
353cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(LOCAL_SRC_FILES)))
354cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o))
355
356cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES))
357cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
358
359$(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
360$(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
361$(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
362$(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
363
364cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects)
365
366ifneq ($(strip $(cpp_objects)),)
367$(cpp_objects): $(intermediates)/%.o: \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700368 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
369 $(yacc_cpps) $(proto_generated_headers) $(my_compiler_dependencies) \
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400370 $(LOCAL_ADDITIONAL_DEPENDENCIES)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800371 $(transform-$(PRIVATE_HOST)cpp-to-o)
372-include $(cpp_objects:%.o=%.P)
373endif
374
375###########################################################
376## C++: Compile generated .cpp files to .o.
377###########################################################
378
379gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_GENERATED_SOURCES))
380gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
381
382ifneq ($(strip $(gen_cpp_objects)),)
383# Compile all generated files as thumb.
384# TODO: support compiling certain generated files as arm.
385$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
386$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400387$(gen_cpp_objects): $(intermediates)/%.o: \
388 $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700389 $(proto_generated_headers) $(my_compiler_dependencies) \
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400390 $(LOCAL_ADDITIONAL_DEPENDENCIES)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800391 $(transform-$(PRIVATE_HOST)cpp-to-o)
392-include $(gen_cpp_objects:%.o=%.P)
393endif
394
395###########################################################
396## S: Compile generated .S and .s files to .o.
397###########################################################
398
399gen_S_sources := $(filter %.S,$(LOCAL_GENERATED_SOURCES))
400gen_S_objects := $(gen_S_sources:%.S=%.o)
401
402ifneq ($(strip $(gen_S_sources)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400403$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700404 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800405 $(transform-$(PRIVATE_HOST)s-to-o)
406-include $(gen_S_objects:%.o=%.P)
407endif
408
409gen_s_sources := $(filter %.s,$(LOCAL_GENERATED_SOURCES))
410gen_s_objects := $(gen_s_sources:%.s=%.o)
411
412ifneq ($(strip $(gen_s_objects)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400413$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700414 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800415 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
416-include $(gen_s_objects:%.o=%.P)
417endif
418
419gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
420
421###########################################################
422## C: Compile .c files to .o.
423###########################################################
424
425c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(LOCAL_SRC_FILES)))
426c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o))
427
428c_normal_sources := $(filter %.c,$(LOCAL_SRC_FILES))
429c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
430
431$(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
432$(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
433$(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
434$(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
435
436c_objects := $(c_arm_objects) $(c_normal_objects)
437
438ifneq ($(strip $(c_objects)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400439$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700440 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800441 $(transform-$(PRIVATE_HOST)c-to-o)
442-include $(c_objects:%.o=%.P)
443endif
444
445###########################################################
Jack Paleviche7b3e2c2009-05-04 14:32:44 -0700446## C: Compile generated .c files to .o.
447###########################################################
448
449gen_c_sources := $(filter %.c,$(LOCAL_GENERATED_SOURCES))
450gen_c_objects := $(gen_c_sources:%.c=%.o)
451
452ifneq ($(strip $(gen_c_objects)),)
453# Compile all generated files as thumb.
454# TODO: support compiling certain generated files as arm.
455$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
456$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400457$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700458 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES)
Jack Paleviche7b3e2c2009-05-04 14:32:44 -0700459 $(transform-$(PRIVATE_HOST)c-to-o)
460-include $(gen_c_objects:%.o=%.P)
461endif
462
463###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200464## ObjC: Compile .m files to .o
465###########################################################
466
467objc_sources := $(filter %.m,$(LOCAL_SRC_FILES))
468objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
469
470ifneq ($(strip $(objc_objects)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400471$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700472 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES)
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200473 $(transform-$(PRIVATE_HOST)m-to-o)
474-include $(objc_objects:%.o=%.P)
475endif
476
477###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800478## AS: Compile .S files to .o.
479###########################################################
480
481asm_sources_S := $(filter %.S,$(LOCAL_SRC_FILES))
482asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
483
484ifneq ($(strip $(asm_objects_S)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400485$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700486 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800487 $(transform-$(PRIVATE_HOST)s-to-o)
488-include $(asm_objects_S:%.o=%.P)
489endif
490
491asm_sources_s := $(filter %.s,$(LOCAL_SRC_FILES))
492asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
493
494ifneq ($(strip $(asm_objects_s)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +0400495$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700496 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800497 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
498-include $(asm_objects_s:%.o=%.P)
499endif
500
501asm_objects := $(asm_objects_S) $(asm_objects_s)
502
503
504###########################################################
505## Common object handling.
506###########################################################
507
508# some rules depend on asm_objects being first. If your code depends on
509# being first, it's reasonable to require it to be assembly
510all_objects := \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700511 $(asm_objects) \
512 $(cpp_objects) \
513 $(gen_cpp_objects) \
514 $(gen_asm_objects) \
515 $(c_objects) \
516 $(gen_c_objects) \
517 $(objc_objects) \
518 $(yacc_objects) \
519 $(lex_objects) \
520 $(proto_generated_objects) \
521 $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800522
Colin Cross9ad36ef2012-03-30 19:31:00 -0700523LOCAL_C_INCLUDES += $(TOPDIR)$(LOCAL_PATH) $(intermediates)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800524
Ying Wangbce4b752010-07-22 15:51:56 -0700525ifndef LOCAL_NDK_VERSION
526 LOCAL_C_INCLUDES += $(JNI_H_INCLUDE)
527endif
528
The Android Open Source Project88b60792009-03-03 19:28:42 -0800529$(all_objects) : | $(LOCAL_GENERATED_SOURCES)
530ALL_C_CPP_ETC_OBJECTS += $(all_objects)
531
532###########################################################
533## Copy headers to the install tree
534###########################################################
535include $(BUILD_COPY_HEADERS)
536
537###########################################################
538# Standard library handling.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800539###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800540
541###########################################################
542# The list of libraries that this module will link against are in
543# these variables. Each is a list of bare module names like "libc libm".
544#
545# LOCAL_SHARED_LIBRARIES
546# LOCAL_STATIC_LIBRARIES
547# LOCAL_WHOLE_STATIC_LIBRARIES
548#
549# We need to convert the bare names into the dependencies that
550# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
551# LOCAL_BUILT_MODULE should depend on the BUILT versions of the
552# libraries, so that simply building this module doesn't force
553# an install of a library. Similarly, LOCAL_INSTALLED_MODULE
554# should depend on the INSTALLED versions of the libraries so
555# that they get installed when this module does.
556###########################################################
557# NOTE:
558# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
559# module without leaving anything out, which is useful for turning
560# a collection of .a files into a .so file. Linking against a
561# normal STATIC_LIBRARY will only pull in code/symbols that are
562# referenced by the module. (see gcc/ld's --whole-archive option)
563###########################################################
564
565# Get the list of BUILT libraries, which are under
566# various intermediates directories.
567so_suffix := $($(my_prefix)SHLIB_SUFFIX)
568a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
569
Ying Wang1a081002010-07-13 14:55:47 -0700570ifdef LOCAL_NDK_VERSION
The Android Open Source Project88b60792009-03-03 19:28:42 -0800571built_shared_libraries := \
572 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
573 $(addsuffix $(so_suffix), \
574 $(LOCAL_SHARED_LIBRARIES)))
575
Ying Wangcce4c972011-03-03 18:53:53 -0800576my_system_shared_libraries_fullpath := \
577 $(my_ndk_stl_shared_lib_fullpath) \
578 $(addprefix $(my_ndk_version_root)/usr/lib/, \
579 $(addsuffix $(so_suffix), $(LOCAL_SYSTEM_SHARED_LIBRARIES)))
Ying Wang1a081002010-07-13 14:55:47 -0700580
581built_shared_libraries += $(my_system_shared_libraries_fullpath)
582LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
583else
584LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
585built_shared_libraries := \
586 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
587 $(addsuffix $(so_suffix), \
588 $(LOCAL_SHARED_LIBRARIES)))
Ying Wang1a081002010-07-13 14:55:47 -0700589endif
590
The Android Open Source Project88b60792009-03-03 19:28:42 -0800591built_static_libraries := \
592 $(foreach lib,$(LOCAL_STATIC_LIBRARIES), \
593 $(call intermediates-dir-for, \
594 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
595
Ying Wangcce4c972011-03-03 18:53:53 -0800596ifdef LOCAL_NDK_VERSION
597built_static_libraries += $(my_ndk_stl_static_lib)
598endif
599
The Android Open Source Project88b60792009-03-03 19:28:42 -0800600built_whole_libraries := \
601 $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \
602 $(call intermediates-dir-for, \
603 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
604
The Android Open Source Project88b60792009-03-03 19:28:42 -0800605# We don't care about installed static libraries, since the
606# libraries have already been linked into the module at that point.
607# We do, however, care about the NOTICE files for any static
Steve Blockd14d3b42012-03-01 11:34:41 +0000608# libraries that we use. (see notice_files.mk)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800609
610installed_static_library_notice_file_targets := \
611 $(foreach lib,$(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
612 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib))
613
Doug Kwan9a8ecf92011-05-10 21:50:58 -0700614# Default is -fno-rtti.
Doug Kwane3c3c6d2011-06-07 10:55:48 -0700615ifeq ($(strip $(LOCAL_RTTI_FLAG)),)
616LOCAL_RTTI_FLAG := -fno-rtti
617endif
Doug Kwan9a8ecf92011-05-10 21:50:58 -0700618
The Android Open Source Project88b60792009-03-03 19:28:42 -0800619###########################################################
620# Rule-specific variable definitions
621###########################################################
622$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
623$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS)
624$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS)
625$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS)
Doug Kwan9a8ecf92011-05-10 21:50:58 -0700626$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800627$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
628$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(LOCAL_C_INCLUDES)
629$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(LOCAL_LDFLAGS)
630$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS)
Jeff Brown703e7c62011-02-04 20:15:00 -0800631$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_CRT := $(LOCAL_NO_CRT)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800632
633# this is really the way to get the files onto the command line instead
634# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
635$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
636$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
637$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
638$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects)
639
640###########################################################
641# Define library dependencies.
642###########################################################
643# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
644all_libraries := \
645 $(built_shared_libraries) \
646 $(built_static_libraries) \
647 $(built_whole_libraries)
648
The Android Open Source Project88b60792009-03-03 19:28:42 -0800649# Also depend on the notice files for any static libraries that
650# are linked into this module. This will force them to be installed
651# when this module is.
652$(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets)