1############################################################# 2## Set up flags based on LOCAL_CXX_STL. 3## Input variables: LOCAL_CXX_STL, my_prefix 4## Output variables: My_cflags, my_c_includes, my_shared_libraries, etc. 5############################################################# 6 7# Select the appropriate C++ STL 8ifeq ($(strip $(LOCAL_CXX_STL)),default) 9 ifndef LOCAL_SDK_VERSION 10 # Platform code. Select the appropriate STL. 11 my_cxx_stl := libc++ 12 ifdef LOCAL_IS_HOST_MODULE 13 ifneq (,$(BUILD_HOST_static)) 14 my_cxx_stl := libc++_static 15 endif 16 endif 17 else 18 my_cxx_stl := ndk 19 endif 20else 21 my_cxx_stl := $(strip $(LOCAL_CXX_STL)) 22 ifdef LOCAL_SDK_VERSION 23 # The NDK has historically used LOCAL_NDK_STL_VARIANT to specify the 24 # STL. An Android.mk that specifies both LOCAL_CXX_STL and 25 # LOCAL_SDK_VERSION will incorrectly try (and most likely fail) to use 26 # the platform STL in an NDK binary. Emit an error to direct the user 27 # toward the correct option. 28 # 29 # Note that we could also accept LOCAL_CXX_STL as an alias for 30 # LOCAL_NDK_STL_VARIANT (and in fact soong does use the same name), but 31 # the two options use different names for the STLs. 32 $(error $(LOCAL_PATH): $(LOCAL_MODULE): Must use LOCAL_NDK_STL_VARIANT rather than LOCAL_CXX_STL for NDK binaries) 33 endif 34endif 35 36# Yes, this is actually what the clang driver does. 37linux_dynamic_gcclibs := -lgcc_s -lgcc -lc -lgcc_s -lgcc 38linux_static_gcclibs := -Wl,--start-group -lgcc -lgcc_eh -lc -Wl,--end-group 39darwin_dynamic_gcclibs := -lc -lSystem 40darwin_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_DARWIN 41 42my_link_type := dynamic 43ifdef LOCAL_IS_HOST_MODULE 44 ifneq (,$(BUILD_HOST_static)) 45 my_link_type := static 46 endif 47 ifeq (-static,$(filter -static,$(my_ldflags))) 48 my_link_type := static 49 endif 50else 51 ifeq (true,$(LOCAL_FORCE_STATIC_EXECUTABLE)) 52 my_link_type := static 53 endif 54endif 55 56my_cxx_ldlibs := 57ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),) 58 my_cflags += -D_USING_LIBCXX 59 60 ifeq ($($(my_prefix)OS),darwin) 61 # libc++'s headers are annotated with availability macros that indicate 62 # which version of Mac OS was the first to ship with a libc++ feature 63 # available in its *system's* libc++.dylib. We do not use the system's 64 # library, but rather ship our own. As such, these availability 65 # attributes are meaningless for us but cause build breaks when we try 66 # to use code that would not be available in the system's dylib. 67 my_cppflags += -D_LIBCPP_DISABLE_AVAILABILITY 68 endif 69 70 # Note that the structure of this means that LOCAL_CXX_STL := libc++ will 71 # use the static libc++ for static executables. 72 ifeq ($(my_link_type),dynamic) 73 ifeq ($(my_cxx_stl),libc++) 74 my_shared_libraries += libc++ 75 else 76 my_static_libraries += libc++_static 77 endif 78 else 79 my_static_libraries += libc++_static 80 endif 81 82 ifdef LOCAL_IS_HOST_MODULE 83 my_cppflags += -nostdinc++ 84 my_ldflags += -nodefaultlibs 85 my_cxx_ldlibs += $($($(my_prefix)OS)_$(my_link_type)_gcclibs) 86 else 87 ifeq (arm,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) 88 my_static_libraries += libunwind_llvm 89 my_ldflags += -Wl,--exclude-libs,libunwind_llvm.a 90 endif 91 92 ifeq ($(my_link_type),static) 93 my_static_libraries += libm libc libdl 94 endif 95 endif 96else ifeq ($(my_cxx_stl),ndk) 97 # Using an NDK STL. Handled in binary.mk. 98else ifeq ($(my_cxx_stl),libstdc++) 99 $(error $(LOCAL_PATH): $(LOCAL_MODULE): libstdc++ is not supported) 100else ifeq ($(my_cxx_stl),none) 101 ifdef LOCAL_IS_HOST_MODULE 102 my_cppflags += -nostdinc++ 103 my_ldflags += -nodefaultlibs 104 my_cxx_ldlibs += $($($(my_prefix)OS)_$(my_link_type)_gcclibs) 105 endif 106else 107 $(error $(LOCAL_PATH): $(LOCAL_MODULE): $(my_cxx_stl) is not a supported STL.) 108endif 109