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