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