blob: 6741b43624924d7d42ffe58e0bf143174d594b9f [file] [log] [blame]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001###########################################################
2## Standard rules for building binary object files from
3## asm/c/cpp/yacc/lex source files.
4##
5## The list of object files is exported in $(all_objects).
6###########################################################
7
8#######################################
9include $(BUILD_SYSTEM)/base_rules.mk
10#######################################
11
12###########################################################
13## Define PRIVATE_ variables used by multiple module types
14###########################################################
15$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
16 $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
17
18ifeq ($(strip $(LOCAL_CC)),)
19 LOCAL_CC := $($(my_prefix)CC)
20endif
21$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(LOCAL_CC)
22
23ifeq ($(strip $(LOCAL_CXX)),)
24 LOCAL_CXX := $($(my_prefix)CXX)
25endif
26$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(LOCAL_CXX)
27
28# TODO: support a mix of standard extensions so that this isn't necessary
29LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
30ifeq ($(LOCAL_CPP_EXTENSION),)
31 LOCAL_CPP_EXTENSION := .cpp
32endif
33$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION)
34
35# Certain modules like libdl have to have symbols resolved at runtime and blow
36# up if --no-undefined is passed to the linker.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080037ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070038ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),)
39 LOCAL_LDFLAGS := $(LOCAL_LDFLAGS) $($(my_prefix)NO_UNDEFINED_LDFLAGS)
40endif
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080041endif
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070042
43###########################################################
44## Define arm-vs-thumb-mode flags.
45###########################################################
46LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
47arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
48normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
49
50# Read the values from something like TARGET_arm_release_CFLAGS or
51# TARGET_thumb_debug_CFLAGS. HOST_(arm|thumb)_(release|debug)_CFLAGS
52# values aren't actually used (although they are usually empty).
53arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_$($(my_prefix)BUILD_TYPE)_CFLAGS)
54normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_$($(my_prefix)BUILD_TYPE)_CFLAGS)
55
56###########################################################
57## Define per-module debugging flags. Users can turn on
58## debugging for a particular module by setting DEBUG_MODULE_ModuleName
59## to a non-empty value in their environment or buildspec.mk,
60## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
61## debug flags that they want to use.
62###########################################################
63ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
64 debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
65else
66 debug_cflags :=
67endif
68
69###########################################################
70## Stuff source generated from one-off tools
71###########################################################
72$(LOCAL_GENERATED_SOURCES): PRIVATE_MODULE := $(LOCAL_MODULE)
73
74ALL_GENERATED_SOURCES += $(LOCAL_GENERATED_SOURCES)
75
76
77###########################################################
78## YACC: Compile .y files to .cpp and the to .o.
79###########################################################
80
81yacc_sources := $(filter %.y,$(LOCAL_SRC_FILES))
82yacc_cpps := $(addprefix \
83 $(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION)))
84yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h)
85yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o)
86
87ifneq ($(strip $(yacc_cpps)),)
88$(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
89 $(TOPDIR)$(LOCAL_PATH)/%.y \
90 $(lex_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
91 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
92$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
93
94$(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
95 $(transform-$(PRIVATE_HOST)cpp-to-o)
96endif
97
98###########################################################
99## LEX: Compile .l files to .cpp and then to .o.
100###########################################################
101
102lex_sources := $(filter %.l,$(LOCAL_SRC_FILES))
103lex_cpps := $(addprefix \
104 $(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION)))
105lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o)
106
107ifneq ($(strip $(lex_cpps)),)
108$(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
109 $(TOPDIR)$(LOCAL_PATH)/%.l
110 $(transform-l-to-cpp)
111
112$(lex_objects): $(intermediates)/%.o: \
113 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \
114 $(PRIVATE_ADDITIONAL_DEPENDENCIES) \
115 $(yacc_headers)
116 $(transform-$(PRIVATE_HOST)cpp-to-o)
117endif
118
119###########################################################
120## C++: Compile .cpp files to .o.
121###########################################################
122
123# we also do this on host modules and sim builds, even though
124# it's not really arm, because there are files that are shared.
125cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(LOCAL_SRC_FILES)))
126cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o))
127
128cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES))
129cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
130
131$(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
132$(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
133$(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
134$(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
135
136cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects)
137
138ifneq ($(strip $(cpp_objects)),)
139$(cpp_objects): $(intermediates)/%.o: \
140 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
141 $(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
142 $(transform-$(PRIVATE_HOST)cpp-to-o)
143-include $(cpp_objects:%.o=%.P)
144endif
145
146###########################################################
147## C++: Compile generated .cpp files to .o.
148###########################################################
149
150gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_GENERATED_SOURCES))
151gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
152
153ifneq ($(strip $(gen_cpp_objects)),)
154# Compile all generated files as thumb.
155# TODO: support compiling certain generated files as arm.
156$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
157$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
158$(gen_cpp_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
159 $(transform-$(PRIVATE_HOST)cpp-to-o)
160-include $(gen_cpp_objects:%.o=%.P)
161endif
162
163###########################################################
164## S: Compile generated .S and .s files to .o.
165###########################################################
166
167gen_S_sources := $(filter %.S,$(LOCAL_GENERATED_SOURCES))
168gen_S_objects := $(gen_S_sources:%.S=%.o)
169
170ifneq ($(strip $(gen_S_sources)),)
171$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S $(PRIVATE_ADDITIONAL_DEPENDENCIES)
172 $(transform-$(PRIVATE_HOST)s-to-o)
173-include $(gen_S_objects:%.o=%.P)
174endif
175
176gen_s_sources := $(filter %.s,$(LOCAL_GENERATED_SOURCES))
177gen_s_objects := $(gen_s_sources:%.s=%.o)
178
179ifneq ($(strip $(gen_s_objects)),)
180$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s $(PRIVATE_ADDITIONAL_DEPENDENCIES)
181 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
182-include $(gen_s_objects:%.o=%.P)
183endif
184
185gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
186
187###########################################################
188## C: Compile .c files to .o.
189###########################################################
190
191c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(LOCAL_SRC_FILES)))
192c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o))
193
194c_normal_sources := $(filter %.c,$(LOCAL_SRC_FILES))
195c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
196
197$(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
198$(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
199$(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
200$(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
201
202c_objects := $(c_arm_objects) $(c_normal_objects)
203
204ifneq ($(strip $(c_objects)),)
205$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
206 $(transform-$(PRIVATE_HOST)c-to-o)
207-include $(c_objects:%.o=%.P)
208endif
209
210###########################################################
211## AS: Compile .S files to .o.
212###########################################################
213
214asm_sources_S := $(filter %.S,$(LOCAL_SRC_FILES))
215asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
216
217ifneq ($(strip $(asm_objects_S)),)
218$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S $(PRIVATE_ADDITIONAL_DEPENDENCIES)
219 $(transform-$(PRIVATE_HOST)s-to-o)
220-include $(asm_objects_S:%.o=%.P)
221endif
222
223asm_sources_s := $(filter %.s,$(LOCAL_SRC_FILES))
224asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
225
226ifneq ($(strip $(asm_objects_s)),)
227$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s $(PRIVATE_ADDITIONAL_DEPENDENCIES)
228 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
229-include $(asm_objects_s:%.o=%.P)
230endif
231
232asm_objects := $(asm_objects_S) $(asm_objects_s)
233
234
235###########################################################
236## Common object handling.
237###########################################################
238
239# some rules depend on asm_objects being first. If your code depends on
240# being first, it's reasonable to require it to be assembly
241all_objects := \
242 $(asm_objects) \
243 $(cpp_objects) \
244 $(gen_cpp_objects) \
245 $(gen_asm_objects) \
246 $(c_objects) \
247 $(yacc_objects) \
248 $(lex_objects) \
249 $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
250
251LOCAL_C_INCLUDES += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(base_intermediates)
252
253$(all_objects) : | $(LOCAL_GENERATED_SOURCES)
254ALL_C_CPP_ETC_OBJECTS += $(all_objects)
255
256###########################################################
257## Copy headers to the install tree
258###########################################################
259include $(BUILD_COPY_HEADERS)
260
261###########################################################
262# Standard library handling.
263#
264# On the target, we compile with -nostdlib, so we must add in the
265# default system shared libraries, unless they have requested not
266# to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value. One would
267# supply that, for example, when building libc itself.
268###########################################################
269ifndef LOCAL_IS_HOST_MODULE
270 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
271 LOCAL_SHARED_LIBRARIES += $($(my_prefix)DEFAULT_SYSTEM_SHARED_LIBRARIES)
272 else
273 LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
274 endif
275endif
276
277# Logging used to be part of libcutils (target) and libutils (sim);
278# hack modules that use those other libs to also include liblog.
279# All of this complexity is to make sure that liblog only appears
280# once, and appears just before libcutils or libutils on the link
281# line.
282# TODO: remove this hack and change all modules to use liblog
283# when necessary.
284define insert-liblog
285 $(if $(filter liblog,$(1)),$(1), \
286 $(if $(filter libcutils,$(1)), \
287 $(patsubst libcutils,liblog libcutils,$(1)) \
288 , \
289 $(patsubst libutils,liblog libutils,$(1)) \
290 ) \
291 )
292endef
293ifneq (,$(filter libcutils libutils,$(LOCAL_SHARED_LIBRARIES)))
294 LOCAL_SHARED_LIBRARIES := $(call insert-liblog,$(LOCAL_SHARED_LIBRARIES))
295endif
296ifneq (,$(filter libcutils libutils,$(LOCAL_STATIC_LIBRARIES)))
297 LOCAL_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_STATIC_LIBRARIES))
298endif
299ifneq (,$(filter libcutils libutils,$(LOCAL_WHOLE_STATIC_LIBRARIES)))
300 LOCAL_WHOLE_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_WHOLE_STATIC_LIBRARIES))
301endif
302
303###########################################################
304# The list of libraries that this module will link against are in
305# these variables. Each is a list of bare module names like "libc libm".
306#
307# LOCAL_SHARED_LIBRARIES
308# LOCAL_STATIC_LIBRARIES
309# LOCAL_WHOLE_STATIC_LIBRARIES
310#
311# We need to convert the bare names into the dependencies that
312# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
313# LOCAL_BUILT_MODULE should depend on the BUILT versions of the
314# libraries, so that simply building this module doesn't force
315# an install of a library. Similarly, LOCAL_INSTALLED_MODULE
316# should depend on the INSTALLED versions of the libraries so
317# that they get installed when this module does.
318###########################################################
319# NOTE:
320# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
321# module without leaving anything out, which is useful for turning
322# a collection of .a files into a .so file. Linking against a
323# normal STATIC_LIBRARY will only pull in code/symbols that are
324# referenced by the module. (see gcc/ld's --whole-archive option)
325###########################################################
326
327# Get the list of BUILT libraries, which are under
328# various intermediates directories.
329so_suffix := $($(my_prefix)SHLIB_SUFFIX)
330a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
331
332built_shared_libraries := \
333 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
334 $(addsuffix $(so_suffix), \
335 $(LOCAL_SHARED_LIBRARIES)))
336
337built_static_libraries := \
338 $(foreach lib,$(LOCAL_STATIC_LIBRARIES), \
339 $(call intermediates-dir-for, \
340 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
341
342built_whole_libraries := \
343 $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \
344 $(call intermediates-dir-for, \
345 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
346
347# Get the list of INSTALLED libraries. Strip off the various
348# intermediates directories and point to the common lib dirs.
349installed_shared_libraries := \
350 $(addprefix $($(my_prefix)OUT_SHARED_LIBRARIES)/, \
351 $(notdir $(built_shared_libraries)))
352
353# We don't care about installed static libraries, since the
354# libraries have already been linked into the module at that point.
355# We do, however, care about the NOTICE files for any static
356# libraries that we use. (see notice_files.make)
357
358installed_static_library_notice_file_targets := \
359 $(foreach lib,$(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
360 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib))
361
362###########################################################
363# Rule-specific variable definitions
364###########################################################
365$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
366$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS)
367$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS)
368$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS)
369$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
370$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(LOCAL_C_INCLUDES)
371$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(LOCAL_LDFLAGS)
372$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS)
373
374# this is really the way to get the files onto the command line instead
375# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
376$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
377$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
378$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
379$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects)
380
381###########################################################
382# Define library dependencies.
383###########################################################
384# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
385all_libraries := \
386 $(built_shared_libraries) \
387 $(built_static_libraries) \
388 $(built_whole_libraries)
389
390# Make LOCAL_INSTALLED_MODULE depend on the installed versions of the
391# libraries so they get installed along with it. We don't need to
392# rebuild it when installing it, though, so this can be an order-only
393# dependency.
394$(LOCAL_INSTALLED_MODULE): | $(installed_shared_libraries)
395
396# Also depend on the notice files for any static libraries that
397# are linked into this module. This will force them to be installed
398# when this module is.
399$(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets)