binary.mk revision aace2024d723f6914f05bd9d847166c45447a913
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_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_CPU_ABI)/libstlport_static.a 39 else 40 my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(TARGET_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_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_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 69# Logging used to be part of libcutils (target) and libutils (sim); 70# hack modules that use those other libs to also include liblog. 71# All of this complexity is to make sure that liblog only appears 72# once, and appears just before libcutils or libutils on the link 73# line. 74# TODO: remove this hack and change all modules to use liblog 75# when necessary. 76define insert-liblog 77 $(if $(filter liblog,$(1)),$(1), \ 78 $(if $(filter libcutils,$(1)), \ 79 $(patsubst libcutils,liblog libcutils,$(1)) \ 80 , \ 81 $(patsubst libutils,liblog libutils,$(1)) \ 82 ) \ 83 ) 84endef 85ifneq (,$(filter libcutils libutils,$(LOCAL_SHARED_LIBRARIES))) 86 LOCAL_SHARED_LIBRARIES := $(call insert-liblog,$(LOCAL_SHARED_LIBRARIES)) 87endif 88ifneq (,$(filter libcutils libutils,$(LOCAL_STATIC_LIBRARIES))) 89 LOCAL_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_STATIC_LIBRARIES)) 90endif 91ifneq (,$(filter libcutils libutils,$(LOCAL_WHOLE_STATIC_LIBRARIES))) 92 LOCAL_WHOLE_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_WHOLE_STATIC_LIBRARIES)) 93endif 94 95ifdef LOCAL_SDK_VERSION 96 # Get the list of INSTALLED libraries as module names. 97 # We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for 98 # they may cusomize their install path with LOCAL_MODULE_PATH 99 installed_shared_library_module_names := \ 100 $(LOCAL_SHARED_LIBRARIES) 101else 102 installed_shared_library_module_names := \ 103 $(LOCAL_SYSTEM_SHARED_LIBRARIES) $(LOCAL_SHARED_LIBRARIES) 104endif 105installed_shared_library_module_names := $(sort $(installed_shared_library_module_names)) 106 107####################################### 108include $(BUILD_SYSTEM)/base_rules.mk 109####################################### 110 111# The real dependency will be added after all Android.mks are loaded and the install paths 112# of the shared libraries are determined. 113ifdef LOCAL_INSTALLED_MODULE 114ifdef installed_shared_library_module_names 115$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += $(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(installed_shared_library_module_names)) 116endif 117endif 118 119ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),true) 120 LOCAL_CLANG := true 121 LOCAL_CFLAGS += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS) 122 LOCAL_LDFLAGS += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS) 123 LOCAL_SHARED_LIBRARIES += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES) 124 LOCAL_STATIC_LIBRARIES += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES) 125endif 126 127# Add in libcompiler_rt for all regular device builds 128ifeq (,$(LOCAL_SDK_VERSION)$(LOCAL_IS_HOST_MODULE)$(WITHOUT_LIBCOMPILER_RT)) 129 LOCAL_STATIC_LIBRARIES += $(COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES) 130endif 131 132my_compiler_dependencies := 133ifeq ($(strip $(LOCAL_CLANG)),true) 134 LOCAL_CFLAGS += $(CLANG_CONFIG_EXTRA_CFLAGS) 135 LOCAL_ASFLAGS += $(CLANG_CONFIG_EXTRA_ASFLAGS) 136 LOCAL_LDFLAGS += $(CLANG_CONFIG_EXTRA_LDFLAGS) 137 my_compiler_dependencies := $(CLANG) $(CLANG_CXX) 138endif 139 140#################################################### 141## Add FDO flags if FDO is turned on and supported 142#################################################### 143ifeq ($(strip $(LOCAL_NO_FDO_SUPPORT)),) 144 LOCAL_CFLAGS += $(TARGET_FDO_CFLAGS) 145 LOCAL_CPPFLAGS += $(TARGET_FDO_CFLAGS) 146 LOCAL_LDFLAGS += $(TARGET_FDO_CFLAGS) 147endif 148 149#################################################### 150## Add profiling flags if aprof is turned on 151#################################################### 152ifeq ($(strip $(LOCAL_ENABLE_APROF)),true) 153 # -ffunction-sections and -fomit-frame-pointer are conflict with -pg 154 LOCAL_CFLAGS += -fno-omit-frame-pointer -fno-function-sections -pg 155 LOCAL_CPPFLAGS += -fno-omit-frame-pointer -fno-function-sections -pg 156endif 157 158########################################################### 159## Explicitly declare assembly-only __ASSEMBLY__ macro for 160## assembly source 161########################################################### 162LOCAL_ASFLAGS += -D__ASSEMBLY__ 163 164########################################################### 165## Define PRIVATE_ variables from global vars 166########################################################### 167ifdef LOCAL_SDK_VERSION 168my_target_project_includes := 169my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_version_root)/usr/include 170 171# filter out including of AndroidConfig.h in system/core. 172TARGET_GLOBAL_CFLAGS_NO_ANDCONF ?= $(subst $(TARGET_ANDROID_CONFIG_CFLAGS),,\ 173 $(TARGET_GLOBAL_CFLAGS)) 174my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS_NO_ANDCONF) 175else 176my_target_project_includes := $(TARGET_PROJECT_INCLUDES) 177my_target_c_includes := $(TARGET_C_INCLUDES) 178ifeq ($(strip $(LOCAL_CLANG)),true) 179my_target_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES) 180my_target_global_cflags := $(TARGET_GLOBAL_CLANG_FLAGS) 181else 182my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS) 183endif # LOCAL_CLANG 184endif # LOCAL_SDK_VERSION 185 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 := $(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## Compile RenderScript with reflected C++ 277#################################################### 278 279renderscript_sources := $(filter %.rs %.fs,$(LOCAL_SRC_FILES)) 280 281ifneq (,$(renderscript_sources)) 282 283renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources)) 284RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp 285renderscript_intermediate := $(intermediates)/renderscript 286 287ifeq ($(LOCAL_RENDERSCRIPT_CC),) 288LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC) 289endif 290 291# Turn on all warnings and warnings as errors for RS compiles. 292# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error 293renderscript_flags := -Wall -Werror 294renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS) 295 296LOCAL_RENDERSCRIPT_INCLUDES := \ 297 $(TOPDIR)external/clang/lib/Headers \ 298 $(TOPDIR)frameworks/rs/scriptc \ 299 $(LOCAL_RENDERSCRIPT_INCLUDES) 300 301ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),) 302LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE) 303endif 304 305$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES) 306$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC) 307$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags) 308$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath) 309$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate) 310$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC) 311 $(transform-renderscripts-to-cpp-and-bc) 312 313# include the dependency files (.d) generated by llvm-rs-cc. 314renderscript_generated_dep_files := $(addprefix $(renderscript_intermediate)/, \ 315 $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources))))) 316-include $(renderscript_generated_dep_files) 317 318LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp) 319 320rs_generated_cpps := $(addprefix \ 321 $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rs,%.cpp, \ 322 $(notdir $(renderscript_sources))))) 323 324$(rs_generated_cpps) : $(RenderScript_file_stamp) 325 326LOCAL_C_INCLUDES += $(renderscript_intermediate) 327LOCAL_GENERATED_SOURCES += $(rs_generated_cpps) 328 329endif 330 331 332########################################################### 333## Stuff source generated from one-off tools 334########################################################### 335$(LOCAL_GENERATED_SOURCES): PRIVATE_MODULE := $(LOCAL_MODULE) 336 337ALL_GENERATED_SOURCES += $(LOCAL_GENERATED_SOURCES) 338 339 340########################################################### 341## Compile the .proto files to .cc and then to .o 342########################################################### 343proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES)) 344proto_generated_objects := 345proto_generated_headers := 346ifneq ($(proto_sources),) 347proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources)) 348proto_generated_cc_sources_dir := $(intermediates)/proto 349proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \ 350 $(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath))) 351proto_generated_objects := $(patsubst %.cc,%.o, $(proto_generated_cc_sources)) 352 353$(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP) 354$(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir) 355$(proto_generated_cc_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) 356$(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC) 357 $(transform-proto-to-cc) 358 359proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources)) 360$(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc 361 362$(proto_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 363$(proto_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 364$(proto_generated_objects): $(proto_generated_cc_sources_dir)/%.o: $(proto_generated_cc_sources_dir)/%.cc $(proto_generated_headers) 365 $(transform-$(PRIVATE_HOST)cpp-to-o) 366-include $(proto_generated_objects:%.o=%.P) 367 368LOCAL_C_INCLUDES += external/protobuf/src $(proto_generated_cc_sources_dir) 369LOCAL_CFLAGS += -DGOOGLE_PROTOBUF_NO_RTTI 370ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full) 371LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-full 372else 373LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-lite 374endif 375endif 376 377 378########################################################### 379## YACC: Compile .y files to .cpp and the to .o. 380########################################################### 381 382yacc_sources := $(filter %.y,$(LOCAL_SRC_FILES)) 383yacc_cpps := $(addprefix \ 384 $(intermediates)/,$(yacc_sources:.y=$(LOCAL_CPP_EXTENSION))) 385yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h) 386yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o) 387 388ifneq ($(strip $(yacc_cpps)),) 389$(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ 390 $(TOPDIR)$(LOCAL_PATH)/%.y \ 391 $(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES) 392 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION)) 393$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION) 394 395$(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 396$(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 397$(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) 398 $(transform-$(PRIVATE_HOST)cpp-to-o) 399endif 400 401########################################################### 402## LEX: Compile .l files to .cpp and then to .o. 403########################################################### 404 405lex_sources := $(filter %.l,$(LOCAL_SRC_FILES)) 406lex_cpps := $(addprefix \ 407 $(intermediates)/,$(lex_sources:.l=$(LOCAL_CPP_EXTENSION))) 408lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o) 409 410ifneq ($(strip $(lex_cpps)),) 411$(lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ 412 $(TOPDIR)$(LOCAL_PATH)/%.l 413 $(transform-l-to-cpp) 414 415$(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 416$(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 417$(lex_objects): $(intermediates)/%.o: \ 418 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \ 419 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 420 $(yacc_headers) 421 $(transform-$(PRIVATE_HOST)cpp-to-o) 422endif 423 424########################################################### 425## C++: Compile .cpp files to .o. 426########################################################### 427 428# we also do this on host modules, even though 429# it's not really arm, because there are files that are shared. 430cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(LOCAL_SRC_FILES))) 431cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o)) 432 433cpp_normal_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_SRC_FILES)) 434cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o)) 435 436$(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode) 437$(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags) 438$(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 439$(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 440 441cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects) 442 443ifneq ($(strip $(cpp_objects)),) 444$(cpp_objects): $(intermediates)/%.o: \ 445 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \ 446 $(yacc_cpps) $(proto_generated_headers) \ 447 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 448 | $(my_compiler_dependencies) 449 $(transform-$(PRIVATE_HOST)cpp-to-o) 450-include $(cpp_objects:%.o=%.P) 451endif 452 453########################################################### 454## C++: Compile generated .cpp files to .o. 455########################################################### 456 457gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(LOCAL_GENERATED_SOURCES)) 458gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o) 459 460ifneq ($(strip $(gen_cpp_objects)),) 461# Compile all generated files as thumb. 462# TODO: support compiling certain generated files as arm. 463$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 464$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 465$(gen_cpp_objects): $(intermediates)/%.o: \ 466 $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) \ 467 $(proto_generated_headers) \ 468 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 469 | $(my_compiler_dependencies) 470 $(transform-$(PRIVATE_HOST)cpp-to-o) 471-include $(gen_cpp_objects:%.o=%.P) 472endif 473 474########################################################### 475## S: Compile generated .S and .s files to .o. 476########################################################### 477 478gen_S_sources := $(filter %.S,$(LOCAL_GENERATED_SOURCES)) 479gen_S_objects := $(gen_S_sources:%.S=%.o) 480 481ifneq ($(strip $(gen_S_sources)),) 482$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \ 483 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 484 | $(my_compiler_dependencies) 485 $(transform-$(PRIVATE_HOST)s-to-o) 486-include $(gen_S_objects:%.o=%.P) 487endif 488 489gen_s_sources := $(filter %.s,$(LOCAL_GENERATED_SOURCES)) 490gen_s_objects := $(gen_s_sources:%.s=%.o) 491 492ifneq ($(strip $(gen_s_objects)),) 493$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \ 494 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 495 | $(my_compiler_dependencies) 496 $(transform-$(PRIVATE_HOST)s-to-o-no-deps) 497-include $(gen_s_objects:%.o=%.P) 498endif 499 500gen_asm_objects := $(gen_S_objects) $(gen_s_objects) 501 502########################################################### 503## o: Include generated .o files in output. 504########################################################### 505 506gen_o_objects := $(filter %.o,$(LOCAL_GENERATED_SOURCES)) 507 508########################################################### 509## C: Compile .c files to .o. 510########################################################### 511 512c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(LOCAL_SRC_FILES))) 513c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o)) 514 515c_normal_sources := $(filter %.c,$(LOCAL_SRC_FILES)) 516c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o)) 517 518$(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode) 519$(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags) 520$(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 521$(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 522 523c_objects := $(c_arm_objects) $(c_normal_objects) 524 525ifneq ($(strip $(c_objects)),) 526$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \ 527 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 528 | $(my_compiler_dependencies) 529 $(transform-$(PRIVATE_HOST)c-to-o) 530-include $(c_objects:%.o=%.P) 531endif 532 533########################################################### 534## C: Compile generated .c files to .o. 535########################################################### 536 537gen_c_sources := $(filter %.c,$(LOCAL_GENERATED_SOURCES)) 538gen_c_objects := $(gen_c_sources:%.c=%.o) 539 540ifneq ($(strip $(gen_c_objects)),) 541# Compile all generated files as thumb. 542# TODO: support compiling certain generated files as arm. 543$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 544$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 545$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \ 546 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 547 | $(my_compiler_dependencies) 548 $(transform-$(PRIVATE_HOST)c-to-o) 549-include $(gen_c_objects:%.o=%.P) 550endif 551 552########################################################### 553## ObjC: Compile .m files to .o 554########################################################### 555 556objc_sources := $(filter %.m,$(LOCAL_SRC_FILES)) 557objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o)) 558 559ifneq ($(strip $(objc_objects)),) 560$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) \ 561 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 562 | $(my_compiler_dependencies) 563 $(transform-$(PRIVATE_HOST)m-to-o) 564-include $(objc_objects:%.o=%.P) 565endif 566 567########################################################### 568## AS: Compile .S files to .o. 569########################################################### 570 571asm_sources_S := $(filter %.S,$(LOCAL_SRC_FILES)) 572asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o)) 573 574ifneq ($(strip $(asm_objects_S)),) 575$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \ 576 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 577 | $(my_compiler_dependencies) 578 $(transform-$(PRIVATE_HOST)s-to-o) 579-include $(asm_objects_S:%.o=%.P) 580endif 581 582asm_sources_s := $(filter %.s,$(LOCAL_SRC_FILES)) 583asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o)) 584 585ifneq ($(strip $(asm_objects_s)),) 586$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \ 587 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 588 | $(my_compiler_dependencies) 589 $(transform-$(PRIVATE_HOST)s-to-o-no-deps) 590-include $(asm_objects_s:%.o=%.P) 591endif 592 593asm_objects := $(asm_objects_S) $(asm_objects_s) 594 595 596#################################################### 597## Import includes 598#################################################### 599import_includes := $(intermediates)/import_includes 600import_includes_deps := $(strip \ 601 $(foreach l, $(installed_shared_library_module_names), \ 602 $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE))/export_includes) \ 603 $(foreach l, $(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \ 604 $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE))/export_includes)) 605$(import_includes) : $(import_includes_deps) 606 @echo Import includes file: $@ 607 $(hide) mkdir -p $(dir $@) && rm -f $@ 608ifdef import_includes_deps 609 $(hide) for f in $^; do \ 610 cat $$f >> $@; \ 611 done 612else 613 $(hide) touch $@ 614endif 615 616########################################################### 617## Common object handling. 618########################################################### 619 620# some rules depend on asm_objects being first. If your code depends on 621# being first, it's reasonable to require it to be assembly 622all_objects := \ 623 $(asm_objects) \ 624 $(cpp_objects) \ 625 $(gen_cpp_objects) \ 626 $(gen_asm_objects) \ 627 $(c_objects) \ 628 $(gen_c_objects) \ 629 $(objc_objects) \ 630 $(yacc_objects) \ 631 $(lex_objects) \ 632 $(proto_generated_objects) \ 633 $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES)) \ 634 $(gen_o_objects) 635 636LOCAL_C_INCLUDES += $(TOPDIR)$(LOCAL_PATH) $(intermediates) 637 638ifndef LOCAL_SDK_VERSION 639 LOCAL_C_INCLUDES += $(JNI_H_INCLUDE) 640endif 641 642# .o files need to be filtered out of LOCAL_GENERATED_SOURCES 643# to avoid creating circular dependencies. 644$(all_objects) : | $(filter-out %.o,$(LOCAL_GENERATED_SOURCES)) $(import_includes) 645ALL_C_CPP_ETC_OBJECTS += $(all_objects) 646 647########################################################### 648## Copy headers to the install tree 649########################################################### 650include $(BUILD_COPY_HEADERS) 651 652########################################################### 653# Standard library handling. 654########################################################### 655 656########################################################### 657# The list of libraries that this module will link against are in 658# these variables. Each is a list of bare module names like "libc libm". 659# 660# LOCAL_SHARED_LIBRARIES 661# LOCAL_STATIC_LIBRARIES 662# LOCAL_WHOLE_STATIC_LIBRARIES 663# 664# We need to convert the bare names into the dependencies that 665# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE. 666# LOCAL_BUILT_MODULE should depend on the BUILT versions of the 667# libraries, so that simply building this module doesn't force 668# an install of a library. Similarly, LOCAL_INSTALLED_MODULE 669# should depend on the INSTALLED versions of the libraries so 670# that they get installed when this module does. 671########################################################### 672# NOTE: 673# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the 674# module without leaving anything out, which is useful for turning 675# a collection of .a files into a .so file. Linking against a 676# normal STATIC_LIBRARY will only pull in code/symbols that are 677# referenced by the module. (see gcc/ld's --whole-archive option) 678########################################################### 679 680# Get the list of BUILT libraries, which are under 681# various intermediates directories. 682so_suffix := $($(my_prefix)SHLIB_SUFFIX) 683a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX) 684 685ifdef LOCAL_SDK_VERSION 686built_shared_libraries := \ 687 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ 688 $(addsuffix $(so_suffix), \ 689 $(LOCAL_SHARED_LIBRARIES))) 690 691my_system_shared_libraries_fullpath := \ 692 $(my_ndk_stl_shared_lib_fullpath) \ 693 $(addprefix $(my_ndk_version_root)/usr/lib/, \ 694 $(addsuffix $(so_suffix), $(LOCAL_SYSTEM_SHARED_LIBRARIES))) 695 696built_shared_libraries += $(my_system_shared_libraries_fullpath) 697LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) 698else 699LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES) 700built_shared_libraries := \ 701 $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ 702 $(addsuffix $(so_suffix), \ 703 $(LOCAL_SHARED_LIBRARIES))) 704endif 705 706built_static_libraries := \ 707 $(foreach lib,$(LOCAL_STATIC_LIBRARIES), \ 708 $(call intermediates-dir-for, \ 709 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix)) 710 711ifdef LOCAL_SDK_VERSION 712built_static_libraries += $(my_ndk_stl_static_lib) 713endif 714 715built_whole_libraries := \ 716 $(foreach lib,$(LOCAL_WHOLE_STATIC_LIBRARIES), \ 717 $(call intermediates-dir-for, \ 718 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE))/$(lib)$(a_suffix)) 719 720# We don't care about installed static libraries, since the 721# libraries have already been linked into the module at that point. 722# We do, however, care about the NOTICE files for any static 723# libraries that we use. (see notice_files.mk) 724 725installed_static_library_notice_file_targets := \ 726 $(foreach lib,$(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES), \ 727 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib)) 728 729# Default is -fno-rtti. 730ifeq ($(strip $(LOCAL_RTTI_FLAG)),) 731LOCAL_RTTI_FLAG := -fno-rtti 732endif 733 734########################################################### 735# Rule-specific variable definitions 736########################################################### 737$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS) 738$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS) 739$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(LOCAL_CONLYFLAGS) 740$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS) 741$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS) 742$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG) 743$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags) 744$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(LOCAL_C_INCLUDES) 745$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes) 746$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(LOCAL_LDFLAGS) 747$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS) 748$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_CRT := $(LOCAL_NO_CRT) 749 750# this is really the way to get the files onto the command line instead 751# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work 752$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries) 753$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries) 754$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries) 755$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects) 756 757########################################################### 758# Define library dependencies. 759########################################################### 760# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE. 761all_libraries := \ 762 $(built_shared_libraries) \ 763 $(built_static_libraries) \ 764 $(built_whole_libraries) 765 766# Also depend on the notice files for any static libraries that 767# are linked into this module. This will force them to be installed 768# when this module is. 769$(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets) 770 771########################################################### 772# Export includes 773########################################################### 774export_includes := $(intermediates)/export_includes 775$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS) 776$(export_includes) : $(LOCAL_MODULE_MAKEFILE) 777 @echo Export includes file: $< -- $@ 778 $(hide) mkdir -p $(dir $@) && rm -f $@ 779ifdef LOCAL_EXPORT_C_INCLUDE_DIRS 780 $(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \ 781 echo "-I $$d" >> $@; \ 782 done 783else 784 $(hide) touch $@ 785endif 786 787# Make sure export_includes gets generated when you are running mm/mmm 788$(LOCAL_BUILT_MODULE) : | $(export_includes) 789