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 8 ifeq ($(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 17 ifeq ($($(my_prefix)OS),windows) 18 # libc++ is not supported on mingw. 19 my_cxx_stl := libstdc++ 20 endif 21 endif 22 else 23 my_cxx_stl := ndk 24 endif 25 else 26 my_cxx_stl := $(strip $(LOCAL_CXX_STL)) 27 ifdef LOCAL_SDK_VERSION 28 # The NDK has historically used LOCAL_NDK_STL_VARIANT to specify the 29 # STL. An Android.mk that specifies both LOCAL_CXX_STL and 30 # LOCAL_SDK_VERSION will incorrectly try (and most likely fail) to use 31 # the platform STL in an NDK binary. Emit an error to direct the user 32 # toward the correct option. 33 # 34 # Note that we could also accept LOCAL_CXX_STL as an alias for 35 # LOCAL_NDK_STL_VARIANT (and in fact soong does use the same name), but 36 # the two options use different names for the STLs. 37 $(error $(LOCAL_PATH): $(LOCAL_MODULE): Must use LOCAL_NDK_STL_VARIANT rather than LOCAL_CXX_STL for NDK binaries) 38 endif 39 ifdef LOCAL_IS_HOST_MODULE 40 ifeq ($($(my_prefix)OS),windows) 41 ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),) 42 # libc++ is not supported on mingw. 43 my_cxx_stl := libstdc++ 44 endif 45 endif 46 endif 47 endif 48 49 # Yes, this is actually what the clang driver does. 50 linux_dynamic_gcclibs := -lgcc_s -lgcc -lc -lgcc_s -lgcc 51 linux_static_gcclibs := -Wl,--start-group -lgcc -lgcc_eh -lc -Wl,--end-group 52 darwin_dynamic_gcclibs := -lc -lSystem 53 darwin_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_DARWIN 54 windows_dynamic_gcclibs := \ 55 -lmsvcr110 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 \ 56 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt 57 windows_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_WINDOWS 58 59 my_link_type := dynamic 60 ifdef LOCAL_IS_HOST_MODULE 61 ifneq (,$(BUILD_HOST_static)) 62 my_link_type := static 63 endif 64 ifeq (-static,$(filter -static,$(my_ldflags))) 65 my_link_type := static 66 endif 67 else 68 ifeq (true,$(LOCAL_FORCE_STATIC_EXECUTABLE)) 69 my_link_type := static 70 endif 71 endif 72 73 my_cxx_ldlibs := 74 ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),) 75 my_cflags += -D_USING_LIBCXX 76 77 ifeq ($($(my_prefix)OS),darwin) 78 # libc++'s headers are annotated with availability macros that indicate 79 # which version of Mac OS was the first to ship with a libc++ feature 80 # available in its *system's* libc++.dylib. We do not use the system's 81 # library, but rather ship our own. As such, these availability 82 # attributes are meaningless for us but cause build breaks when we try 83 # to use code that would not be available in the system's dylib. 84 my_cppflags += -D_LIBCPP_DISABLE_AVAILABILITY 85 endif 86 87 # Note that the structure of this means that LOCAL_CXX_STL := libc++ will 88 # use the static libc++ for static executables. 89 ifeq ($(my_link_type),dynamic) 90 ifeq ($(my_cxx_stl),libc++) 91 my_shared_libraries += libc++ 92 else 93 my_static_libraries += libc++_static 94 endif 95 else 96 my_static_libraries += libc++_static 97 endif 98 99 ifdef LOCAL_IS_HOST_MODULE 100 my_cppflags += -nostdinc++ 101 my_ldflags += -nodefaultlibs 102 my_cxx_ldlibs += $($($(my_prefix)OS)_$(my_link_type)_gcclibs) 103 else 104 ifeq (arm,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) 105 my_static_libraries += libunwind_llvm 106 my_ldflags += -Wl,--exclude-libs,libunwind_llvm.a 107 endif 108 109 ifeq ($(my_link_type),static) 110 my_static_libraries += libm libc libdl 111 endif 112 endif 113 else ifeq ($(my_cxx_stl),ndk) 114 # Using an NDK STL. Handled in binary.mk. 115 else ifeq ($(my_cxx_stl),libstdc++) 116 ifndef LOCAL_IS_HOST_MODULE 117 $(error $(LOCAL_PATH): $(LOCAL_MODULE): libstdc++ is not supported for device modules) 118 else ifneq ($($(my_prefix)OS),windows) 119 $(error $(LOCAL_PATH): $(LOCAL_MODULE): libstdc++ is not supported on $($(my_prefix)OS)) 120 endif 121 else ifeq ($(my_cxx_stl),none) 122 ifdef LOCAL_IS_HOST_MODULE 123 my_cppflags += -nostdinc++ 124 my_ldflags += -nodefaultlibs 125 my_cxx_ldlibs += $($($(my_prefix)OS)_$(my_link_type)_gcclibs) 126 endif 127 else 128 $(error $(LOCAL_PATH): $(LOCAL_MODULE): $(my_cxx_stl) is not a supported STL.) 129 endif 130