binary.mk revision 022a7b32efb9ff9ad36dca70696c428b1059ade4
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###################################### 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 27 my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/android-ndk-r$(LOCAL_NDK_VERSION)/sources 28 my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/android-ndk-r$(LOCAL_NDK_VERSION)/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_ARCH) 29 ifeq ($(wildcard $(my_ndk_version_root)),) 30 $(error $(LOCAL_PATH): ndk version root does not exist: $(my_ndk_version_root)) 31 endif 32 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 59 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 61 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_CPU_ABI)/libstdc++.a 62 endif 63 endif 64endif 65 66################################################## 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 123####################################### 124include $(BUILD_SYSTEM)/base_rules.mk 125####################################### 126 127ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),true) 128 LOCAL_CLANG := true 129 LOCAL_CFLAGS += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS) 130 LOCAL_LDFLAGS += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS) 131 LOCAL_SHARED_LIBRARIES += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES) 132 LOCAL_STATIC_LIBRARIES += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES) 133endif 134 135# Add in libcompiler-rt for all device builds 136ifeq (,$(LOCAL_NDK_VERSION)$(LOCAL_IS_HOST_MODULE)) 137 LOCAL_STATIC_LIBRARIES += $(COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES) 138endif 139 140my_compiler_dependencies := 141ifeq ($(strip $(LOCAL_CLANG)),true) 142 LOCAL_CFLAGS += $(CLANG_CONFIG_EXTRA_CFLAGS) 143 LOCAL_LDFLAGS += $(CLANG_CONFIG_EXTRA_LDFLAGS) 144 my_compiler_dependencies := $(CLANG) $(CLANG_CXX) 145endif 146 147#################################################### 148## Add FDO flags if FDO is turned on and supported 149#################################################### 150ifeq ($(strip $(LOCAL_NO_FDO_SUPPORT)),) 151 LOCAL_CFLAGS += $(TARGET_FDO_CFLAGS) 152 LOCAL_CPPFLAGS += $(TARGET_FDO_CFLAGS) 153 LOCAL_LDFLAGS += $(TARGET_FDO_CFLAGS) 154endif 155 156########################################################### 157## Explicitly declare assembly-only __ASSEMBLY__ macro for 158## assembly source 159########################################################### 160LOCAL_ASFLAGS += -D__ASSEMBLY__ 161 162########################################################### 163## Define PRIVATE_ variables from global vars 164########################################################### 165ifeq ($(strip $(LOCAL_CLANG)),true) 166my_target_global_cflags := $(TARGET_GLOBAL_CLANG_FLAGS) 167else 168my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS) 169endif 170 171ifdef LOCAL_NDK_VERSION 172my_target_project_includes := 173my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_version_root)/usr/include 174# TODO: more reliable way to remove platform stuff. 175my_target_global_cflags := $(filter-out -include -I system/%, $(my_target_global_cflags)) 176my_target_global_cppflags := $(filter-out -include -I system/%, $(TARGET_GLOBAL_CPPFLAGS)) 177else 178my_target_project_includes := $(TARGET_PROJECT_INCLUDES) 179my_target_c_includes := $(TARGET_C_INCLUDES) 180my_target_global_cflags := $(my_target_global_cflags) 181my_target_global_cppflags := $(TARGET_GLOBAL_CPPFLAGS) 182ifeq ($(strip $(LOCAL_CLANG)),true) 183 my_target_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES) 184endif 185endif 186$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes) 187$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes) 188$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags) 189$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags) 190 191########################################################### 192## Define PRIVATE_ variables used by multiple module types 193########################################################### 194$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \ 195 $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)) 196 197ifeq ($(strip $(LOCAL_CC)),) 198 ifeq ($(strip $(LOCAL_CLANG)),true) 199 LOCAL_CC := $(CLANG) 200 else 201 LOCAL_CC := $($(my_prefix)CC) 202 endif 203endif 204$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(LOCAL_CC) 205 206ifeq ($(strip $(LOCAL_CXX)),) 207 ifeq ($(strip $(LOCAL_CLANG)),true) 208 LOCAL_CXX := $(CLANG_CXX) 209 else 210 LOCAL_CXX := $($(my_prefix)CXX) 211 endif 212endif 213$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(LOCAL_CXX) 214 215# TODO: support a mix of standard extensions so that this isn't necessary 216LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) 217ifeq ($(LOCAL_CPP_EXTENSION),) 218 LOCAL_CPP_EXTENSION := .cpp 219endif 220$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION) 221 222# Certain modules like libdl have to have symbols resolved at runtime and blow 223# up if --no-undefined is passed to the linker. 224ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),) 225ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),) 226 LOCAL_LDFLAGS := $(LOCAL_LDFLAGS) $($(my_prefix)NO_UNDEFINED_LDFLAGS) 227endif 228endif 229 230ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES)) 231$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true 232else 233$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := 234endif 235 236########################################################### 237## Define arm-vs-thumb-mode flags. 238########################################################### 239LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE)) 240ifeq ($(TARGET_ARCH),arm) 241arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm) 242normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb) 243 244# Read the values from something like TARGET_arm_CFLAGS or 245# TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't 246# actually used (although they are usually empty). 247ifeq ($(strip $(LOCAL_CLANG)),true) 248arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CLANG_CFLAGS) 249normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_CLANG_CFLAGS) 250else 251arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CFLAGS) 252normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_CFLAGS) 253endif 254 255else 256arm_objects_mode := 257normal_objects_mode := 258arm_objects_cflags := 259normal_objects_cflags := 260endif 261 262########################################################### 263## Define per-module debugging flags. Users can turn on 264## debugging for a particular module by setting DEBUG_MODULE_ModuleName 265## to a non-empty value in their environment or buildspec.mk, 266## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the 267## debug flags that they want to use. 268########################################################### 269ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE)) 270 debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS) 271else 272 debug_cflags := 273endif 274 275########################################################### 276## Stuff source generated from one-off tools 277########################################################### 278$(LOCAL_GENERATED_SOURCES): PRIVATE_MODULE := $(LOCAL_MODULE) 279 280ALL_GENERATED_SOURCES += $(LOCAL_GENERATED_SOURCES) 281 282 283########################################################### 284## Compile the .proto files to .cc and then to .o 285########################################################### 286proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES)) 287proto_generated_objects := 288proto_generated_headers := 289ifneq ($(proto_sources),) 290proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources)) 291proto_generated_cc_sources_dir := $(intermediates)/proto 292proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \ 293 $(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath))) 294proto_generated_objects := $(patsubst %.cc,%.o, $(proto_generated_cc_sources)) 295 296$(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP) 297$(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir) 298$(proto_generated_cc_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) 299$(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC) 300 $(transform-proto-to-cc) 301 302proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources)) 303$(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc 304 305$(proto_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 306$(proto_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 307$(proto_generated_objects): $(proto_generated_cc_sources_dir)/%.o: $(proto_generated_cc_sources_dir)/%.cc $(proto_generated_headers) 308 $(transform-$(PRIVATE_HOST)cpp-to-o) 309-include $(proto_generated_objects:%.o=%.P) 310 311LOCAL_C_INCLUDES += external/protobuf/src $(proto_generated_cc_sources_dir) 312LOCAL_CFLAGS += -DGOOGLE_PROTOBUF_NO_RTTI 313ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full) 314LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-full 315else 316LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-lite 317endif 318endif 319 320 321########################################################### 322## YACC: Compile .y files to .cpp and the to .o. 323########################################################### 324 325yacc_sources := $(filter %.y,$(LOCAL_SRC_FILES)) 326yacc_cpps := $(addprefix \ 327 $(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION))) 328yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h) 329yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o) 330 331ifneq ($(strip $(yacc_cpps)),) 332$(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ 333 $(TOPDIR)$(LOCAL_PATH)/%.y \ 334 $(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES) 335 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION)) 336$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION) 337 338$(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 339$(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 340$(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) 341 $(transform-$(PRIVATE_HOST)cpp-to-o) 342endif 343 344########################################################### 345## LEX: Compile .l files to .cpp and then to .o. 346########################################################### 347 348lex_sources := $(filter %.l,$(LOCAL_SRC_FILES)) 349lex_cpps := $(addprefix \ 350 $(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION))) 351lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o) 352 353ifneq ($(strip $(lex_cpps)),) 354$(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ 355 $(TOPDIR)$(LOCAL_PATH)/%.l 356 $(transform-l-to-cpp) 357 358$(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 359$(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 360$(lex_objects): $(intermediates)/%.o: \ 361 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \ 362 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 363 $(yacc_headers) 364 $(transform-$(PRIVATE_HOST)cpp-to-o) 365endif 366 367########################################################### 368## C++: Compile .cpp files to .o. 369########################################################### 370 371# we also do this on host modules, even though 372# it's not really arm, because there are files that are shared. 373cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(LOCAL_SRC_FILES))) 374cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o)) 375 376cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES)) 377cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o)) 378 379$(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode) 380$(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags) 381$(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 382$(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 383 384cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects) 385 386ifneq ($(strip $(cpp_objects)),) 387$(cpp_objects): $(intermediates)/%.o: \ 388 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \ 389 $(yacc_cpps) $(proto_generated_headers) $(my_compiler_dependencies) \ 390 $(LOCAL_ADDITIONAL_DEPENDENCIES) 391 $(transform-$(PRIVATE_HOST)cpp-to-o) 392-include $(cpp_objects:%.o=%.P) 393endif 394 395########################################################### 396## C++: Compile generated .cpp files to .o. 397########################################################### 398 399gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_GENERATED_SOURCES)) 400gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o) 401 402ifneq ($(strip $(gen_cpp_objects)),) 403# Compile all generated files as thumb. 404# TODO: support compiling certain generated files as arm. 405$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 406$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 407$(gen_cpp_objects): $(intermediates)/%.o: \ 408 $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) \ 409 $(proto_generated_headers) $(my_compiler_dependencies) \ 410 $(LOCAL_ADDITIONAL_DEPENDENCIES) 411 $(transform-$(PRIVATE_HOST)cpp-to-o) 412-include $(gen_cpp_objects:%.o=%.P) 413endif 414 415########################################################### 416## S: Compile generated .S and .s files to .o. 417########################################################### 418 419gen_S_sources := $(filter %.S,$(LOCAL_GENERATED_SOURCES)) 420gen_S_objects := $(gen_S_sources:%.S=%.o) 421 422ifneq ($(strip $(gen_S_sources)),) 423$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \ 424 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES) 425 $(transform-$(PRIVATE_HOST)s-to-o) 426-include $(gen_S_objects:%.o=%.P) 427endif 428 429gen_s_sources := $(filter %.s,$(LOCAL_GENERATED_SOURCES)) 430gen_s_objects := $(gen_s_sources:%.s=%.o) 431 432ifneq ($(strip $(gen_s_objects)),) 433$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \ 434 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES) 435 $(transform-$(PRIVATE_HOST)s-to-o-no-deps) 436-include $(gen_s_objects:%.o=%.P) 437endif 438 439gen_asm_objects := $(gen_S_objects) $(gen_s_objects) 440 441########################################################### 442## C: Compile .c files to .o. 443########################################################### 444 445c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(LOCAL_SRC_FILES))) 446c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o)) 447 448c_normal_sources := $(filter %.c,$(LOCAL_SRC_FILES)) 449c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o)) 450 451$(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode) 452$(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags) 453$(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 454$(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 455 456c_objects := $(c_arm_objects) $(c_normal_objects) 457 458ifneq ($(strip $(c_objects)),) 459$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \ 460 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES) 461 $(transform-$(PRIVATE_HOST)c-to-o) 462-include $(c_objects:%.o=%.P) 463endif 464 465########################################################### 466## C: Compile generated .c files to .o. 467########################################################### 468 469gen_c_sources := $(filter %.c,$(LOCAL_GENERATED_SOURCES)) 470gen_c_objects := $(gen_c_sources:%.c=%.o) 471 472ifneq ($(strip $(gen_c_objects)),) 473# Compile all generated files as thumb. 474# TODO: support compiling certain generated files as arm. 475$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 476$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 477$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \ 478 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES) 479 $(transform-$(PRIVATE_HOST)c-to-o) 480-include $(gen_c_objects:%.o=%.P) 481endif 482 483########################################################### 484## ObjC: Compile .m files to .o 485########################################################### 486 487objc_sources := $(filter %.m,$(LOCAL_SRC_FILES)) 488objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o)) 489 490ifneq ($(strip $(objc_objects)),) 491$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) \ 492 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES) 493 $(transform-$(PRIVATE_HOST)m-to-o) 494-include $(objc_objects:%.o=%.P) 495endif 496 497########################################################### 498## AS: Compile .S files to .o. 499########################################################### 500 501asm_sources_S := $(filter %.S,$(LOCAL_SRC_FILES)) 502asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o)) 503 504ifneq ($(strip $(asm_objects_S)),) 505$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \ 506 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES) 507 $(transform-$(PRIVATE_HOST)s-to-o) 508-include $(asm_objects_S:%.o=%.P) 509endif 510 511asm_sources_s := $(filter %.s,$(LOCAL_SRC_FILES)) 512asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o)) 513 514ifneq ($(strip $(asm_objects_s)),) 515$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \ 516 $(my_compiler_dependencies) $(LOCAL_ADDITIONAL_DEPENDENCIES) 517 $(transform-$(PRIVATE_HOST)s-to-o-no-deps) 518-include $(asm_objects_s:%.o=%.P) 519endif 520 521asm_objects := $(asm_objects_S) $(asm_objects_s) 522 523 524#################################################### 525## Import includes 526#################################################### 527import_includes := $(intermediates)/import_includes 528import_includes_deps := $(strip \ 529 $(foreach l, $(installed_shared_library_module_names), \ 530 $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE))/export_includes) \ 531 $(foreach l, $(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \ 532 $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE))/export_includes)) 533$(import_includes) : $(import_includes_deps) 534 @echo Import includes file: $@ 535 $(hide) mkdir -p $(dir $@) && rm -f $@ 536ifdef import_includes_deps 537 $(hide) for f in $^; do \ 538 cat $$f >> $@; \ 539 done 540else 541 $(hide) touch $@ 542endif 543 544########################################################### 545## Common object handling. 546########################################################### 547 548# some rules depend on asm_objects being first. If your code depends on 549# being first, it's reasonable to require it to be assembly 550all_objects := \ 551 $(asm_objects) \ 552 $(cpp_objects) \ 553 $(gen_cpp_objects) \ 554 $(gen_asm_objects) \ 555 $(c_objects) \ 556 $(gen_c_objects) \ 557 $(objc_objects) \ 558 $(yacc_objects) \ 559 $(lex_objects) \ 560 $(proto_generated_objects) \ 561 $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES)) 562 563LOCAL_C_INCLUDES += $(TOPDIR)$(LOCAL_PATH) $(intermediates) 564 565ifndef LOCAL_NDK_VERSION 566 LOCAL_C_INCLUDES += $(JNI_H_INCLUDE) 567endif 568 569$(all_objects) : | $(LOCAL_GENERATED_SOURCES) $(import_includes) 570ALL_C_CPP_ETC_OBJECTS += $(all_objects) 571 572########################################################### 573## Copy headers to the install tree 574########################################################### 575include $(BUILD_COPY_HEADERS) 576 577########################################################### 578# Standard library handling. 579########################################################### 580 581########################################################### 582# The list of libraries that this module will link against are in 583# these variables. Each is a list of bare module names like "libc libm". 584# 585# LOCAL_SHARED_LIBRARIES 586# LOCAL_STATIC_LIBRARIES 587# LOCAL_WHOLE_STATIC_LIBRARIES 588# 589# We need to convert the bare names into the dependencies that 590# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE. 591# LOCAL_BUILT_MODULE should depend on the BUILT versions of the 592# libraries, so that simply building this module doesn't force 593# an install of a library. Similarly, LOCAL_INSTALLED_MODULE 594# should depend on the INSTALLED versions of the libraries so 595# that they get installed when this module does. 596########################################################### 597# NOTE: 598# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the 599# module without leaving anything out, which is useful for turning 600# a collection of .a files into a .so file. Linking against a 601# normal STATIC_LIBRARY will only pull in code/symbols that are 602# referenced by the module. (see gcc/ld's --whole-archive option) 603########################################################### 604 605# Get the list of BUILT libraries, which are under 606# various intermediates directories. 607so_suffix := $($(my_prefix)SHLIB_SUFFIX) 608a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX) 609 610ifdef LOCAL_NDK_VERSION 611built_shared_libraries := \ 612 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ 613 $(addsuffix $(so_suffix), \ 614 $(LOCAL_SHARED_LIBRARIES))) 615 616my_system_shared_libraries_fullpath := \ 617 $(my_ndk_stl_shared_lib_fullpath) \ 618 $(addprefix $(my_ndk_version_root)/usr/lib/, \ 619 $(addsuffix $(so_suffix), $(LOCAL_SYSTEM_SHARED_LIBRARIES))) 620 621built_shared_libraries += $(my_system_shared_libraries_fullpath) 622LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) 623else 624LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) 625built_shared_libraries := \ 626 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ 627 $(addsuffix $(so_suffix), \ 628 $(LOCAL_SHARED_LIBRARIES))) 629endif 630 631built_static_libraries := \ 632 $(foreach lib,$(LOCAL_STATIC_LIBRARIES), \ 633 $(call intermediates-dir-for, \ 634 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix)) 635 636ifdef LOCAL_NDK_VERSION 637built_static_libraries += $(my_ndk_stl_static_lib) 638endif 639 640built_whole_libraries := \ 641 $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \ 642 $(call intermediates-dir-for, \ 643 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix)) 644 645# We don't care about installed static libraries, since the 646# libraries have already been linked into the module at that point. 647# We do, however, care about the NOTICE files for any static 648# libraries that we use. (see notice_files.mk) 649 650installed_static_library_notice_file_targets := \ 651 $(foreach lib,$(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \ 652 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib)) 653 654# Default is -fno-rtti. 655ifeq ($(strip $(LOCAL_RTTI_FLAG)),) 656LOCAL_RTTI_FLAG := -fno-rtti 657endif 658 659########################################################### 660# Rule-specific variable definitions 661########################################################### 662$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS) 663$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS) 664$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS) 665$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS) 666$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG) 667$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags) 668$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(LOCAL_C_INCLUDES) 669$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes) 670$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(LOCAL_LDFLAGS) 671$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS) 672$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_CRT := $(LOCAL_NO_CRT) 673 674# this is really the way to get the files onto the command line instead 675# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work 676$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries) 677$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries) 678$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries) 679$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects) 680 681########################################################### 682# Define library dependencies. 683########################################################### 684# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE. 685all_libraries := \ 686 $(built_shared_libraries) \ 687 $(built_static_libraries) \ 688 $(built_whole_libraries) 689 690# Also depend on the notice files for any static libraries that 691# are linked into this module. This will force them to be installed 692# when this module is. 693$(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets) 694 695########################################################### 696# Export includes 697########################################################### 698export_includes := $(intermediates)/export_includes 699$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS) 700$(export_includes) : $(LOCAL_MODULE_MAKEFILE) 701 @echo Export includes file: $< -- $@ 702 $(hide) mkdir -p $(dir $@) && rm -f $@ 703ifdef LOCAL_EXPORT_C_INCLUDE_DIRS 704 $(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \ 705 echo "-I $$d" >> $@; \ 706 done 707else 708 $(hide) touch $@ 709endif 710 711# Make sure export_includes gets generated when you are running mm/mmm 712$(LOCAL_BUILT_MODULE) : | $(export_includes) 713