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