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