1 ###########################################################
2 ## Standard rules for building binary object files from
3 ## asm/c/cpp/yacc/lex source files.
5 ## The list of object files is exported in $(all_objects).
6 ###########################################################
8 #######################################
9 include $(BUILD_SYSTEM)/base_rules.mk
10 #######################################
12 ####################################################
13 ## Add FDO flags if FDO is turned on and supported
14 ####################################################
15 ifeq ($(strip $(LOCAL_NO_FDO_SUPPORT)),)
16 LOCAL_CFLAGS += $(TARGET_FDO_CFLAGS)
17 LOCAL_CPPFLAGS += $(TARGET_FDO_CFLAGS)
18 LOCAL_LDFLAGS += $(TARGET_FDO_CFLAGS)
21 ###########################################################
22 ## Define PRIVATE_ variables used by multiple module types
23 ###########################################################
24 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
25 $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
27 ifeq ($(strip $(LOCAL_CC)),)
28 LOCAL_CC := $($(my_prefix)CC)
30 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(LOCAL_CC)
32 ifeq ($(strip $(LOCAL_CXX)),)
33 LOCAL_CXX := $($(my_prefix)CXX)
35 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(LOCAL_CXX)
37 # TODO: support a mix of standard extensions so that this isn't necessary
38 LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
39 ifeq ($(LOCAL_CPP_EXTENSION),)
40 LOCAL_CPP_EXTENSION := .cpp
42 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION)
44 # Certain modules like libdl have to have symbols resolved at runtime and blow
45 # up if --no-undefined is passed to the linker.
46 ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
47 ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),)
48 LOCAL_LDFLAGS := $(LOCAL_LDFLAGS) $($(my_prefix)NO_UNDEFINED_LDFLAGS)
52 ###########################################################
53 ## Define arm-vs-thumb-mode flags.
54 ###########################################################
55 LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
56 arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
57 normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
59 # Read the values from something like TARGET_arm_CFLAGS or
60 # TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't
61 # actually used (although they are usually empty).
62 arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CFLAGS)
63 normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_CFLAGS)
65 ###########################################################
66 ## Define per-module debugging flags. Users can turn on
67 ## debugging for a particular module by setting DEBUG_MODULE_ModuleName
68 ## to a non-empty value in their environment or buildspec.mk,
69 ## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
70 ## debug flags that they want to use.
71 ###########################################################
72 ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
73 debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
78 ###########################################################
79 ## Stuff source generated from one-off tools
80 ###########################################################
81 $(LOCAL_GENERATED_SOURCES): PRIVATE_MODULE := $(LOCAL_MODULE)
83 ALL_GENERATED_SOURCES += $(LOCAL_GENERATED_SOURCES)
86 ###########################################################
87 ## YACC: Compile .y files to .cpp and the to .o.
88 ###########################################################
90 yacc_sources := $(filter %.y,$(LOCAL_SRC_FILES))
91 yacc_cpps := $(addprefix \
92 $(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION)))
93 yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h)
94 yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o)
96 ifneq ($(strip $(yacc_cpps)),)
97 $(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
98 $(TOPDIR)$(LOCAL_PATH)/%.y \
99 $(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
100 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
101 $(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
103 $(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
104 $(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
105 $(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
106 $(transform-$(PRIVATE_HOST)cpp-to-o)
109 ###########################################################
110 ## LEX: Compile .l files to .cpp and then to .o.
111 ###########################################################
113 lex_sources := $(filter %.l,$(LOCAL_SRC_FILES))
114 lex_cpps := $(addprefix \
115 $(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION)))
116 lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o)
118 ifneq ($(strip $(lex_cpps)),)
119 $(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
120 $(TOPDIR)$(LOCAL_PATH)/%.l
121 $(transform-l-to-cpp)
123 $(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
124 $(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
125 $(lex_objects): $(intermediates)/%.o: \
126 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \
127 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
129 $(transform-$(PRIVATE_HOST)cpp-to-o)
132 ###########################################################
133 ## C++: Compile .cpp files to .o.
134 ###########################################################
136 # we also do this on host modules and sim builds, even though
137 # it's not really arm, because there are files that are shared.
138 cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(LOCAL_SRC_FILES)))
139 cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o))
141 cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES))
142 cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
144 $(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
145 $(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
146 $(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
147 $(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
149 cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects)
151 ifneq ($(strip $(cpp_objects)),)
152 $(cpp_objects): $(intermediates)/%.o: \
153 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
154 $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
155 $(transform-$(PRIVATE_HOST)cpp-to-o)
156 -include $(cpp_objects:%.o=%.P)
159 ###########################################################
160 ## C++: Compile generated .cpp files to .o.
161 ###########################################################
163 gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_GENERATED_SOURCES))
164 gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
166 ifneq ($(strip $(gen_cpp_objects)),)
167 # Compile all generated files as thumb.
168 # TODO: support compiling certain generated files as arm.
169 $(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
170 $(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
171 $(gen_cpp_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
172 $(transform-$(PRIVATE_HOST)cpp-to-o)
173 -include $(gen_cpp_objects:%.o=%.P)
176 ###########################################################
177 ## S: Compile generated .S and .s files to .o.
178 ###########################################################
180 gen_S_sources := $(filter %.S,$(LOCAL_GENERATED_SOURCES))
181 gen_S_objects := $(gen_S_sources:%.S=%.o)
183 ifneq ($(strip $(gen_S_sources)),)
184 $(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S $(LOCAL_ADDITIONAL_DEPENDENCIES)
185 $(transform-$(PRIVATE_HOST)s-to-o)
186 -include $(gen_S_objects:%.o=%.P)
189 gen_s_sources := $(filter %.s,$(LOCAL_GENERATED_SOURCES))
190 gen_s_objects := $(gen_s_sources:%.s=%.o)
192 ifneq ($(strip $(gen_s_objects)),)
193 $(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s $(LOCAL_ADDITIONAL_DEPENDENCIES)
194 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
195 -include $(gen_s_objects:%.o=%.P)
198 gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
200 ###########################################################
201 ## C: Compile .c files to .o.
202 ###########################################################
204 c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(LOCAL_SRC_FILES)))
205 c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o))
207 c_normal_sources := $(filter %.c,$(LOCAL_SRC_FILES))
208 c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
210 $(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
211 $(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
212 $(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
213 $(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
215 c_objects := $(c_arm_objects) $(c_normal_objects)
217 ifneq ($(strip $(c_objects)),)
218 $(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
219 $(transform-$(PRIVATE_HOST)c-to-o)
220 -include $(c_objects:%.o=%.P)
223 ###########################################################
224 ## C: Compile generated .c files to .o.
225 ###########################################################
227 gen_c_sources := $(filter %.c,$(LOCAL_GENERATED_SOURCES))
228 gen_c_objects := $(gen_c_sources:%.c=%.o)
230 ifneq ($(strip $(gen_c_objects)),)
231 # Compile all generated files as thumb.
232 # TODO: support compiling certain generated files as arm.
233 $(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
234 $(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
235 $(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
236 $(transform-$(PRIVATE_HOST)c-to-o)
237 -include $(gen_c_objects:%.o=%.P)
240 ###########################################################
241 ## ObjC: Compile .m files to .o
242 ###########################################################
244 objc_sources := $(filter %.m,$(LOCAL_SRC_FILES))
245 objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
247 ifneq ($(strip $(objc_objects)),)
248 $(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
249 $(transform-$(PRIVATE_HOST)m-to-o)
250 -include $(objc_objects:%.o=%.P)
253 ###########################################################
254 ## AS: Compile .S files to .o.
255 ###########################################################
257 asm_sources_S := $(filter %.S,$(LOCAL_SRC_FILES))
258 asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
260 ifneq ($(strip $(asm_objects_S)),)
261 $(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S $(LOCAL_ADDITIONAL_DEPENDENCIES)
262 $(transform-$(PRIVATE_HOST)s-to-o)
263 -include $(asm_objects_S:%.o=%.P)
266 asm_sources_s := $(filter %.s,$(LOCAL_SRC_FILES))
267 asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
269 ifneq ($(strip $(asm_objects_s)),)
270 $(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s $(LOCAL_ADDITIONAL_DEPENDENCIES)
271 $(transform-$(PRIVATE_HOST)s-to-o-no-deps)
272 -include $(asm_objects_s:%.o=%.P)
275 asm_objects := $(asm_objects_S) $(asm_objects_s)
278 ###########################################################
279 ## Common object handling.
280 ###########################################################
282 # some rules depend on asm_objects being first. If your code depends on
283 # being first, it's reasonable to require it to be assembly
293 $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
295 LOCAL_C_INCLUDES += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(base_intermediates)
297 $(all_objects) : | $(LOCAL_GENERATED_SOURCES)
298 ALL_C_CPP_ETC_OBJECTS += $(all_objects)
300 ###########################################################
301 ## Copy headers to the install tree
302 ###########################################################
303 include $(BUILD_COPY_HEADERS)
305 ###########################################################
306 # Standard library handling.
308 # On the target, we compile with -nostdlib, so we must add in the
309 # default system shared libraries, unless they have requested not
310 # to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value. One would
311 # supply that, for example, when building libc itself.
312 ###########################################################
313 ifndef LOCAL_IS_HOST_MODULE
314 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
315 LOCAL_SHARED_LIBRARIES += $($(my_prefix)DEFAULT_SYSTEM_SHARED_LIBRARIES)
317 LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
321 # Logging used to be part of libcutils (target) and libutils (sim);
322 # hack modules that use those other libs to also include liblog.
323 # All of this complexity is to make sure that liblog only appears
324 # once, and appears just before libcutils or libutils on the link
326 # TODO: remove this hack and change all modules to use liblog
329 $(if $(filter liblog,$(1)),$(1), \
330 $(if $(filter libcutils,$(1)), \
331 $(patsubst libcutils,liblog libcutils,$(1)) \
333 $(patsubst libutils,liblog libutils,$(1)) \
337 ifneq (,$(filter libcutils libutils,$(LOCAL_SHARED_LIBRARIES)))
338 LOCAL_SHARED_LIBRARIES := $(call insert-liblog,$(LOCAL_SHARED_LIBRARIES))
340 ifneq (,$(filter libcutils libutils,$(LOCAL_STATIC_LIBRARIES)))
341 LOCAL_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_STATIC_LIBRARIES))
343 ifneq (,$(filter libcutils libutils,$(LOCAL_WHOLE_STATIC_LIBRARIES)))
344 LOCAL_WHOLE_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_WHOLE_STATIC_LIBRARIES))
347 ###########################################################
348 # The list of libraries that this module will link against are in
349 # these variables. Each is a list of bare module names like "libc libm".
351 # LOCAL_SHARED_LIBRARIES
352 # LOCAL_STATIC_LIBRARIES
353 # LOCAL_WHOLE_STATIC_LIBRARIES
355 # We need to convert the bare names into the dependencies that
356 # we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
357 # LOCAL_BUILT_MODULE should depend on the BUILT versions of the
358 # libraries, so that simply building this module doesn't force
359 # an install of a library. Similarly, LOCAL_INSTALLED_MODULE
360 # should depend on the INSTALLED versions of the libraries so
361 # that they get installed when this module does.
362 ###########################################################
364 # WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
365 # module without leaving anything out, which is useful for turning
366 # a collection of .a files into a .so file. Linking against a
367 # normal STATIC_LIBRARY will only pull in code/symbols that are
368 # referenced by the module. (see gcc/ld's --whole-archive option)
369 ###########################################################
371 # Get the list of BUILT libraries, which are under
372 # various intermediates directories.
373 so_suffix := $($(my_prefix)SHLIB_SUFFIX)
374 a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
376 built_shared_libraries := \
377 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
378 $(addsuffix $(so_suffix), \
379 $(LOCAL_SHARED_LIBRARIES)))
381 built_static_libraries := \
382 $(foreach lib,$(LOCAL_STATIC_LIBRARIES), \
383 $(call intermediates-dir-for, \
384 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
386 built_whole_libraries := \
387 $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \
388 $(call intermediates-dir-for, \
389 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix))
391 # Get the list of INSTALLED libraries. Strip off the various
392 # intermediates directories and point to the common lib dirs.
393 installed_shared_libraries := \
394 $(addprefix $($(my_prefix)OUT_SHARED_LIBRARIES)/, \
395 $(notdir $(built_shared_libraries)))
397 # We don't care about installed static libraries, since the
398 # libraries have already been linked into the module at that point.
399 # We do, however, care about the NOTICE files for any static
400 # libraries that we use. (see notice_files.make)
402 installed_static_library_notice_file_targets := \
403 $(foreach lib,$(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \
404 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib))
406 ###########################################################
407 # Rule-specific variable definitions
408 ###########################################################
409 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
410 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS)
411 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS)
412 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS)
413 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
414 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(LOCAL_C_INCLUDES)
415 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(LOCAL_LDFLAGS)
416 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS)
418 # this is really the way to get the files onto the command line instead
419 # of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
420 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
421 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
422 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
423 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects)
425 ###########################################################
426 # Define library dependencies.
427 ###########################################################
428 # all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
430 $(built_shared_libraries) \
431 $(built_static_libraries) \
432 $(built_whole_libraries)
434 # Make LOCAL_INSTALLED_MODULE depend on the installed versions of the
435 # libraries so they get installed along with it. We don't need to
436 # rebuild it when installing it, though, so this can be an order-only
438 $(LOCAL_INSTALLED_MODULE): | $(installed_shared_libraries)
440 # Also depend on the notice files for any static libraries that
441 # are linked into this module. This will force them to be installed
442 # when this module is.
443 $(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets)