binary.mk revision 2958af2aeb3430806b223af65352a4afaf89c514
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 8my_ndk_version_root := 9ifdef LOCAL_SDK_VERSION 10 ifdef LOCAL_NDK_VERSION 11 $(error $(LOCAL_PATH): LOCAL_NDK_VERSION is now retired.) 12 endif 13 ifdef LOCAL_IS_HOST_MODULE 14 $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module) 15 endif 16 my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources 17 my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) 18 19 # Set up the NDK stl variant. Starting from NDK-r5 the c++ stl resides in a separate location. 20 # See ndk/docs/CPLUSPLUS-SUPPORT.html 21 my_ndk_stl_include_path := 22 my_ndk_stl_shared_lib_fullpath := 23 my_ndk_stl_shared_lib := 24 my_ndk_stl_static_lib := 25 ifeq (,$(LOCAL_NDK_STL_VARIANT)) 26 LOCAL_NDK_STL_VARIANT := system 27 endif 28 ifneq (1,$(words $(filter system stlport_static stlport_shared gnustl_static, $(LOCAL_NDK_STL_VARIANT)))) 29 $(error $(LOCAL_PATH): Unknown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT)) 30 endif 31 ifeq (system,$(LOCAL_NDK_STL_VARIANT)) 32 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/system/include 33 # for "system" variant, the shared library exists in the system library and -lstdc++ is added by default. 34 else # LOCAL_NDK_STL_VARIANT is not system 35 ifneq (,$(filter stlport_%, $(LOCAL_NDK_STL_VARIANT))) 36 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/stlport/stlport 37 ifeq (stlport_static,$(LOCAL_NDK_STL_VARIANT)) 38 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libstlport_static.a 39 else 40 my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libstlport_shared.so 41 my_ndk_stl_shared_lib := -lstlport_shared 42 endif 43 else 44 # LOCAL_NDK_STL_VARIANT is gnustl_static 45 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/include \ 46 $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/include 47 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libgnustl_static.a 48 endif 49 endif 50endif 51 52################################################## 53# Compute the dependency of the shared libraries 54################################################## 55# On the target, we compile with -nostdlib, so we must add in the 56# default system shared libraries, unless they have requested not 57# to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value. One would 58# supply that, for example, when building libc itself. 59ifdef LOCAL_IS_HOST_MODULE 60 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 61 LOCAL_SYSTEM_SHARED_LIBRARIES := 62 endif 63else 64 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 65 LOCAL_SYSTEM_SHARED_LIBRARIES := $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES) 66 endif 67endif 68 69ifdef LOCAL_SDK_VERSION 70 # Get the list of INSTALLED libraries as module names. 71 # We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for 72 # they may cusomize their install path with LOCAL_MODULE_PATH 73 installed_shared_library_module_names := \ 74 $(LOCAL_SHARED_LIBRARIES) 75else 76 installed_shared_library_module_names := \ 77 $(LOCAL_SYSTEM_SHARED_LIBRARIES) $(LOCAL_SHARED_LIBRARIES) 78endif 79installed_shared_library_module_names := $(sort $(installed_shared_library_module_names)) 80 81####################################### 82include $(BUILD_SYSTEM)/base_rules.mk 83####################################### 84 85# The following LOCAL_ variables will be modified in this file. 86# Because the same LOCAL_ variables may be used to define modules for both 1st arch and 2nd arch, 87# we can't modify them in place. 88my_static_libraries := $(LOCAL_STATIC_LIBRARIES) 89my_shared_libraries := $(LOCAL_SHARED_LIBRARIES) 90my_cflags := $(LOCAL_CFLAGS) 91my_cppflags := $(LOCAL_CPPFLAGS) 92my_ldflags := $(LOCAL_LDFLAGS) 93my_asflags := $(LOCAL_ASFLAGS) 94my_cc := $(LOCAL_CC) 95my_cxx := $(LOCAL_CXX) 96my_c_includes := $(LOCAL_C_INCLUDES) 97my_generated_sources := $(LOCAL_GENERATED_SOURCES) 98 99 100# The real dependency will be added after all Android.mks are loaded and the install paths 101# of the shared libraries are determined. 102ifdef LOCAL_INSTALLED_MODULE 103ifdef installed_shared_library_module_names 104$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \ 105 $(LOCAL_MODULE):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(installed_shared_library_module_names)) 106endif 107endif 108 109# Add static HAL libraries 110ifdef LOCAL_HAL_STATIC_LIBRARIES 111$(foreach lib, $(LOCAL_HAL_STATIC_LIBRARIES), \ 112 $(eval b_lib := $(filter $(lib).%,$(BOARD_HAL_STATIC_LIBRARIES)))\ 113 $(if $(b_lib), $(eval my_static_libraries += $(b_lib)),\ 114 $(eval my_static_libraries += $(lib).default))) 115b_lib := 116endif 117 118ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),true) 119 LOCAL_CLANG := true 120 my_cflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS) 121 my_ldflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS) 122 my_shared_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES) 123 my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES) 124endif 125 126ifeq ($(strip $(WITHOUT_CLANG)),true) 127 LOCAL_CLANG := 128endif 129 130# Add in libcompiler_rt for all regular device builds 131ifeq (,$(LOCAL_SDK_VERSION)$(LOCAL_IS_HOST_MODULE)$(WITHOUT_LIBCOMPILER_RT)) 132 my_static_libraries += $(COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES) 133endif 134 135my_compiler_dependencies := 136ifeq ($(strip $(LOCAL_CLANG)),true) 137 my_compiler_dependencies := $(CLANG) $(CLANG_CXX) 138endif 139 140#################################################### 141## Add FDO flags if FDO is turned on and supported 142#################################################### 143ifneq ($(strip $(LOCAL_FDO_SUPPORT)),) 144 ifeq ($(strip $(LOCAL_IS_HOST_MODULE)),) 145 my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_CFLAGS) 146 my_cppflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_CFLAGS) 147 my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_CFLAGS) 148 endif 149endif 150 151########################################################### 152## Explicitly declare assembly-only __ASSEMBLY__ macro for 153## assembly source 154########################################################### 155my_asflags += -D__ASSEMBLY__ 156 157########################################################### 158## Define PRIVATE_ variables from global vars 159########################################################### 160ifndef LOCAL_IS_HOST_MODULE 161ifdef LOCAL_SDK_VERSION 162my_target_project_includes := 163my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_version_root)/usr/include 164else 165my_target_project_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PROJECT_INCLUDES) 166my_target_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_C_INCLUDES) 167endif # LOCAL_SDK_VERSION 168 169ifeq ($(LOCAL_CLANG),true) 170my_target_global_cflags := $(CLANG_TARGET_GLOBAL_CFLAGS) 171my_target_global_cppflags := $(CLANG_TARGET_GLOBAL_CPPFLAGS) 172my_target_global_ldflags := $(CLANG_TARGET_GLOBAL_LDFLAGS) 173my_target_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES) 174else 175my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CFLAGS) 176my_target_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CPPFLAGS) 177my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LDFLAGS) 178endif # LOCAL_CLANG 179 180$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes) 181$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes) 182$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags) 183$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags) 184$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags) 185 186else # LOCAL_IS_HOST_MODULE 187 188ifeq ($(LOCAL_CLANG),true) 189my_host_global_cflags := $(CLANG_HOST_GLOBAL_CFLAGS) 190my_host_global_cppflags := $(CLANG_HOST_GLOBAL_CPPFLAGS) 191my_host_global_ldflags := $(CLANG_HOST_GLOBAL_LDFLAGS) 192my_host_c_includes := $(HOST_C_INCLUDES) $(CLANG_CONFIG_EXTRA_HOST_C_INCLUDES) 193else 194my_host_global_cflags := $(HOST_GLOBAL_CFLAGS) 195my_host_global_cppflags := $(HOST_GLOBAL_CPPFLAGS) 196my_host_global_ldflags := $(HOST_GLOBAL_LDFLAGS) 197my_host_c_includes := $(HOST_C_INCLUDES) 198endif # LOCAL_CLANG 199 200$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_C_INCLUDES := $(my_host_c_includes) 201$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CFLAGS := $(my_host_global_cflags) 202$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CPPFLAGS := $(my_host_global_cppflags) 203$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_LDFLAGS := $(my_host_global_ldflags) 204endif # LOCAL_IS_HOST_MODULE 205 206########################################################### 207## Define PRIVATE_ variables used by multiple module types 208########################################################### 209$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \ 210 $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)) 211 212ifeq ($(strip $(WITH_SYNTAX_CHECK)),) 213 LOCAL_NO_SYNTAX_CHECK := true 214endif 215 216ifeq ($(strip $(WITH_STATIC_ANALYZER)),) 217 LOCAL_NO_STATIC_ANALYZER := true 218endif 219 220ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),) 221 my_syntax_arch := host 222else 223 my_syntax_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) 224endif 225 226ifeq ($(strip $(my_cc)),) 227 ifeq ($(strip $(LOCAL_CLANG)),true) 228 my_cc := $(CLANG) 229 else 230 my_cc := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)CC) 231 endif 232endif 233ifneq ($(LOCAL_NO_STATIC_ANALYZER),true) 234 my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer $(my_syntax_arch) "$(my_cc)" 235else 236ifneq ($(LOCAL_NO_SYNTAX_CHECK),true) 237 my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-syntax $(my_syntax_arch) "$(my_cc)" 238endif 239endif 240$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(my_cc) 241 242ifeq ($(strip $(my_cxx)),) 243 ifeq ($(strip $(LOCAL_CLANG)),true) 244 my_cxx := $(CLANG_CXX) 245 else 246 my_cxx := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)CXX) 247 endif 248endif 249ifneq ($(LOCAL_NO_STATIC_ANALYZER),true) 250 my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-analyzer $(my_syntax_arch) "$(my_cxx)" 251else 252ifneq ($(LOCAL_NO_SYNTAX_CHECK),true) 253 my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-syntax $(my_syntax_arch) "$(my_cxx)" 254endif 255endif 256$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(my_cxx) 257 258# TODO: support a mix of standard extensions so that this isn't necessary 259LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) 260ifeq ($(LOCAL_CPP_EXTENSION),) 261 LOCAL_CPP_EXTENSION := .cpp 262endif 263$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION) 264 265# Certain modules like libdl have to have symbols resolved at runtime and blow 266# up if --no-undefined is passed to the linker. 267ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),) 268ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),) 269 my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)NO_UNDEFINED_LDFLAGS) 270endif 271endif 272 273ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES)) 274$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true 275else 276$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := 277endif 278 279########################################################### 280## Define arm-vs-thumb-mode flags. 281########################################################### 282LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE)) 283ifeq ($(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH),arm) 284arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm) 285normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb) 286 287# Read the values from something like TARGET_arm_CFLAGS or 288# TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't 289# actually used (although they are usually empty). 290arm_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(arm_objects_mode)_CFLAGS) 291normal_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(normal_objects_mode)_CFLAGS) 292ifeq ($(strip $(LOCAL_CLANG)),true) 293arm_objects_cflags := $(call convert-to-$(my_host)clang-flags,$(arm_objects_cflags)) 294normal_objects_cflags := $(call convert-to-$(my_host)clang-flags,$(normal_objects_cflags)) 295endif 296 297else 298arm_objects_mode := 299normal_objects_mode := 300arm_objects_cflags := 301normal_objects_cflags := 302endif 303 304########################################################### 305## Define per-module debugging flags. Users can turn on 306## debugging for a particular module by setting DEBUG_MODULE_ModuleName 307## to a non-empty value in their environment or buildspec.mk, 308## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the 309## debug flags that they want to use. 310########################################################### 311ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE)) 312 debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS) 313else 314 debug_cflags := 315endif 316 317#################################################### 318## Compile RenderScript with reflected C++ 319#################################################### 320 321renderscript_sources := $(filter %.rs %.fs,$(LOCAL_SRC_FILES)) 322 323ifneq (,$(renderscript_sources)) 324 325renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources)) 326RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp 327renderscript_intermediate := $(intermediates)/renderscript 328 329ifeq ($(LOCAL_RENDERSCRIPT_CC),) 330LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC) 331endif 332 333# Turn on all warnings and warnings as errors for RS compiles. 334# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error 335renderscript_flags := -Wall -Werror 336renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS) 337 338renderscript_includes := \ 339 $(TOPDIR)external/clang/lib/Headers \ 340 $(TOPDIR)frameworks/rs/scriptc \ 341 $(LOCAL_RENDERSCRIPT_INCLUDES) 342 343ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),) 344renderscript_includes := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE) 345endif 346 347$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(renderscript_includes) 348$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC) 349$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags) 350$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath) 351$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate) 352$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC) 353 $(transform-renderscripts-to-cpp-and-bc) 354 355# include the dependency files (.d) generated by llvm-rs-cc. 356renderscript_generated_dep_files := $(addprefix $(renderscript_intermediate)/, \ 357 $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources))))) 358-include $(renderscript_generated_dep_files) 359 360LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp) 361 362rs_generated_cpps := $(addprefix \ 363 $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rs,%.cpp, \ 364 $(notdir $(renderscript_sources))))) 365 366$(rs_generated_cpps) : $(RenderScript_file_stamp) 367 368my_c_includes += $(renderscript_intermediate) 369my_generated_sources += $(rs_generated_cpps) 370 371endif 372 373 374########################################################### 375## Stuff source generated from one-off tools 376########################################################### 377$(my_generated_sources): PRIVATE_MODULE := $(my_register_name) 378 379ALL_GENERATED_SOURCES += $(my_generated_sources) 380 381 382########################################################### 383## Compile the .proto files to .cc and then to .o 384########################################################### 385proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES)) 386proto_generated_objects := 387proto_generated_headers := 388ifneq ($(proto_sources),) 389proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources)) 390proto_generated_cc_sources_dir := $(intermediates)/proto 391proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \ 392 $(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath))) 393proto_generated_objects := $(patsubst %.cc,%.o, $(proto_generated_cc_sources)) 394 395$(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP) 396$(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir) 397$(proto_generated_cc_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) 398$(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC) 399 $(transform-proto-to-cc) 400 401proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources)) 402$(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc 403 404$(proto_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 405$(proto_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 406$(proto_generated_objects): $(proto_generated_cc_sources_dir)/%.o: $(proto_generated_cc_sources_dir)/%.cc $(proto_generated_headers) 407 $(transform-$(PRIVATE_HOST)cpp-to-o) 408-include $(proto_generated_objects:%.o=%.P) 409 410my_c_includes += external/protobuf/src $(proto_generated_cc_sources_dir) 411my_cflags += -DGOOGLE_PROTOBUF_NO_RTTI 412ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full) 413my_static_libraries += libprotobuf-cpp-2.3.0-full 414else 415my_static_libraries += libprotobuf-cpp-2.3.0-lite 416endif 417endif 418 419 420########################################################### 421## YACC: Compile .y files to .cpp and the to .o. 422########################################################### 423 424yacc_sources := $(filter %.y,$(LOCAL_SRC_FILES)) 425yacc_cpps := $(addprefix \ 426 $(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION))) 427yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h) 428yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o) 429 430ifneq ($(strip $(yacc_cpps)),) 431$(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ 432 $(TOPDIR)$(LOCAL_PATH)/%.y \ 433 $(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES) 434 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION)) 435$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION) 436 437$(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 438$(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 439$(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) 440 $(transform-$(PRIVATE_HOST)cpp-to-o) 441endif 442 443########################################################### 444## LEX: Compile .l files to .cpp and then to .o. 445########################################################### 446 447lex_sources := $(filter %.l,$(LOCAL_SRC_FILES)) 448lex_cpps := $(addprefix \ 449 $(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION))) 450lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o) 451 452ifneq ($(strip $(lex_cpps)),) 453$(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ 454 $(TOPDIR)$(LOCAL_PATH)/%.l 455 $(transform-l-to-cpp) 456 457$(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 458$(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 459$(lex_objects): $(intermediates)/%.o: \ 460 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \ 461 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 462 $(yacc_headers) 463 $(transform-$(PRIVATE_HOST)cpp-to-o) 464endif 465 466########################################################### 467## C++: Compile .cpp files to .o. 468########################################################### 469 470# we also do this on host modules, even though 471# it's not really arm, because there are files that are shared. 472cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(LOCAL_SRC_FILES))) 473cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o)) 474 475cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES)) 476cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o)) 477 478$(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode) 479$(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags) 480$(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 481$(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 482 483cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects) 484 485ifneq ($(strip $(cpp_objects)),) 486$(cpp_objects): $(intermediates)/%.o: \ 487 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \ 488 $(yacc_cpps) $(proto_generated_headers) \ 489 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 490 | $(my_compiler_dependencies) 491 $(transform-$(PRIVATE_HOST)cpp-to-o) 492-include $(cpp_objects:%.o=%.P) 493endif 494 495########################################################### 496## C++: Compile generated .cpp files to .o. 497########################################################### 498 499gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(my_generated_sources)) 500gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o) 501 502ifneq ($(strip $(gen_cpp_objects)),) 503# Compile all generated files as thumb. 504# TODO: support compiling certain generated files as arm. 505$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 506$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 507$(gen_cpp_objects): $(intermediates)/%.o: \ 508 $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) \ 509 $(proto_generated_headers) \ 510 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 511 | $(my_compiler_dependencies) 512 $(transform-$(PRIVATE_HOST)cpp-to-o) 513-include $(gen_cpp_objects:%.o=%.P) 514endif 515 516########################################################### 517## S: Compile generated .S and .s files to .o. 518########################################################### 519 520gen_S_sources := $(filter %.S,$(my_generated_sources)) 521gen_S_objects := $(gen_S_sources:%.S=%.o) 522 523ifneq ($(strip $(gen_S_sources)),) 524$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \ 525 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 526 | $(my_compiler_dependencies) 527 $(transform-$(PRIVATE_HOST)s-to-o) 528-include $(gen_S_objects:%.o=%.P) 529endif 530 531gen_s_sources := $(filter %.s,$(my_generated_sources)) 532gen_s_objects := $(gen_s_sources:%.s=%.o) 533 534ifneq ($(strip $(gen_s_objects)),) 535$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \ 536 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 537 | $(my_compiler_dependencies) 538 $(transform-$(PRIVATE_HOST)s-to-o-no-deps) 539-include $(gen_s_objects:%.o=%.P) 540endif 541 542gen_asm_objects := $(gen_S_objects) $(gen_s_objects) 543 544########################################################### 545## o: Include generated .o files in output. 546########################################################### 547 548gen_o_objects := $(filter %.o,$(my_generated_sources)) 549 550########################################################### 551## C: Compile .c files to .o. 552########################################################### 553 554c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(LOCAL_SRC_FILES))) 555c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o)) 556 557c_normal_sources := $(filter %.c,$(LOCAL_SRC_FILES)) 558c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o)) 559 560$(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode) 561$(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags) 562$(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 563$(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 564 565c_objects := $(c_arm_objects) $(c_normal_objects) 566 567ifneq ($(strip $(c_objects)),) 568$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \ 569 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 570 | $(my_compiler_dependencies) 571 $(transform-$(PRIVATE_HOST)c-to-o) 572-include $(c_objects:%.o=%.P) 573endif 574 575########################################################### 576## C: Compile generated .c files to .o. 577########################################################### 578 579gen_c_sources := $(filter %.c,$(my_generated_sources)) 580gen_c_objects := $(gen_c_sources:%.c=%.o) 581 582ifneq ($(strip $(gen_c_objects)),) 583# Compile all generated files as thumb. 584# TODO: support compiling certain generated files as arm. 585$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 586$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 587$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \ 588 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 589 | $(my_compiler_dependencies) 590 $(transform-$(PRIVATE_HOST)c-to-o) 591-include $(gen_c_objects:%.o=%.P) 592endif 593 594########################################################### 595## ObjC: Compile .m files to .o 596########################################################### 597 598objc_sources := $(filter %.m,$(LOCAL_SRC_FILES)) 599objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o)) 600 601ifneq ($(strip $(objc_objects)),) 602$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) \ 603 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 604 | $(my_compiler_dependencies) 605 $(transform-$(PRIVATE_HOST)m-to-o) 606-include $(objc_objects:%.o=%.P) 607endif 608 609########################################################### 610## AS: Compile .S files to .o. 611########################################################### 612 613asm_sources_S := $(filter %.S,$(LOCAL_SRC_FILES)) 614asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o)) 615 616ifneq ($(strip $(asm_objects_S)),) 617$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \ 618 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 619 | $(my_compiler_dependencies) 620 $(transform-$(PRIVATE_HOST)s-to-o) 621-include $(asm_objects_S:%.o=%.P) 622endif 623 624asm_sources_s := $(filter %.s,$(LOCAL_SRC_FILES)) 625asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o)) 626 627ifneq ($(strip $(asm_objects_s)),) 628$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \ 629 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 630 | $(my_compiler_dependencies) 631 $(transform-$(PRIVATE_HOST)s-to-o-no-deps) 632-include $(asm_objects_s:%.o=%.P) 633endif 634 635asm_objects := $(asm_objects_S) $(asm_objects_s) 636 637 638#################################################### 639## Import includes 640#################################################### 641import_includes := $(intermediates)/import_includes 642import_includes_deps := $(strip \ 643 $(foreach l, $(installed_shared_library_module_names), \ 644 $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/export_includes) \ 645 $(foreach l, $(my_static_libraries) $(LOCAL_WHOLE_STATIC_LIBRARIES), \ 646 $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/export_includes)) 647$(import_includes) : $(import_includes_deps) 648 @echo Import includes file: $@ 649 $(hide) mkdir -p $(dir $@) && rm -f $@ 650ifdef import_includes_deps 651 $(hide) for f in $^; do \ 652 cat $$f >> $@; \ 653 done 654else 655 $(hide) touch $@ 656endif 657 658########################################################### 659## Common object handling. 660########################################################### 661 662# some rules depend on asm_objects being first. If your code depends on 663# being first, it's reasonable to require it to be assembly 664normal_objects := \ 665 $(asm_objects) \ 666 $(cpp_objects) \ 667 $(gen_cpp_objects) \ 668 $(gen_asm_objects) \ 669 $(c_objects) \ 670 $(gen_c_objects) \ 671 $(objc_objects) \ 672 $(yacc_objects) \ 673 $(lex_objects) \ 674 $(proto_generated_objects) \ 675 $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES)) 676 677all_objects := $(normal_objects) $(gen_o_objects) 678 679my_c_includes += $(TOPDIR)$(LOCAL_PATH) $(intermediates) 680 681ifndef LOCAL_SDK_VERSION 682 my_c_includes += $(JNI_H_INCLUDE) 683endif 684 685# all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES; 686# use normal_objects here to avoid creating circular dependencies. This assumes 687# that custom build rules which generate .o files don't consume other generated 688# sources as input (or if they do they take care of that dependency themselves). 689$(normal_objects) : | $(my_generated_sources) 690$(all_objects) : | $(import_includes) 691ALL_C_CPP_ETC_OBJECTS += $(all_objects) 692 693########################################################### 694## Copy headers to the install tree 695########################################################### 696ifndef LOCAL_2ND_ARCH_VAR_PREFIX 697include $(BUILD_COPY_HEADERS) 698endif 699 700########################################################### 701# Standard library handling. 702########################################################### 703 704########################################################### 705# The list of libraries that this module will link against are in 706# these variables. Each is a list of bare module names like "libc libm". 707# 708# LOCAL_SHARED_LIBRARIES 709# LOCAL_STATIC_LIBRARIES 710# LOCAL_WHOLE_STATIC_LIBRARIES 711# 712# We need to convert the bare names into the dependencies that 713# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE. 714# LOCAL_BUILT_MODULE should depend on the BUILT versions of the 715# libraries, so that simply building this module doesn't force 716# an install of a library. Similarly, LOCAL_INSTALLED_MODULE 717# should depend on the INSTALLED versions of the libraries so 718# that they get installed when this module does. 719########################################################### 720# NOTE: 721# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the 722# module without leaving anything out, which is useful for turning 723# a collection of .a files into a .so file. Linking against a 724# normal STATIC_LIBRARY will only pull in code/symbols that are 725# referenced by the module. (see gcc/ld's --whole-archive option) 726########################################################### 727 728# Get the list of BUILT libraries, which are under 729# various intermediates directories. 730so_suffix := $($(my_prefix)SHLIB_SUFFIX) 731a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX) 732 733ifdef LOCAL_SDK_VERSION 734built_shared_libraries := \ 735 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ 736 $(addsuffix $(so_suffix), \ 737 $(my_shared_libraries))) 738 739my_system_shared_libraries_fullpath := \ 740 $(my_ndk_stl_shared_lib_fullpath) \ 741 $(addprefix $(my_ndk_version_root)/usr/lib/, \ 742 $(addsuffix $(so_suffix), $(LOCAL_SYSTEM_SHARED_LIBRARIES))) 743 744built_shared_libraries += $(my_system_shared_libraries_fullpath) 745my_shared_libraries += $(LOCAL_SYSTEM_SHARED_LIBRARIES) 746else 747my_shared_libraries += $(LOCAL_SYSTEM_SHARED_LIBRARIES) 748built_shared_libraries := \ 749 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ 750 $(addsuffix $(so_suffix), \ 751 $(my_shared_libraries))) 752endif 753 754built_static_libraries := \ 755 $(foreach lib,$(my_static_libraries), \ 756 $(call intermediates-dir-for, \ 757 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/$(lib)$(a_suffix)) 758 759ifdef LOCAL_SDK_VERSION 760built_static_libraries += $(my_ndk_stl_static_lib) 761endif 762 763built_whole_libraries := \ 764 $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \ 765 $(call intermediates-dir-for, \ 766 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/$(lib)$(a_suffix)) 767 768# We don't care about installed static libraries, since the 769# libraries have already been linked into the module at that point. 770# We do, however, care about the NOTICE files for any static 771# libraries that we use. (see notice_files.mk) 772 773installed_static_library_notice_file_targets := \ 774 $(foreach lib,$(my_static_libraries) $(LOCAL_WHOLE_STATIC_LIBRARIES), \ 775 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib)) 776 777# Default is -fno-rtti. 778ifeq ($(strip $(LOCAL_RTTI_FLAG)),) 779LOCAL_RTTI_FLAG := -fno-rtti 780endif 781 782########################################################### 783# Rule-specific variable definitions 784########################################################### 785 786ifeq ($(LOCAL_CLANG),true) 787my_cflags := $(call convert-to-$(my_host)clang-flags,$(my_cflags)) 788my_cppflags := $(call convert-to-$(my_host)clang-flags,$(my_cppflags)) 789my_asflags := $(call convert-to-$(my_host)clang-flags,$(my_asflags)) 790my_ldflags := $(call convert-to-$(my_host)clang-flags,$(my_ldflags)) 791endif 792 793$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS) 794$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(my_asflags) 795$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(LOCAL_CONLYFLAGS) 796$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(my_cflags) 797$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(my_cppflags) 798$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG) 799$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags) 800$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(my_c_includes) 801$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes) 802$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(my_ldflags) 803$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS) 804$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_CRT := $(LOCAL_NO_CRT) 805 806# this is really the way to get the files onto the command line instead 807# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work 808$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries) 809$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries) 810$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries) 811$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects) 812 813########################################################### 814# Define library dependencies. 815########################################################### 816# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE. 817all_libraries := \ 818 $(built_shared_libraries) \ 819 $(built_static_libraries) \ 820 $(built_whole_libraries) 821 822# Also depend on the notice files for any static libraries that 823# are linked into this module. This will force them to be installed 824# when this module is. 825$(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets) 826 827########################################################### 828# Export includes 829########################################################### 830export_includes := $(intermediates)/export_includes 831$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS) 832$(export_includes) : $(LOCAL_MODULE_MAKEFILE) 833 @echo Export includes file: $< -- $@ 834 $(hide) mkdir -p $(dir $@) && rm -f $@ 835ifdef LOCAL_EXPORT_C_INCLUDE_DIRS 836 $(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \ 837 echo "-I $$d" >> $@; \ 838 done 839else 840 $(hide) touch $@ 841endif 842 843# Make sure export_includes gets generated when you are running mm/mmm 844$(LOCAL_BUILT_MODULE) : | $(export_includes) 845