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