binary.mk revision 529f176ee1cbdf06b72de4c5a24683990ae94406
1########################################################### 2## Standard rules for building binary object files from 3## asm/c/cpp/yacc/lex/etc source files. 4## 5## The list of object files is exported in $(all_objects). 6########################################################### 7 8####################################### 9include $(BUILD_SYSTEM)/base_rules.mk 10####################################### 11 12################################################## 13# Compute the dependency of the shared libraries 14################################################## 15# On the target, we compile with -nostdlib, so we must add in the 16# default system shared libraries, unless they have requested not 17# to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value. One would 18# supply that, for example, when building libc itself. 19ifdef LOCAL_IS_HOST_MODULE 20 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 21 my_system_shared_libraries := 22 else 23 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) 24 endif 25else 26 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 27 my_system_shared_libraries := libc libm 28 else 29 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) 30 endif 31endif 32 33# The following LOCAL_ variables will be modified in this file. 34# Because the same LOCAL_ variables may be used to define modules for both 1st arch and 2nd arch, 35# we can't modify them in place. 36my_src_files := $(LOCAL_SRC_FILES) 37my_static_libraries := $(LOCAL_STATIC_LIBRARIES) 38my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES) 39my_shared_libraries := $(LOCAL_SHARED_LIBRARIES) 40my_cflags := $(LOCAL_CFLAGS) 41my_conlyflags := $(LOCAL_CONLYFLAGS) 42my_cppflags := $(LOCAL_CPPFLAGS) 43my_cflags_no_override := $(GLOBAL_CFLAGS_NO_OVERRIDE) 44my_cppflags_no_override := $(GLOBAL_CPPFLAGS_NO_OVERRIDE) 45my_ldflags := $(LOCAL_LDFLAGS) 46my_ldlibs := $(LOCAL_LDLIBS) 47my_asflags := $(LOCAL_ASFLAGS) 48my_cc := $(LOCAL_CC) 49my_cc_wrapper := $(CC_WRAPPER) 50my_cxx := $(LOCAL_CXX) 51my_cxx_wrapper := $(CXX_WRAPPER) 52my_c_includes := $(LOCAL_C_INCLUDES) 53my_generated_sources := $(LOCAL_GENERATED_SOURCES) 54my_native_coverage := $(LOCAL_NATIVE_COVERAGE) 55my_additional_dependencies := $(LOCAL_MODULE_MAKEFILE) $(LOCAL_ADDITIONAL_DEPENDENCIES) 56my_export_c_include_dirs := $(LOCAL_EXPORT_C_INCLUDE_DIRS) 57 58ifdef LOCAL_IS_HOST_MODULE 59my_allow_undefined_symbols := true 60else 61my_allow_undefined_symbols := $(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)) 62endif 63 64my_ndk_sysroot := 65my_ndk_sysroot_include := 66my_ndk_sysroot_lib := 67ifdef LOCAL_SDK_VERSION 68 ifdef LOCAL_NDK_VERSION 69 $(error $(LOCAL_PATH): LOCAL_NDK_VERSION is now retired.) 70 endif 71 ifdef LOCAL_IS_HOST_MODULE 72 $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module) 73 endif 74 my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources 75 my_ndk_sysroot := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) 76 my_ndk_sysroot_include := $(my_ndk_sysroot)/usr/include 77 ifeq (x86_64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) 78 my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/lib64 79 else ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT)) 80 my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/libr6 81 else 82 my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/lib 83 endif 84 85 # The bionic linker now has support for packed relocations and gnu style 86 # hashes (which are much faster!), but shipping to older devices requires 87 # the old style hash and disabling packed relocations. 88 #ifeq ($(shell expr $(LOCAL_SDK_VERSION) >= FIRST_SUPPORTED_VERSION),0) 89 my_ldflags += -Wl,--hash-style=sysv 90 LOCAL_PACK_MODULE_RELOCATIONS := false 91 #endif 92 93 # Set up the NDK stl variant. Starting from NDK-r5 the c++ stl resides in a separate location. 94 # See ndk/docs/CPLUSPLUS-SUPPORT.html 95 my_ndk_stl_include_path := 96 my_ndk_stl_shared_lib_fullpath := 97 my_ndk_stl_shared_lib := 98 my_ndk_stl_static_lib := 99 my_ndk_stl_cppflags := 100 my_cpu_variant := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI) 101 ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT)) 102 my_cpu_variant := mips32r6 103 endif 104 LOCAL_NDK_STL_VARIANT := $(strip $(LOCAL_NDK_STL_VARIANT)) 105 ifeq (,$(LOCAL_NDK_STL_VARIANT)) 106 LOCAL_NDK_STL_VARIANT := system 107 endif 108 ifneq (1,$(words $(filter system stlport_static stlport_shared c++_static c++_shared gnustl_static, $(LOCAL_NDK_STL_VARIANT)))) 109 $(error $(LOCAL_PATH): Unknown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT)) 110 endif 111 ifeq (system,$(LOCAL_NDK_STL_VARIANT)) 112 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/system/include 113 # for "system" variant, the shared library exists in the system library and -lstdc++ is added by default. 114 else # LOCAL_NDK_STL_VARIANT is not system 115 ifneq (,$(filter stlport_%, $(LOCAL_NDK_STL_VARIANT))) 116 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/stlport/stlport 117 ifeq (stlport_static,$(LOCAL_NDK_STL_VARIANT)) 118 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(my_cpu_variant)/libstlport_static.a 119 else 120 my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/stlport/libs/$(my_cpu_variant)/libstlport_shared.so 121 my_ndk_stl_shared_lib := -lstlport_shared 122 endif 123 else # LOCAL_NDK_STL_VARIANT is not stlport_* either 124 ifneq (,$(filter c++_%, $(LOCAL_NDK_STL_VARIANT))) 125 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/llvm-libc++/libcxx/include \ 126 $(my_ndk_source_root)/cxx-stl/llvm-libc++/gabi++/include \ 127 $(my_ndk_source_root)/android/support/include 128 ifeq (c++_static,$(LOCAL_NDK_STL_VARIANT)) 129 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/llvm-libc++/libs/$(my_cpu_variant)/libc++_static.a 130 else 131 my_ndk_stl_shared_lib_fullpath := $(my_ndk_source_root)/cxx-stl/llvm-libc++/libs/$(my_cpu_variant)/libc++_shared.so 132 my_ndk_stl_shared_lib := -lc++_shared 133 endif 134 my_ndk_stl_cppflags := -std=c++11 135 else 136 # LOCAL_NDK_STL_VARIANT is gnustl_static 137 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/$($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_GCC_VERSION)/libs/$(my_cpu_variant)/include \ 138 $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/$($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_GCC_VERSION)/include 139 my_ndk_stl_static_lib := $(my_ndk_source_root)/cxx-stl/gnu-libstdc++/$($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_GCC_VERSION)/libs/$(my_cpu_variant)/libgnustl_static.a 140 endif 141 endif 142 endif 143endif 144 145# MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because 146# all code is position independent, and then those warnings get promoted to 147# errors. 148ifndef USE_MINGW 149ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES) 150my_cflags += -fpie 151else 152my_cflags += -fPIC 153endif 154endif 155 156my_src_files += $(LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SRC_FILES_$(my_32_64_bit_suffix)) 157my_shared_libraries += $(LOCAL_SHARED_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SHARED_LIBRARIES_$(my_32_64_bit_suffix)) 158my_cflags += $(LOCAL_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CFLAGS_$(my_32_64_bit_suffix)) 159my_cppflags += $(LOCAL_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CPPFLAGS_$(my_32_64_bit_suffix)) 160my_ldflags += $(LOCAL_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_LDFLAGS_$(my_32_64_bit_suffix)) 161my_asflags += $(LOCAL_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_ASFLAGS_$(my_32_64_bit_suffix)) 162my_c_includes += $(LOCAL_C_INCLUDES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_C_INCLUDES_$(my_32_64_bit_suffix)) 163my_generated_sources += $(LOCAL_GENERATED_SOURCES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_GENERATED_SOURCES_$(my_32_64_bit_suffix)) 164 165my_clang := $(strip $(LOCAL_CLANG)) 166ifdef LOCAL_CLANG_$(my_32_64_bit_suffix) 167my_clang := $(strip $(LOCAL_CLANG_$(my_32_64_bit_suffix))) 168endif 169ifdef LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) 170my_clang := $(strip $(LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))) 171endif 172 173# clang is enabled by default for host builds 174# enable it unless we've specifically disabled clang above 175ifdef LOCAL_IS_HOST_MODULE 176 ifneq ($(HOST_OS),windows) 177 ifeq ($(my_clang),) 178 my_clang := true 179 endif 180 endif 181endif 182 183my_cpp_std_version := -std=gnu++14 184ifdef LOCAL_SDK_VERSION 185 # The NDK handles this itself. 186 my_cpp_std_version := 187endif 188 189ifdef LOCAL_IS_HOST_MODULE 190 ifneq ($(my_clang),true) 191 # The host GCC doesn't support C++14 (and is deprecated, so likely 192 # never will). Build these modules with C++11. 193 my_cpp_std_version := -std=gnu++11 194 endif 195endif 196 197my_cppflags := $(my_cpp_std_version) $(my_cppflags) 198 199# Add option to make clang the default for device build 200ifeq ($(USE_CLANG_PLATFORM_BUILD),true) 201 ifeq ($(my_clang),) 202 my_clang := true 203 endif 204endif 205 206# arch-specific static libraries go first so that generic ones can depend on them 207my_static_libraries := $(LOCAL_STATIC_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_STATIC_LIBRARIES_$(my_32_64_bit_suffix)) $(my_static_libraries) 208my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_WHOLE_STATIC_LIBRARIES_$(my_32_64_bit_suffix)) $(my_whole_static_libraries) 209 210include $(BUILD_SYSTEM)/cxx_stl_setup.mk 211 212# Add static HAL libraries 213ifdef LOCAL_HAL_STATIC_LIBRARIES 214$(foreach lib, $(LOCAL_HAL_STATIC_LIBRARIES), \ 215 $(eval b_lib := $(filter $(lib).%,$(BOARD_HAL_STATIC_LIBRARIES)))\ 216 $(if $(b_lib), $(eval my_static_libraries += $(b_lib)),\ 217 $(eval my_static_libraries += $(lib).default))) 218b_lib := 219endif 220 221my_linker := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LINKER) 222 223include $(BUILD_SYSTEM)/config_sanitizers.mk 224 225ifeq ($(strip $($(LOCAL_2ND_ARCH_VAR_PREFIX)WITHOUT_$(my_prefix)CLANG)),true) 226 my_clang := 227endif 228 229# Add in libcompiler_rt for all regular device builds 230ifeq (,$(LOCAL_SDK_VERSION)$(WITHOUT_LIBCOMPILER_RT)) 231 my_static_libraries += $(COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES) 232endif 233 234#################################################### 235## Add FDO flags if FDO is turned on and supported 236## Please note that we will do option filtering during FDO build. 237## i.e. Os->O2, remove -fno-early-inline and -finline-limit. 238################################################################## 239my_fdo_build := 240ifneq ($(filter true always, $(LOCAL_FDO_SUPPORT)),) 241 ifeq ($(BUILD_FDO_INSTRUMENT),true) 242 my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_CFLAGS) 243 my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_LDFLAGS) 244 my_fdo_build := true 245 else ifneq ($(filter true,$(BUILD_FDO_OPTIMIZE))$(filter always,$(LOCAL_FDO_SUPPORT)),) 246 my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_OPTIMIZE_CFLAGS) 247 my_fdo_build := true 248 endif 249 # Disable ccache (or other compiler wrapper). 250 my_cc_wrapper := 251 my_cxx_wrapper := 252endif 253 254########################################################### 255## Explicitly declare assembly-only __ASSEMBLY__ macro for 256## assembly source 257########################################################### 258my_asflags += -D__ASSEMBLY__ 259 260 261########################################################### 262## Define PRIVATE_ variables from global vars 263########################################################### 264ifndef LOCAL_IS_HOST_MODULE 265ifdef LOCAL_SDK_VERSION 266my_target_project_includes := 267my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_sysroot_include) 268my_target_global_cppflags := $(my_ndk_stl_cppflags) 269else 270my_target_project_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PROJECT_INCLUDES) 271my_target_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_C_INCLUDES) 272my_target_global_cppflags := 273endif # LOCAL_SDK_VERSION 274 275ifeq ($(my_clang),true) 276my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CFLAGS) 277my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CONLYFLAGS) 278my_target_global_cppflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CPPFLAGS) 279my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_LDFLAGS) 280else 281my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CFLAGS) 282my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CONLYFLAGS) 283my_target_global_cppflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CPPFLAGS) 284my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LDFLAGS) 285endif # my_clang 286 287$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes) 288$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes) 289$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags) 290$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CONLYFLAGS := $(my_target_global_conlyflags) 291$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags) 292$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags) 293 294else # LOCAL_IS_HOST_MODULE 295 296ifeq ($(my_clang),true) 297my_host_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_HOST_GLOBAL_CFLAGS) 298my_host_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_HOST_GLOBAL_CONLYFLAGS) 299my_host_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_HOST_GLOBAL_CPPFLAGS) 300my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_HOST_GLOBAL_LDFLAGS) 301my_host_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_C_INCLUDES) 302else 303my_host_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_CFLAGS) 304my_host_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_CONLYFLAGS) 305my_host_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_CPPFLAGS) 306my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_LDFLAGS) 307my_host_c_includes := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_C_INCLUDES) 308endif # my_clang 309 310$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_C_INCLUDES := $(my_host_c_includes) 311$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CFLAGS := $(my_host_global_cflags) 312$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CONLYFLAGS := $(my_host_global_conlyflags) 313$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CPPFLAGS := $(my_host_global_cppflags) 314$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_LDFLAGS := $(my_host_global_ldflags) 315endif # LOCAL_IS_HOST_MODULE 316 317# To enable coverage for a given module, set LOCAL_NATIVE_COVERAGE=true and 318# build with NATIVE_COVERAGE=true in your enviornment. Note that the build 319# system is not sensitive to changes to NATIVE_COVERAGE, so you should do a 320# clean build of your module after toggling it. 321ifeq ($(NATIVE_COVERAGE),true) 322 ifeq ($(my_native_coverage),true) 323 # Note that clang coverage doesn't play nicely with acov out of the box. 324 # Clang apparently generates .gcno files that aren't compatible with 325 # gcov-4.8. This can be solved by installing gcc-4.6 and invoking lcov 326 # with `--gcov-tool /usr/bin/gcov-4.6`. 327 # 328 # http://stackoverflow.com/questions/17758126/clang-code-coverage-invalid-output 329 my_cflags += --coverage -O0 330 my_ldflags += --coverage 331 endif 332else 333 my_native_coverage := false 334endif 335 336########################################################### 337## Define PRIVATE_ variables used by multiple module types 338########################################################### 339$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \ 340 $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)) 341 342ifeq ($(strip $(WITH_SYNTAX_CHECK)),) 343 LOCAL_NO_SYNTAX_CHECK := true 344endif 345 346ifeq ($(strip $(WITH_STATIC_ANALYZER)),) 347 LOCAL_NO_STATIC_ANALYZER := true 348endif 349 350ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),) 351 my_syntax_arch := host 352else 353 my_syntax_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) 354endif 355 356ifeq ($(strip $(my_cc)),) 357 ifeq ($(my_clang),true) 358 my_cc := $(CLANG) 359 else 360 my_cc := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)CC) 361 endif 362 my_cc := $(my_cc_wrapper) $(my_cc) 363endif 364ifneq ($(LOCAL_NO_STATIC_ANALYZER),true) 365 my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer $(my_syntax_arch) "$(my_cc)" 366else 367ifneq ($(LOCAL_NO_SYNTAX_CHECK),true) 368 my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-syntax $(my_syntax_arch) "$(my_cc)" 369endif 370endif 371$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(my_cc) 372 373ifeq ($(strip $(my_cxx)),) 374 ifeq ($(my_clang),true) 375 my_cxx := $(CLANG_CXX) 376 else 377 my_cxx := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)CXX) 378 endif 379 my_cxx := $(my_cxx_wrapper) $(my_cxx) 380endif 381ifneq ($(LOCAL_NO_STATIC_ANALYZER),true) 382 my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-analyzer $(my_syntax_arch) "$(my_cxx)" 383else 384ifneq ($(LOCAL_NO_SYNTAX_CHECK),true) 385 my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-syntax $(my_syntax_arch) "$(my_cxx)" 386endif 387endif 388$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LINKER := $(my_linker) 389$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(my_cxx) 390$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLANG := $(my_clang) 391 392# TODO: support a mix of standard extensions so that this isn't necessary 393LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) 394ifeq ($(LOCAL_CPP_EXTENSION),) 395 LOCAL_CPP_EXTENSION := .cpp 396endif 397$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPP_EXTENSION := $(LOCAL_CPP_EXTENSION) 398 399# Certain modules like libdl have to have symbols resolved at runtime and blow 400# up if --no-undefined is passed to the linker. 401ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),) 402ifeq ($(my_allow_undefined_symbols),) 403 my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)NO_UNDEFINED_LDFLAGS) 404endif 405endif 406 407ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES)) 408$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true 409else 410$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := 411endif 412 413########################################################### 414## Define arm-vs-thumb-mode flags. 415########################################################### 416LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE)) 417ifeq ($($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH),arm) 418arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm) 419normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb) 420 421# Read the values from something like TARGET_arm_CFLAGS or 422# TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't 423# actually used (although they are usually empty). 424arm_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(arm_objects_mode)_CFLAGS) 425normal_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(normal_objects_mode)_CFLAGS) 426ifeq ($(my_clang),true) 427arm_objects_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(arm_objects_cflags)) 428normal_objects_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(normal_objects_cflags)) 429endif 430 431else 432arm_objects_mode := 433normal_objects_mode := 434arm_objects_cflags := 435normal_objects_cflags := 436endif 437 438########################################################### 439## Define per-module debugging flags. Users can turn on 440## debugging for a particular module by setting DEBUG_MODULE_ModuleName 441## to a non-empty value in their environment or buildspec.mk, 442## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the 443## debug flags that they want to use. 444########################################################### 445ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE)) 446 debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS) 447else 448 debug_cflags := 449endif 450 451#################################################### 452## Compile RenderScript with reflected C++ 453#################################################### 454 455renderscript_sources := $(filter %.rs %.fs,$(my_src_files)) 456 457ifneq (,$(renderscript_sources)) 458 459renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources)) 460RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp 461renderscript_intermediate := $(intermediates)/renderscript 462 463renderscript_target_api := 464 465ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API)) 466renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API) 467else 468ifneq (,$(LOCAL_SDK_VERSION)) 469# Set target-api for LOCAL_SDK_VERSIONs other than current. 470ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION))) 471renderscript_target_api := $(LOCAL_SDK_VERSION) 472endif 473endif # LOCAL_SDK_VERSION is set 474endif # LOCAL_RENDERSCRIPT_TARGET_API is set 475 476 477ifeq ($(LOCAL_RENDERSCRIPT_CC),) 478LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC) 479endif 480 481# Turn on all warnings and warnings as errors for RS compiles. 482# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error 483renderscript_flags := -Wall -Werror 484renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS) 485# -m32 or -m64 486renderscript_flags += -m$(my_32_64_bit_suffix) 487 488renderscript_includes := \ 489 $(TOPDIR)external/clang/lib/Headers \ 490 $(TOPDIR)frameworks/rs/scriptc \ 491 $(LOCAL_RENDERSCRIPT_INCLUDES) 492 493ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),) 494renderscript_includes := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE) 495endif 496 497bc_dep_files := $(addprefix $(renderscript_intermediate)/, \ 498 $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources))))) 499 500$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(renderscript_includes) 501$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC) 502$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags) 503$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath) 504$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate) 505$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(renderscript_target_api) 506$(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files) 507$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC) 508 $(transform-renderscripts-to-cpp-and-bc) 509 510# include the dependency files (.d/.P) generated by llvm-rs-cc. 511-include $(bc_dep_files:%.d=%.P) 512 513LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp) 514 515rs_generated_cpps := $(addprefix \ 516 $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rs,%.cpp, \ 517 $(notdir $(renderscript_sources))))) 518 519# This is just a dummy rule to make sure gmake doesn't skip updating the dependents. 520$(rs_generated_cpps) : $(RenderScript_file_stamp) 521 @echo "Updated RS generated cpp file $@." 522 523my_c_includes += $(renderscript_intermediate) 524my_generated_sources += $(rs_generated_cpps) 525 526endif 527 528 529########################################################### 530## Stuff source generated from one-off tools 531########################################################### 532$(my_generated_sources): PRIVATE_MODULE := $(my_register_name) 533 534my_gen_sources_copy := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(filter $(generated_sources_dir)/%,$(my_generated_sources))) 535 536$(my_gen_sources_copy): $(intermediates)/% : $(generated_sources_dir)/% | $(ACP) 537 @echo "Copy: $@" 538 $(copy-file-to-target) 539 540my_generated_sources := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(my_generated_sources)) 541 542ALL_GENERATED_SOURCES += $(my_generated_sources) 543 544########################################################### 545## Compile the .proto files to .cc (or .c) and then to .o 546########################################################### 547proto_sources := $(filter %.proto,$(my_src_files)) 548proto_generated_objects := 549proto_generated_headers := 550ifneq ($(proto_sources),) 551proto_generated_sources_dir := $(generated_sources_dir)/proto 552proto_generated_obj_dir := $(intermediates)/proto 553 554ifneq (,$(filter nanopb-c nanopb-c-enable_malloc, $(LOCAL_PROTOC_OPTIMIZE_TYPE))) 555my_proto_source_suffix := .c 556my_proto_c_includes := external/nanopb-c 557my_protoc_flags := --nanopb_out=$(proto_generated_sources_dir) \ 558 --plugin=external/nanopb-c/generator/protoc-gen-nanopb 559else 560my_proto_source_suffix := .cc 561my_proto_c_includes := external/protobuf/src 562my_cflags += -DGOOGLE_PROTOBUF_NO_RTTI 563my_protoc_flags := --cpp_out=$(proto_generated_sources_dir) 564endif 565my_proto_c_includes += $(proto_generated_sources_dir) 566 567proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources)) 568proto_generated_sources := $(addprefix $(proto_generated_sources_dir)/, \ 569 $(patsubst %.proto,%.pb$(my_proto_source_suffix),$(proto_sources_fullpath))) 570proto_generated_headers := $(patsubst %.pb$(my_proto_source_suffix),%.pb.h, $(proto_generated_sources)) 571proto_generated_objects := $(addprefix $(proto_generated_obj_dir)/, \ 572 $(patsubst %.proto,%.pb.o,$(proto_sources_fullpath))) 573 574# Ensure the transform-proto-to-cc rule is only defined once in multilib build. 575ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined 576$(proto_generated_sources): PRIVATE_PROTO_INCLUDES := $(TOP) 577$(proto_generated_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) $(my_protoc_flags) 578$(proto_generated_sources): $(proto_generated_sources_dir)/%.pb$(my_proto_source_suffix): %.proto $(PROTOC) 579 $(transform-proto-to-cc) 580 581# This is just a dummy rule to make sure gmake doesn't skip updating the dependents. 582$(proto_generated_headers): $(proto_generated_sources_dir)/%.pb.h: $(proto_generated_sources_dir)/%.pb$(my_proto_source_suffix) 583 @echo "Updated header file $@." 584 585$(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined := true 586endif # transform-proto-to-cc rule included only once 587 588$(proto_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 589$(proto_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 590$(proto_generated_objects): $(proto_generated_obj_dir)/%.o: $(proto_generated_sources_dir)/%$(my_proto_source_suffix) $(proto_generated_headers) 591ifeq ($(my_proto_source_suffix),.c) 592 $(transform-$(PRIVATE_HOST)c-to-o) 593else 594 $(transform-$(PRIVATE_HOST)cpp-to-o) 595endif 596-include $(proto_generated_objects:%.o=%.P) 597 598my_c_includes += $(my_proto_c_includes) 599# Auto-export the generated proto source dir. 600my_export_c_include_dirs += $(my_proto_c_includes) 601 602ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc) 603 my_static_libraries += libprotobuf-c-nano-enable_malloc 604else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c) 605 my_static_libraries += libprotobuf-c-nano 606else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full) 607 ifdef LOCAL_SDK_VERSION 608 my_static_libraries += libprotobuf-cpp-full 609 else 610 my_shared_libraries += libprotobuf-cpp-full 611 endif 612else 613 ifdef LOCAL_SDK_VERSION 614 my_static_libraries += libprotobuf-cpp-lite 615 else 616 my_shared_libraries += libprotobuf-cpp-lite 617 endif 618endif 619endif # $(proto_sources) non-empty 620 621########################################################### 622## Compile the .dbus.xml files to c++ headers 623########################################################### 624dbus_definitions := $(filter %.dbus.xml,$(my_src_files)) 625dbus_generated_headers := 626ifneq ($(dbus_definitions),) 627 628dbus_definition_paths := $(addprefix $(LOCAL_PATH)/,$(dbus_definitions)) 629dbus_service_config := $(filter %dbus-service-config.json,$(my_src_files)) 630dbus_service_config_path := $(addprefix $(LOCAL_PATH)/,$(dbus_service_config)) 631 632dbus_gen_dir := $(generated_sources_dir)/dbus_bindings 633 634ifdef LOCAL_DBUS_PROXY_PREFIX 635dbus_header_dir := $(dbus_gen_dir)/include/$(LOCAL_DBUS_PROXY_PREFIX) 636dbus_headers := dbus-proxies.h 637else 638dbus_header_dir := $(dbus_gen_dir) 639dbus_headers := $(patsubst %.dbus.xml,%.h,$(dbus_definitions)) 640endif 641dbus_generated_headers := $(addprefix $(dbus_header_dir)/,$(dbus_headers)) 642 643# Ensure that we only define build rules once in multilib builds. 644ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_dbus_bindings_defined 645$(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_dbus_bindings_defined := true 646 647$(dbus_generated_headers): PRIVATE_MODULE := $(LOCAL_MODULE) 648$(dbus_generated_headers): PRIVATE_DBUS_SERVICE_CONFIG := $(dbus_service_config_path) 649$(dbus_generated_headers) : $(dbus_service_config_path) $(DBUS_GENERATOR) 650ifdef LOCAL_DBUS_PROXY_PREFIX 651$(dbus_generated_headers) : $(dbus_definition_paths) 652 $(generate-dbus-proxies) 653 654# Auto-export the generated dbus proxy directory. 655my_export_c_include_dirs += $(dbus_gen_dir)/include 656my_c_includes += $(dbus_gen_dir)/include 657else 658$(dbus_generated_headers) : $(dbus_header_dir)/%.h : $(LOCAL_PATH)/%.dbus.xml 659 $(generate-dbus-adaptors) 660 661my_export_c_include_dirs += $(dbus_header_dir) 662my_c_includes += $(dbus_header_dir) 663endif # $(LOCAL_DBUS_PROXY_PREFIX) 664endif # $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_dbus_bindings_defined 665 666my_generated_sources += $(dbus_generated_headers) 667 668endif # $(dbus_definitions) non-empty 669 670 671########################################################### 672## YACC: Compile .y and .yy files to .cpp and the to .o. 673########################################################### 674 675y_yacc_sources := $(filter %.y,$(my_src_files)) 676y_yacc_cpps := $(addprefix \ 677 $(intermediates)/,$(y_yacc_sources:.y=$(LOCAL_CPP_EXTENSION))) 678 679yy_yacc_sources := $(filter %.yy,$(my_src_files)) 680yy_yacc_cpps := $(addprefix \ 681 $(intermediates)/,$(yy_yacc_sources:.yy=$(LOCAL_CPP_EXTENSION))) 682 683yacc_cpps := $(y_yacc_cpps) $(yy_yacc_cpps) 684yacc_headers := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.h) 685yacc_objects := $(yacc_cpps:$(LOCAL_CPP_EXTENSION)=.o) 686 687ifneq ($(strip $(y_yacc_cpps)),) 688$(y_yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ 689 $(TOPDIR)$(LOCAL_PATH)/%.y \ 690 $(lex_cpps) $(my_additional_dependencies) 691 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION)) 692$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION) 693endif 694 695ifneq ($(strip $(yy_yacc_cpps)),) 696$(yy_yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ 697 $(TOPDIR)$(LOCAL_PATH)/%.yy \ 698 $(lex_cpps) $(my_additional_dependencies) 699 $(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION)) 700$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION) 701endif 702 703ifneq ($(strip $(yacc_cpps)),) 704$(yacc_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 705$(yacc_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 706$(yacc_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) 707 $(transform-$(PRIVATE_HOST)cpp-to-o) 708endif 709 710########################################################### 711## LEX: Compile .l and .ll files to .cpp and then to .o. 712########################################################### 713 714l_lex_sources := $(filter %.l,$(my_src_files)) 715l_lex_cpps := $(addprefix \ 716 $(intermediates)/,$(l_lex_sources:.l=$(LOCAL_CPP_EXTENSION))) 717 718ll_lex_sources := $(filter %.ll,$(my_src_files)) 719ll_lex_cpps := $(addprefix \ 720 $(intermediates)/,$(ll_lex_sources:.ll=$(LOCAL_CPP_EXTENSION))) 721 722lex_cpps := $(l_lex_cpps) $(ll_lex_cpps) 723lex_objects := $(lex_cpps:$(LOCAL_CPP_EXTENSION)=.o) 724 725ifneq ($(strip $(l_lex_cpps)),) 726$(l_lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ 727 $(TOPDIR)$(LOCAL_PATH)/%.l 728 $(transform-l-to-cpp) 729endif 730 731ifneq ($(strip $(ll_lex_cpps)),) 732$(ll_lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \ 733 $(TOPDIR)$(LOCAL_PATH)/%.ll 734 $(transform-l-to-cpp) 735endif 736 737ifneq ($(strip $(lex_cpps)),) 738$(lex_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 739$(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 740$(lex_objects): $(intermediates)/%.o: \ 741 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \ 742 $(my_additional_dependencies) \ 743 $(yacc_headers) 744 $(transform-$(PRIVATE_HOST)cpp-to-o) 745endif 746 747########################################################### 748## C++: Compile .cpp files to .o. 749########################################################### 750 751# we also do this on host modules, even though 752# it's not really arm, because there are files that are shared. 753cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(my_src_files))) 754dotdot_arm_sources := $(filter ../%,$(cpp_arm_sources)) 755cpp_arm_sources := $(filter-out ../%,$(cpp_arm_sources)) 756cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o)) 757 758# For source files starting with ../, we remove all the ../ in the object file path, 759# to avoid object file escaping the intermediate directory. 760dotdot_arm_objects := 761$(foreach s,$(dotdot_arm_sources),\ 762 $(eval $(call compile-dotdot-cpp-file,$(s),\ 763 $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\ 764 dotdot_arm_objects))) 765 766dotdot_sources := $(filter ../%$(LOCAL_CPP_EXTENSION),$(my_src_files)) 767dotdot_objects := 768$(foreach s,$(dotdot_sources),\ 769 $(eval $(call compile-dotdot-cpp-file,$(s),\ 770 $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\ 771 dotdot_objects))) 772 773cpp_normal_sources := $(filter-out ../%,$(filter %$(LOCAL_CPP_EXTENSION),$(my_src_files))) 774cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o)) 775 776$(dotdot_arm_objects) $(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode) 777$(dotdot_arm_objects) $(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags) 778$(dotdot_objects) $(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 779$(dotdot_objects) $(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 780 781cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects) 782 783ifneq ($(strip $(cpp_objects)),) 784$(cpp_objects): $(intermediates)/%.o: \ 785 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \ 786 $(yacc_cpps) $(proto_generated_headers) \ 787 $(my_additional_dependencies) 788 $(transform-$(PRIVATE_HOST)cpp-to-o) 789-include $(cpp_objects:%.o=%.P) 790endif 791 792cpp_objects += $(dotdot_arm_objects) $(dotdot_objects) 793 794########################################################### 795## C++: Compile generated .cpp files to .o. 796########################################################### 797 798gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(my_generated_sources)) 799gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o) 800 801ifneq ($(strip $(gen_cpp_objects)),) 802# Compile all generated files as thumb. 803# TODO: support compiling certain generated files as arm. 804$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 805$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 806$(gen_cpp_objects): $(intermediates)/%.o: \ 807 $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) \ 808 $(proto_generated_headers) \ 809 $(my_additional_dependencies) 810 $(transform-$(PRIVATE_HOST)cpp-to-o) 811-include $(gen_cpp_objects:%.o=%.P) 812endif 813 814########################################################### 815## S: Compile generated .S and .s files to .o. 816########################################################### 817 818gen_S_sources := $(filter %.S,$(my_generated_sources)) 819gen_S_objects := $(gen_S_sources:%.S=%.o) 820 821ifneq ($(strip $(gen_S_sources)),) 822$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \ 823 $(my_additional_dependencies) 824 $(transform-$(PRIVATE_HOST)s-to-o) 825-include $(gen_S_objects:%.o=%.P) 826endif 827 828gen_s_sources := $(filter %.s,$(my_generated_sources)) 829gen_s_objects := $(gen_s_sources:%.s=%.o) 830 831ifneq ($(strip $(gen_s_objects)),) 832$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \ 833 $(my_additional_dependencies) 834 $(transform-$(PRIVATE_HOST)s-to-o-no-deps) 835-include $(gen_s_objects:%.o=%.P) 836endif 837 838gen_asm_objects := $(gen_S_objects) $(gen_s_objects) 839 840########################################################### 841## o: Include generated .o files in output. 842########################################################### 843 844gen_o_objects := $(filter %.o,$(my_generated_sources)) 845 846########################################################### 847## C: Compile .c files to .o. 848########################################################### 849 850c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(my_src_files))) 851dotdot_arm_sources := $(filter ../%,$(c_arm_sources)) 852c_arm_sources := $(filter-out ../%,$(c_arm_sources)) 853c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o)) 854 855# For source files starting with ../, we remove all the ../ in the object file path, 856# to avoid object file escaping the intermediate directory. 857dotdot_arm_objects := 858$(foreach s,$(dotdot_arm_sources),\ 859 $(eval $(call compile-dotdot-c-file,$(s),\ 860 $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\ 861 dotdot_arm_objects))) 862 863dotdot_sources := $(filter ../%.c, $(my_src_files)) 864dotdot_objects := 865$(foreach s, $(dotdot_sources),\ 866 $(eval $(call compile-dotdot-c-file,$(s),\ 867 $(yacc_cpps) $(proto_generated_headers) $(my_additional_dependencies),\ 868 dotdot_objects))) 869 870c_normal_sources := $(filter-out ../%,$(filter %.c,$(my_src_files))) 871c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o)) 872 873$(dotdot_arm_objects) $(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode) 874$(dotdot_arm_objects) $(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags) 875$(dotdot_objects) $(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 876$(dotdot_objects) $(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 877 878c_objects := $(c_arm_objects) $(c_normal_objects) 879 880ifneq ($(strip $(c_objects)),) 881$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \ 882 $(my_additional_dependencies) 883 $(transform-$(PRIVATE_HOST)c-to-o) 884-include $(c_objects:%.o=%.P) 885endif 886 887c_objects += $(dotdot_arm_objects) $(dotdot_objects) 888 889########################################################### 890## C: Compile generated .c files to .o. 891########################################################### 892 893gen_c_sources := $(filter %.c,$(my_generated_sources)) 894gen_c_objects := $(gen_c_sources:%.c=%.o) 895 896ifneq ($(strip $(gen_c_objects)),) 897# Compile all generated files as thumb. 898# TODO: support compiling certain generated files as arm. 899$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) 900$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) 901$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \ 902 $(my_additional_dependencies) 903 $(transform-$(PRIVATE_HOST)c-to-o) 904-include $(gen_c_objects:%.o=%.P) 905endif 906 907########################################################### 908## ObjC: Compile .m files to .o 909########################################################### 910 911objc_sources := $(filter %.m,$(my_src_files)) 912objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o)) 913 914ifneq ($(strip $(objc_objects)),) 915$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) \ 916 $(my_additional_dependencies) 917 $(transform-$(PRIVATE_HOST)m-to-o) 918-include $(objc_objects:%.o=%.P) 919endif 920 921########################################################### 922## AS: Compile .S files to .o. 923########################################################### 924 925asm_sources_S := $(filter %.S,$(my_src_files)) 926dotdot_sources := $(filter ../%,$(asm_sources_S)) 927asm_sources_S := $(filter-out ../%,$(asm_sources_S)) 928asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o)) 929 930dotdot_objects_S := 931$(foreach s,$(dotdot_sources),\ 932 $(eval $(call compile-dotdot-s-file,$(s),\ 933 $(my_additional_dependencies),\ 934 dotdot_objects_S))) 935 936ifneq ($(strip $(asm_objects_S)),) 937$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \ 938 $(my_additional_dependencies) 939 $(transform-$(PRIVATE_HOST)s-to-o) 940-include $(asm_objects_S:%.o=%.P) 941endif 942 943asm_sources_s := $(filter %.s,$(my_src_files)) 944dotdot_sources := $(filter ../%,$(asm_sources_s)) 945asm_sources_s := $(filter-out ../%,$(asm_sources_s)) 946asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o)) 947 948dotdot_objects_s := 949$(foreach s,$(dotdot_sources),\ 950 $(eval $(call compile-dotdot-s-file-no-deps,$(s),\ 951 $(my_additional_dependencies),\ 952 dotdot_objects_s))) 953 954ifneq ($(strip $(asm_objects_s)),) 955$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \ 956 $(my_additional_dependencies) 957 $(transform-$(PRIVATE_HOST)s-to-o-no-deps) 958endif 959 960asm_objects := $(dotdot_objects_S) $(dotdot_objects_s) $(asm_objects_S) $(asm_objects_s) 961 962 963# .asm for x86/x86_64 needs to be compiled with yasm. 964asm_sources_asm := $(filter %.asm,$(my_src_files)) 965ifneq ($(strip $(asm_sources_asm)),) 966asm_objects_asm := $(addprefix $(intermediates)/,$(asm_sources_asm:.asm=.o)) 967$(asm_objects_asm): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.asm \ 968 $(my_additional_dependencies) 969 $(transform-asm-to-o) 970 971asm_objects += $(asm_objects_asm) 972endif 973 974 975########################################################## 976## Set up installed module dependency 977## We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for 978## they may cusomize their install path with LOCAL_MODULE_PATH 979########################################################## 980# Get the list of INSTALLED libraries as module names. 981ifdef LOCAL_SDK_VERSION 982 installed_shared_library_module_names := \ 983 $(my_shared_libraries) 984else 985 installed_shared_library_module_names := \ 986 $(my_shared_libraries) $(my_system_shared_libraries) 987endif 988 989# The real dependency will be added after all Android.mks are loaded and the install paths 990# of the shared libraries are determined. 991ifdef LOCAL_INSTALLED_MODULE 992ifdef installed_shared_library_module_names 993$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \ 994 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(sort $(installed_shared_library_module_names))) 995endif 996endif 997 998 999#################################################### 1000## Import includes 1001#################################################### 1002import_includes := $(intermediates)/import_includes 1003import_includes_deps := $(strip \ 1004 $(foreach l, $(installed_shared_library_module_names), \ 1005 $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/export_includes) \ 1006 $(foreach l, $(my_static_libraries) $(my_whole_static_libraries), \ 1007 $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/export_includes)) 1008$(import_includes): PRIVATE_IMPORT_EXPORT_INCLUDES := $(import_includes_deps) 1009$(import_includes) : $(LOCAL_MODULE_MAKEFILE) $(import_includes_deps) 1010 @echo Import includes file: $@ 1011 $(hide) mkdir -p $(dir $@) && rm -f $@ 1012ifdef import_includes_deps 1013 $(hide) for f in $(PRIVATE_IMPORT_EXPORT_INCLUDES); do \ 1014 cat $$f >> $@; \ 1015 done 1016else 1017 $(hide) touch $@ 1018endif 1019 1020########################################################### 1021## Common object handling. 1022########################################################### 1023 1024# some rules depend on asm_objects being first. If your code depends on 1025# being first, it's reasonable to require it to be assembly 1026normal_objects := \ 1027 $(asm_objects) \ 1028 $(cpp_objects) \ 1029 $(gen_cpp_objects) \ 1030 $(gen_asm_objects) \ 1031 $(c_objects) \ 1032 $(gen_c_objects) \ 1033 $(objc_objects) \ 1034 $(yacc_objects) \ 1035 $(lex_objects) \ 1036 $(proto_generated_objects) \ 1037 $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES)) 1038 1039all_objects := $(normal_objects) $(gen_o_objects) 1040 1041my_c_includes += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(generated_sources_dir) 1042 1043ifndef LOCAL_SDK_VERSION 1044 my_c_includes += $(JNI_H_INCLUDE) 1045endif 1046 1047# all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES; 1048# use normal_objects here to avoid creating circular dependencies. This assumes 1049# that custom build rules which generate .o files don't consume other generated 1050# sources as input (or if they do they take care of that dependency themselves). 1051$(normal_objects) : | $(my_generated_sources) 1052$(all_objects) : | $(import_includes) 1053ALL_C_CPP_ETC_OBJECTS += $(all_objects) 1054 1055 1056########################################################### 1057# Standard library handling. 1058########################################################### 1059 1060########################################################### 1061# The list of libraries that this module will link against are in 1062# these variables. Each is a list of bare module names like "libc libm". 1063# 1064# LOCAL_SHARED_LIBRARIES 1065# LOCAL_STATIC_LIBRARIES 1066# LOCAL_WHOLE_STATIC_LIBRARIES 1067# 1068# We need to convert the bare names into the dependencies that 1069# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE. 1070# LOCAL_BUILT_MODULE should depend on the BUILT versions of the 1071# libraries, so that simply building this module doesn't force 1072# an install of a library. Similarly, LOCAL_INSTALLED_MODULE 1073# should depend on the INSTALLED versions of the libraries so 1074# that they get installed when this module does. 1075########################################################### 1076# NOTE: 1077# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the 1078# module without leaving anything out, which is useful for turning 1079# a collection of .a files into a .so file. Linking against a 1080# normal STATIC_LIBRARY will only pull in code/symbols that are 1081# referenced by the module. (see gcc/ld's --whole-archive option) 1082########################################################### 1083 1084# Get the list of BUILT libraries, which are under 1085# various intermediates directories. 1086so_suffix := $($(my_prefix)SHLIB_SUFFIX) 1087a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX) 1088 1089ifdef LOCAL_SDK_VERSION 1090built_shared_libraries := \ 1091 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ 1092 $(addsuffix $(so_suffix), \ 1093 $(my_shared_libraries))) 1094 1095# Add the NDK libraries to the built module dependency 1096my_system_shared_libraries_fullpath := \ 1097 $(my_ndk_stl_shared_lib_fullpath) \ 1098 $(addprefix $(my_ndk_sysroot_lib)/, \ 1099 $(addsuffix $(so_suffix), $(my_system_shared_libraries))) 1100 1101built_shared_libraries += $(my_system_shared_libraries_fullpath) 1102else 1103built_shared_libraries := \ 1104 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ 1105 $(addsuffix $(so_suffix), \ 1106 $(installed_shared_library_module_names))) 1107endif 1108 1109built_static_libraries := \ 1110 $(foreach lib,$(my_static_libraries), \ 1111 $(call intermediates-dir-for, \ 1112 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/$(lib)$(a_suffix)) 1113 1114ifdef LOCAL_SDK_VERSION 1115built_static_libraries += $(my_ndk_stl_static_lib) 1116endif 1117 1118built_whole_libraries := \ 1119 $(foreach lib,$(my_whole_static_libraries), \ 1120 $(call intermediates-dir-for, \ 1121 STATIC_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX))/$(lib)$(a_suffix)) 1122 1123# We don't care about installed static libraries, since the 1124# libraries have already been linked into the module at that point. 1125# We do, however, care about the NOTICE files for any static 1126# libraries that we use. (see notice_files.mk) 1127 1128installed_static_library_notice_file_targets := \ 1129 $(foreach lib,$(my_static_libraries) $(my_whole_static_libraries), \ 1130 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST,TARGET)-STATIC_LIBRARIES-$(lib)) 1131 1132# Default is -fno-rtti. 1133ifeq ($(strip $(LOCAL_RTTI_FLAG)),) 1134LOCAL_RTTI_FLAG := -fno-rtti 1135endif 1136 1137########################################################### 1138# Rule-specific variable definitions 1139########################################################### 1140 1141ifeq ($(my_clang),true) 1142my_cflags += $(LOCAL_CLANG_CFLAGS) 1143my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS) 1144my_cppflags += $(LOCAL_CLANG_CPPFLAGS) 1145my_cflags_no_override += $(GLOBAL_CLANG_CFLAGS_NO_OVERRIDE) 1146my_cppflags_no_override += $(GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE) 1147my_asflags += $(LOCAL_CLANG_ASFLAGS) 1148my_ldflags += $(LOCAL_CLANG_LDFLAGS) 1149my_cflags += $(LOCAL_CLANG_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CFLAGS_$(my_32_64_bit_suffix)) 1150my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CONLYFLAGS_$(my_32_64_bit_suffix)) 1151my_cppflags += $(LOCAL_CLANG_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CPPFLAGS_$(my_32_64_bit_suffix)) 1152my_ldflags += $(LOCAL_CLANG_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_LDFLAGS_$(my_32_64_bit_suffix)) 1153my_asflags += $(LOCAL_CLANG_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_ASFLAGS_$(my_32_64_bit_suffix)) 1154my_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_cflags)) 1155my_cppflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_cppflags)) 1156my_asflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_asflags)) 1157my_ldflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_ldflags)) 1158endif 1159 1160ifeq ($(my_fdo_build), true) 1161 my_cflags := $(patsubst -Os,-O2,$(my_cflags)) 1162 fdo_incompatible_flags := -fno-early-inlining -finline-limit=% 1163 my_cflags := $(filter-out $(fdo_incompatible_flags),$(my_cflags)) 1164endif 1165 1166# No one should ever use this flag. On GCC it's mere presence will disable all 1167# warnings, even those that are specified after it (contrary to typical warning 1168# flag behavior). This circumvents CFLAGS_NO_OVERRIDE from forcibly enabling the 1169# warnings that are *always* bugs. 1170my_illegal_flags := -w 1171my_cflags := $(filter-out $(my_illegal_flags),$(my_cflags)) 1172my_cppflags := $(filter-out $(my_illegal_flags),$(my_cppflags)) 1173my_conlyflags := $(filter-out $(my_illegal_flags),$(my_conlyflags)) 1174 1175$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS) 1176$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(my_asflags) 1177$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(my_conlyflags) 1178$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(my_cflags) 1179$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(my_cppflags) 1180$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS_NO_OVERRIDE := $(my_cflags_no_override) 1181$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS_NO_OVERRIDE := $(my_cppflags_no_override) 1182$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG) 1183$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags) 1184$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(my_c_includes) 1185$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes) 1186$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(my_ldflags) 1187$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(my_ldlibs) 1188 1189# this is really the way to get the files onto the command line instead 1190# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work 1191$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries) 1192$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries) 1193$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries) 1194$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(all_objects) 1195 1196########################################################### 1197# Define library dependencies. 1198########################################################### 1199# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE. 1200all_libraries := \ 1201 $(built_shared_libraries) \ 1202 $(built_static_libraries) \ 1203 $(built_whole_libraries) 1204 1205# Also depend on the notice files for any static libraries that 1206# are linked into this module. This will force them to be installed 1207# when this module is. 1208$(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets) 1209 1210########################################################### 1211# Export includes 1212########################################################### 1213export_includes := $(intermediates)/export_includes 1214$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(my_export_c_include_dirs) 1215# Make sure .pb.h are already generated before any dependent source files get compiled. 1216$(export_includes) : $(LOCAL_MODULE_MAKEFILE) $(proto_generated_headers) $(dbus_generated_headers) 1217 @echo Export includes file: $< -- $@ 1218 $(hide) mkdir -p $(dir $@) && rm -f $@ 1219ifdef my_export_c_include_dirs 1220 $(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \ 1221 echo "-I $$d" >> $@; \ 1222 done 1223else 1224 $(hide) touch $@ 1225endif 1226 1227# Make sure export_includes gets generated when you are running mm/mmm 1228$(LOCAL_BUILT_MODULE) : | $(export_includes) 1229