The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 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 | |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 8 | ###################################### |
| 9 | ## Sanity check for LOCAL_NDK_VERSION |
| 10 | ###################################### |
| 11 | my_ndk_version_root := |
Ying Wang | 75b2857 | 2010-07-16 11:34:36 -0700 | [diff] [blame] | 12 | ifeq ($(TARGET_SIMULATOR),true) |
| 13 | # NDK does not support sim build. |
| 14 | LOCAL_NDK_VERSION := |
| 15 | endif |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 16 | ifdef LOCAL_NDK_VERSION |
| 17 | ifdef LOCAL_IS_HOST_MODULE |
| 18 | $(error $(LOCAL_PATH): LOCAL_NDK_VERSION can not be used in host module) |
| 19 | endif |
| 20 | ifneq ($(filter-out SHARED_LIBRARIES STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)),) |
| 21 | $(error $(LOCAL_PATH): LOCAL_NDK_VERSION can only be used to build target shared/static libraries, \ |
| 22 | while your module is of class $(LOCAL_MODULE_CLASS)) |
| 23 | endif |
| 24 | ifeq ($(filter $(LOCAL_NDK_VERSION),$(TARGET_AVAILABLE_NDK_VERSIONS)),) |
| 25 | $(error $(LOCAL_PATH): Invalid LOCAL_NDK_VERSION '$(LOCAL_NDK_VERSION)' \ |
| 26 | Choices are $(TARGET_AVAILABLE_NDK_VERSIONS)) |
| 27 | endif |
| 28 | ifndef LOCAL_SDK_VERSION |
| 29 | $(error $(LOCAL_PATH): LOCAL_NDK_VERSION must be defined with LOCAL_SDK_VERSION) |
| 30 | endif |
Ying Wang | 02c9813 | 2010-09-23 17:59:36 -0700 | [diff] [blame] | 31 | my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/android-ndk-r$(LOCAL_NDK_VERSION)/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_ARCH) |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 32 | ifeq ($(wildcard $(my_ndk_version_root)),) |
| 33 | $(error $(LOCAL_PATH): ndk version root does not exist: $(my_ndk_version_root)) |
| 34 | endif |
| 35 | endif |
| 36 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 37 | ####################################### |
| 38 | include $(BUILD_SYSTEM)/base_rules.mk |
| 39 | ####################################### |
| 40 | |
Jing Yu | 2dcc806 | 2009-09-21 16:31:50 -0700 | [diff] [blame] | 41 | #################################################### |
| 42 | ## Add FDO flags if FDO is turned on and supported |
| 43 | #################################################### |
| 44 | ifeq ($(strip $(LOCAL_NO_FDO_SUPPORT)),) |
| 45 | LOCAL_CFLAGS += $(TARGET_FDO_CFLAGS) |
| 46 | LOCAL_CPPFLAGS += $(TARGET_FDO_CFLAGS) |
| 47 | LOCAL_LDFLAGS += $(TARGET_FDO_CFLAGS) |
| 48 | endif |
| 49 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 50 | ########################################################### |
Jim Huang | 20d1ba6 | 2010-10-14 16:15:56 +0800 | [diff] [blame] | 51 | ## Explicitly declare assembly-only __ASSEMBLY__ macro for |
| 52 | ## assembly source |
| 53 | ########################################################### |
| 54 | LOCAL_ASFLAGS += -D__ASSEMBLY__ |
| 55 | |
| 56 | ########################################################### |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 57 | ## Define PRIVATE_ variables from global vars |
| 58 | ########################################################### |
| 59 | ifdef LOCAL_NDK_VERSION |
| 60 | my_target_project_includes := |
| 61 | my_target_c_inclues := $(my_ndk_version_root)/usr/include |
| 62 | # TODO: more reliable way to remove platform stuff. |
| 63 | my_target_global_cflags := $(filter-out -include -I system/%, $(TARGET_GLOBAL_CFLAGS)) |
| 64 | my_target_global_cppflags := $(filter-out -include -I system/%, $(TARGET_GLOBAL_CPPFLAGS)) |
| 65 | else |
| 66 | my_target_project_includes := $(TARGET_PROJECT_INCLUDES) |
| 67 | my_target_c_inclues := $(TARGET_C_INCLUDES) |
| 68 | my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS) |
| 69 | my_target_global_cppflags := $(TARGET_GLOBAL_CPPFLAGS) |
| 70 | endif |
| 71 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes) |
| 72 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_inclues) |
| 73 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags) |
| 74 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags) |
| 75 | |
| 76 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 77 | ## Define PRIVATE_ variables used by multiple module types |
| 78 | ########################################################### |
| 79 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \ |
| 80 | $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)) |
| 81 | |
| 82 | ifeq ($(strip $(LOCAL_CC)),) |
| 83 | LOCAL_CC := $($(my_prefix)CC) |
| 84 | endif |
| 85 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(LOCAL_CC) |
| 86 | |
| 87 | ifeq ($(strip $(LOCAL_CXX)),) |
| 88 | LOCAL_CXX := $($(my_prefix)CXX) |
| 89 | endif |
| 90 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(LOCAL_CXX) |
| 91 | |
| 92 | # TODO: support a mix of standard extensions so that this isn't necessary |
| 93 | LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) |
| 94 | ifeq ($(LOCAL_CPP_EXTENSION),) |
| 95 | LOCAL_CPP_EXTENSION := .cpp |
| 96 | endif |
| 97 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION) |
| 98 | |
| 99 | # Certain modules like libdl have to have symbols resolved at runtime and blow |
| 100 | # up if --no-undefined is passed to the linker. |
| 101 | ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),) |
| 102 | ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),) |
| 103 | LOCAL_LDFLAGS := $(LOCAL_LDFLAGS) $($(my_prefix)NO_UNDEFINED_LDFLAGS) |
| 104 | endif |
| 105 | endif |
| 106 | |
| 107 | ########################################################### |
| 108 | ## Define arm-vs-thumb-mode flags. |
| 109 | ########################################################### |
| 110 | LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE)) |
Chih-Wei Huang | 0d09e58 | 2010-07-09 10:07:52 +0800 | [diff] [blame] | 111 | ifeq ($(TARGET_ARCH),arm) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 112 | arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm) |
| 113 | normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb) |
| 114 | |
Dave Bort | 9528248 | 2009-04-23 18:44:55 -0700 | [diff] [blame] | 115 | # Read the values from something like TARGET_arm_CFLAGS or |
| 116 | # TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't |
| 117 | # actually used (although they are usually empty). |
| 118 | arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CFLAGS) |
| 119 | normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_CFLAGS) |
Chih-Wei Huang | 0d09e58 | 2010-07-09 10:07:52 +0800 | [diff] [blame] | 120 | else |
| 121 | arm_objects_mode := |
| 122 | normal_objects_mode := |
| 123 | arm_objects_cflags := |
| 124 | normal_objects_cflags := |
| 125 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 126 | |
| 127 | ########################################################### |
| 128 | ## Define per-module debugging flags. Users can turn on |
| 129 | ## debugging for a particular module by setting DEBUG_MODULE_ModuleName |
| 130 | ## to a non-empty value in their environment or buildspec.mk, |
| 131 | ## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the |
| 132 | ## debug flags that they want to use. |
| 133 | ########################################################### |
| 134 | ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE)) |
| 135 | debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS) |
| 136 | else |
| 137 | debug_cflags := |
| 138 | endif |
| 139 | |
| 140 | ########################################################### |
| 141 | ## Stuff source generated from one-off tools |
| 142 | ########################################################### |
| 143 | $(LOCAL_GENERATED_SOURCES): PRIVATE_MODULE := $(LOCAL_MODULE) |
| 144 | |
| 145 | ALL_GENERATED_SOURCES += $(LOCAL_GENERATED_SOURCES) |
| 146 | |
| 147 | |
| 148 | ########################################################### |
Jean-Baptiste Queru | 79ee7bf | 2011-01-27 12:19:43 -0800 | [diff] [blame] | 149 | ## Compile the .proto files to .cc and then to .o |
| 150 | ########################################################### |
| 151 | proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES)) |
| 152 | proto_generated_objects := |
| 153 | proto_generated_headers := |
| 154 | ifneq ($(proto_sources),) |
| 155 | proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources)) |
| 156 | proto_generated_cc_sources_dir := $(intermediates)/proto |
| 157 | proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \ |
| 158 | $(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath))) |
| 159 | proto_generated_objects := $(patsubst %.cc,%.o, $(proto_generated_cc_sources)) |
| 160 | |
| 161 | $(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP) |
| 162 | $(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir) |
Jean-Baptiste Queru | c61d4c9 | 2011-01-27 13:49:30 -0800 | [diff] [blame] | 163 | $(proto_generated_cc_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) |
Jean-Baptiste Queru | 79ee7bf | 2011-01-27 12:19:43 -0800 | [diff] [blame] | 164 | $(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC) |
| 165 | $(transform-proto-to-cc) |
| 166 | |
| 167 | proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources)) |
| 168 | $(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc |
| 169 | |
| 170 | $(proto_generated_cc_sources): PRIVATE_ARM_MODE := $(normal_objects_mode) |
| 171 | $(proto_generated_cc_sources): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) |
| 172 | $(proto_generated_objects): $(proto_generated_cc_sources_dir)/%.o: $(proto_generated_cc_sources_dir)/%.cc |
| 173 | $(transform-$(PRIVATE_HOST)cpp-to-o) |
| 174 | -include $(proto_generated_objects:%.o=%.P) |
| 175 | |
| 176 | LOCAL_C_INCLUDES += external/protobuf/src $(proto_generated_cc_sources_dir) |
| 177 | LOCAL_CFLAGS += -DGOOGLE_PROTOBUF_NO_RTTI |
| 178 | ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full) |
| 179 | LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-full |
| 180 | else |
| 181 | LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-lite |
| 182 | endif |
| 183 | endif |
| 184 | |
| 185 | |
| 186 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 187 | ## YACC: Compile .y files to .cpp and the to .o. |
| 188 | ########################################################### |
| 189 | |
| 190 | yacc_sources := $(filter %.y,$(LOCAL_SRC_FILES)) |
| 191 | yacc_cpps := $(addprefix \ |
| 192 | $(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION))) |
| 193 | yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h) |
| 194 | yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o) |
| 195 | |
| 196 | ifneq ($(strip $(yacc_cpps)),) |
| 197 | $(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ |
| 198 | $(TOPDIR)$(LOCAL_PATH)/%.y \ |
Patrick Scott | d033d57 | 2009-05-19 18:13:58 -0400 | [diff] [blame] | 199 | $(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 200 | $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION)) |
| 201 | $(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION) |
| 202 | |
| 203 | $(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) |
| 204 | $(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) |
| 205 | $(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) |
| 206 | $(transform-$(PRIVATE_HOST)cpp-to-o) |
| 207 | endif |
| 208 | |
| 209 | ########################################################### |
| 210 | ## LEX: Compile .l files to .cpp and then to .o. |
| 211 | ########################################################### |
| 212 | |
| 213 | lex_sources := $(filter %.l,$(LOCAL_SRC_FILES)) |
| 214 | lex_cpps := $(addprefix \ |
| 215 | $(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION))) |
| 216 | lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o) |
| 217 | |
| 218 | ifneq ($(strip $(lex_cpps)),) |
| 219 | $(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ |
| 220 | $(TOPDIR)$(LOCAL_PATH)/%.l |
| 221 | $(transform-l-to-cpp) |
| 222 | |
| 223 | $(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) |
| 224 | $(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) |
| 225 | $(lex_objects): $(intermediates)/%.o: \ |
| 226 | $(intermediates)/%$(LOCAL_CPP_EXTENSION) \ |
Patrick Scott | d033d57 | 2009-05-19 18:13:58 -0400 | [diff] [blame] | 227 | $(LOCAL_ADDITIONAL_DEPENDENCIES) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 228 | $(yacc_headers) |
| 229 | $(transform-$(PRIVATE_HOST)cpp-to-o) |
| 230 | endif |
| 231 | |
| 232 | ########################################################### |
| 233 | ## C++: Compile .cpp files to .o. |
| 234 | ########################################################### |
| 235 | |
| 236 | # we also do this on host modules and sim builds, even though |
| 237 | # it's not really arm, because there are files that are shared. |
| 238 | cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(LOCAL_SRC_FILES))) |
| 239 | cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o)) |
| 240 | |
| 241 | cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES)) |
| 242 | cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o)) |
| 243 | |
| 244 | $(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode) |
| 245 | $(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags) |
| 246 | $(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) |
| 247 | $(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) |
| 248 | |
| 249 | cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects) |
| 250 | |
| 251 | ifneq ($(strip $(cpp_objects)),) |
| 252 | $(cpp_objects): $(intermediates)/%.o: \ |
| 253 | $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \ |
Jean-Baptiste Queru | 79ee7bf | 2011-01-27 12:19:43 -0800 | [diff] [blame] | 254 | $(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 255 | $(transform-$(PRIVATE_HOST)cpp-to-o) |
| 256 | -include $(cpp_objects:%.o=%.P) |
| 257 | endif |
| 258 | |
| 259 | ########################################################### |
| 260 | ## C++: Compile generated .cpp files to .o. |
| 261 | ########################################################### |
| 262 | |
| 263 | gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_GENERATED_SOURCES)) |
| 264 | gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o) |
| 265 | |
| 266 | ifneq ($(strip $(gen_cpp_objects)),) |
| 267 | # Compile all generated files as thumb. |
| 268 | # TODO: support compiling certain generated files as arm. |
| 269 | $(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) |
| 270 | $(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) |
Jean-Baptiste Queru | 79ee7bf | 2011-01-27 12:19:43 -0800 | [diff] [blame] | 271 | $(gen_cpp_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 272 | $(transform-$(PRIVATE_HOST)cpp-to-o) |
| 273 | -include $(gen_cpp_objects:%.o=%.P) |
| 274 | endif |
| 275 | |
| 276 | ########################################################### |
| 277 | ## S: Compile generated .S and .s files to .o. |
| 278 | ########################################################### |
| 279 | |
| 280 | gen_S_sources := $(filter %.S,$(LOCAL_GENERATED_SOURCES)) |
| 281 | gen_S_objects := $(gen_S_sources:%.S=%.o) |
| 282 | |
| 283 | ifneq ($(strip $(gen_S_sources)),) |
Patrick Scott | d033d57 | 2009-05-19 18:13:58 -0400 | [diff] [blame] | 284 | $(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S $(LOCAL_ADDITIONAL_DEPENDENCIES) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 285 | $(transform-$(PRIVATE_HOST)s-to-o) |
| 286 | -include $(gen_S_objects:%.o=%.P) |
| 287 | endif |
| 288 | |
| 289 | gen_s_sources := $(filter %.s,$(LOCAL_GENERATED_SOURCES)) |
| 290 | gen_s_objects := $(gen_s_sources:%.s=%.o) |
| 291 | |
| 292 | ifneq ($(strip $(gen_s_objects)),) |
Patrick Scott | d033d57 | 2009-05-19 18:13:58 -0400 | [diff] [blame] | 293 | $(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s $(LOCAL_ADDITIONAL_DEPENDENCIES) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 294 | $(transform-$(PRIVATE_HOST)s-to-o-no-deps) |
| 295 | -include $(gen_s_objects:%.o=%.P) |
| 296 | endif |
| 297 | |
| 298 | gen_asm_objects := $(gen_S_objects) $(gen_s_objects) |
| 299 | |
| 300 | ########################################################### |
| 301 | ## C: Compile .c files to .o. |
| 302 | ########################################################### |
| 303 | |
| 304 | c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(LOCAL_SRC_FILES))) |
| 305 | c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o)) |
| 306 | |
| 307 | c_normal_sources := $(filter %.c,$(LOCAL_SRC_FILES)) |
| 308 | c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o)) |
| 309 | |
| 310 | $(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode) |
| 311 | $(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags) |
| 312 | $(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) |
| 313 | $(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) |
| 314 | |
| 315 | c_objects := $(c_arm_objects) $(c_normal_objects) |
| 316 | |
| 317 | ifneq ($(strip $(c_objects)),) |
Jean-Baptiste Queru | 79ee7bf | 2011-01-27 12:19:43 -0800 | [diff] [blame] | 318 | $(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 319 | $(transform-$(PRIVATE_HOST)c-to-o) |
| 320 | -include $(c_objects:%.o=%.P) |
| 321 | endif |
| 322 | |
| 323 | ########################################################### |
Jack Palevich | e7b3e2c | 2009-05-04 14:32:44 -0700 | [diff] [blame] | 324 | ## C: Compile generated .c files to .o. |
| 325 | ########################################################### |
| 326 | |
| 327 | gen_c_sources := $(filter %.c,$(LOCAL_GENERATED_SOURCES)) |
| 328 | gen_c_objects := $(gen_c_sources:%.c=%.o) |
| 329 | |
| 330 | ifneq ($(strip $(gen_c_objects)),) |
| 331 | # Compile all generated files as thumb. |
| 332 | # TODO: support compiling certain generated files as arm. |
| 333 | $(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) |
| 334 | $(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) |
Jean-Baptiste Queru | 79ee7bf | 2011-01-27 12:19:43 -0800 | [diff] [blame] | 335 | $(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES) |
Jack Palevich | e7b3e2c | 2009-05-04 14:32:44 -0700 | [diff] [blame] | 336 | $(transform-$(PRIVATE_HOST)c-to-o) |
| 337 | -include $(gen_c_objects:%.o=%.P) |
| 338 | endif |
| 339 | |
| 340 | ########################################################### |
David 'Digit' Turner | 5dbb529 | 2009-05-14 16:00:09 +0200 | [diff] [blame] | 341 | ## ObjC: Compile .m files to .o |
| 342 | ########################################################### |
| 343 | |
| 344 | objc_sources := $(filter %.m,$(LOCAL_SRC_FILES)) |
| 345 | objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o)) |
| 346 | |
| 347 | ifneq ($(strip $(objc_objects)),) |
Jean-Baptiste Queru | 79ee7bf | 2011-01-27 12:19:43 -0800 | [diff] [blame] | 348 | $(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) $(PRIVATE_ADDITIONAL_DEPENDENCIES) |
David 'Digit' Turner | 5dbb529 | 2009-05-14 16:00:09 +0200 | [diff] [blame] | 349 | $(transform-$(PRIVATE_HOST)m-to-o) |
| 350 | -include $(objc_objects:%.o=%.P) |
| 351 | endif |
| 352 | |
| 353 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 354 | ## AS: Compile .S files to .o. |
| 355 | ########################################################### |
| 356 | |
| 357 | asm_sources_S := $(filter %.S,$(LOCAL_SRC_FILES)) |
| 358 | asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o)) |
| 359 | |
| 360 | ifneq ($(strip $(asm_objects_S)),) |
Patrick Scott | d033d57 | 2009-05-19 18:13:58 -0400 | [diff] [blame] | 361 | $(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S $(LOCAL_ADDITIONAL_DEPENDENCIES) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 362 | $(transform-$(PRIVATE_HOST)s-to-o) |
| 363 | -include $(asm_objects_S:%.o=%.P) |
| 364 | endif |
| 365 | |
| 366 | asm_sources_s := $(filter %.s,$(LOCAL_SRC_FILES)) |
| 367 | asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o)) |
| 368 | |
| 369 | ifneq ($(strip $(asm_objects_s)),) |
Patrick Scott | d033d57 | 2009-05-19 18:13:58 -0400 | [diff] [blame] | 370 | $(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s $(LOCAL_ADDITIONAL_DEPENDENCIES) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 371 | $(transform-$(PRIVATE_HOST)s-to-o-no-deps) |
| 372 | -include $(asm_objects_s:%.o=%.P) |
| 373 | endif |
| 374 | |
| 375 | asm_objects := $(asm_objects_S) $(asm_objects_s) |
| 376 | |
| 377 | |
| 378 | ########################################################### |
| 379 | ## Common object handling. |
| 380 | ########################################################### |
| 381 | |
| 382 | # some rules depend on asm_objects being first. If your code depends on |
| 383 | # being first, it's reasonable to require it to be assembly |
| 384 | all_objects := \ |
| 385 | $(asm_objects) \ |
| 386 | $(cpp_objects) \ |
| 387 | $(gen_cpp_objects) \ |
| 388 | $(gen_asm_objects) \ |
| 389 | $(c_objects) \ |
Jack Palevich | e7b3e2c | 2009-05-04 14:32:44 -0700 | [diff] [blame] | 390 | $(gen_c_objects) \ |
David 'Digit' Turner | 5ca286d | 2011-02-11 16:19:31 +0100 | [diff] [blame] | 391 | $(objc_objects) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 392 | $(yacc_objects) \ |
| 393 | $(lex_objects) \ |
Jean-Baptiste Queru | 79ee7bf | 2011-01-27 12:19:43 -0800 | [diff] [blame] | 394 | $(proto_generated_objects) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 395 | $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES)) |
| 396 | |
| 397 | LOCAL_C_INCLUDES += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(base_intermediates) |
| 398 | |
Ying Wang | bce4b75 | 2010-07-22 15:51:56 -0700 | [diff] [blame] | 399 | ifndef LOCAL_NDK_VERSION |
| 400 | LOCAL_C_INCLUDES += $(JNI_H_INCLUDE) |
| 401 | endif |
| 402 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 403 | $(all_objects) : | $(LOCAL_GENERATED_SOURCES) |
| 404 | ALL_C_CPP_ETC_OBJECTS += $(all_objects) |
| 405 | |
| 406 | ########################################################### |
| 407 | ## Copy headers to the install tree |
| 408 | ########################################################### |
| 409 | include $(BUILD_COPY_HEADERS) |
| 410 | |
| 411 | ########################################################### |
| 412 | # Standard library handling. |
| 413 | # |
| 414 | # On the target, we compile with -nostdlib, so we must add in the |
| 415 | # default system shared libraries, unless they have requested not |
| 416 | # to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value. One would |
| 417 | # supply that, for example, when building libc itself. |
| 418 | ########################################################### |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 419 | ifdef LOCAL_IS_HOST_MODULE |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 420 | ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 421 | LOCAL_SYSTEM_SHARED_LIBRARIES := |
| 422 | endif |
| 423 | else |
| 424 | ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) |
| 425 | LOCAL_SYSTEM_SHARED_LIBRARIES := $($(my_prefix)DEFAULT_SYSTEM_SHARED_LIBRARIES) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 426 | endif |
| 427 | endif |
| 428 | |
| 429 | # Logging used to be part of libcutils (target) and libutils (sim); |
| 430 | # hack modules that use those other libs to also include liblog. |
| 431 | # All of this complexity is to make sure that liblog only appears |
| 432 | # once, and appears just before libcutils or libutils on the link |
| 433 | # line. |
| 434 | # TODO: remove this hack and change all modules to use liblog |
| 435 | # when necessary. |
| 436 | define insert-liblog |
| 437 | $(if $(filter liblog,$(1)),$(1), \ |
| 438 | $(if $(filter libcutils,$(1)), \ |
| 439 | $(patsubst libcutils,liblog libcutils,$(1)) \ |
| 440 | , \ |
| 441 | $(patsubst libutils,liblog libutils,$(1)) \ |
| 442 | ) \ |
| 443 | ) |
| 444 | endef |
| 445 | ifneq (,$(filter libcutils libutils,$(LOCAL_SHARED_LIBRARIES))) |
| 446 | LOCAL_SHARED_LIBRARIES := $(call insert-liblog,$(LOCAL_SHARED_LIBRARIES)) |
| 447 | endif |
| 448 | ifneq (,$(filter libcutils libutils,$(LOCAL_STATIC_LIBRARIES))) |
| 449 | LOCAL_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_STATIC_LIBRARIES)) |
| 450 | endif |
| 451 | ifneq (,$(filter libcutils libutils,$(LOCAL_WHOLE_STATIC_LIBRARIES))) |
| 452 | LOCAL_WHOLE_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_WHOLE_STATIC_LIBRARIES)) |
| 453 | endif |
| 454 | |
| 455 | ########################################################### |
| 456 | # The list of libraries that this module will link against are in |
| 457 | # these variables. Each is a list of bare module names like "libc libm". |
| 458 | # |
| 459 | # LOCAL_SHARED_LIBRARIES |
| 460 | # LOCAL_STATIC_LIBRARIES |
| 461 | # LOCAL_WHOLE_STATIC_LIBRARIES |
| 462 | # |
| 463 | # We need to convert the bare names into the dependencies that |
| 464 | # we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE. |
| 465 | # LOCAL_BUILT_MODULE should depend on the BUILT versions of the |
| 466 | # libraries, so that simply building this module doesn't force |
| 467 | # an install of a library. Similarly, LOCAL_INSTALLED_MODULE |
| 468 | # should depend on the INSTALLED versions of the libraries so |
| 469 | # that they get installed when this module does. |
| 470 | ########################################################### |
| 471 | # NOTE: |
| 472 | # WHOLE_STATIC_LIBRARIES are libraries that are pulled into the |
| 473 | # module without leaving anything out, which is useful for turning |
| 474 | # a collection of .a files into a .so file. Linking against a |
| 475 | # normal STATIC_LIBRARY will only pull in code/symbols that are |
| 476 | # referenced by the module. (see gcc/ld's --whole-archive option) |
| 477 | ########################################################### |
| 478 | |
| 479 | # Get the list of BUILT libraries, which are under |
| 480 | # various intermediates directories. |
| 481 | so_suffix := $($(my_prefix)SHLIB_SUFFIX) |
| 482 | a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX) |
| 483 | |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 484 | ifdef LOCAL_NDK_VERSION |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 485 | built_shared_libraries := \ |
| 486 | $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ |
| 487 | $(addsuffix $(so_suffix), \ |
| 488 | $(LOCAL_SHARED_LIBRARIES))) |
| 489 | |
Ying Wang | 1a08100 | 2010-07-13 14:55:47 -0700 | [diff] [blame] | 490 | # Get the list of INSTALLED libraries. Strip off the various |
| 491 | # intermediates directories and point to the common lib dirs. |
| 492 | installed_shared_libraries := \ |
| 493 | $(addprefix $($(my_prefix)OUT_SHARED_LIBRARIES)/, \ |
| 494 | $(notdir $(built_shared_libraries))) |
| 495 | |
| 496 | my_system_shared_libraries_fullpath := $(addprefix $(my_ndk_version_root)/usr/lib/, \ |
| 497 | $(addsuffix $(so_suffix), $(LOCAL_SYSTEM_SHARED_LIBRARIES))) |
| 498 | |
| 499 | built_shared_libraries += $(my_system_shared_libraries_fullpath) |
| 500 | LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) |
| 501 | else |
| 502 | LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) |
| 503 | built_shared_libraries := \ |
| 504 | $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ |
| 505 | $(addsuffix $(so_suffix), \ |
| 506 | $(LOCAL_SHARED_LIBRARIES))) |
| 507 | |
| 508 | installed_shared_libraries := \ |
| 509 | $(addprefix $($(my_prefix)OUT_SHARED_LIBRARIES)/, \ |
| 510 | $(notdir $(built_shared_libraries))) |
| 511 | endif |
| 512 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 513 | built_static_libraries := \ |
| 514 | $(foreach lib,$(LOCAL_STATIC_LIBRARIES), \ |
| 515 | $(call intermediates-dir-for, \ |
| 516 | STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix)) |
| 517 | |
| 518 | built_whole_libraries := \ |
| 519 | $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \ |
| 520 | $(call intermediates-dir-for, \ |
| 521 | STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix)) |
| 522 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 523 | # We don't care about installed static libraries, since the |
| 524 | # libraries have already been linked into the module at that point. |
| 525 | # We do, however, care about the NOTICE files for any static |
| 526 | # libraries that we use. (see notice_files.make) |
| 527 | |
| 528 | installed_static_library_notice_file_targets := \ |
| 529 | $(foreach lib,$(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \ |
| 530 | NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib)) |
| 531 | |
| 532 | ########################################################### |
| 533 | # Rule-specific variable definitions |
| 534 | ########################################################### |
| 535 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS) |
| 536 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS) |
| 537 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS) |
| 538 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS) |
| 539 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags) |
| 540 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(LOCAL_C_INCLUDES) |
| 541 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(LOCAL_LDFLAGS) |
| 542 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS) |
Jeff Brown | bd528a8 | 2011-02-16 14:42:40 -0800 | [diff] [blame] | 543 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_CRT := $(LOCAL_NO_CRT) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 544 | |
| 545 | # this is really the way to get the files onto the command line instead |
| 546 | # of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work |
| 547 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries) |
| 548 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries) |
| 549 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries) |
| 550 | $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects) |
| 551 | |
| 552 | ########################################################### |
| 553 | # Define library dependencies. |
| 554 | ########################################################### |
| 555 | # all_libraries is used for the dependencies on LOCAL_BUILT_MODULE. |
| 556 | all_libraries := \ |
| 557 | $(built_shared_libraries) \ |
| 558 | $(built_static_libraries) \ |
| 559 | $(built_whole_libraries) |
| 560 | |
| 561 | # Make LOCAL_INSTALLED_MODULE depend on the installed versions of the |
| 562 | # libraries so they get installed along with it. We don't need to |
| 563 | # rebuild it when installing it, though, so this can be an order-only |
| 564 | # dependency. |
| 565 | $(LOCAL_INSTALLED_MODULE): | $(installed_shared_libraries) |
| 566 | |
| 567 | # Also depend on the notice files for any static libraries that |
| 568 | # are linked into this module. This will force them to be installed |
| 569 | # when this module is. |
| 570 | $(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets) |