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