Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 1 | ############################################################# |
| 2 | ## Set up flags based on LOCAL_CXX_STL. |
Dan Willemsen | 057aaea | 2015-08-14 12:59:50 -0700 | [diff] [blame] | 3 | ## Input variables: LOCAL_CXX_STL, my_prefix |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 4 | ## Output variables: My_cflags, my_c_includes, my_shared_libraries, etc. |
| 5 | ############################################################# |
| 6 | |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 7 | # Select the appropriate C++ STL |
| 8 | ifeq ($(strip $(LOCAL_CXX_STL)),default) |
| 9 | ifndef LOCAL_SDK_VERSION |
Dan Albert | 93766b2 | 2014-10-16 19:07:41 -0700 | [diff] [blame] | 10 | # Platform code. Select the appropriate STL. |
Dan Albert | 88a8ce6 | 2015-05-04 16:34:19 -0700 | [diff] [blame] | 11 | my_cxx_stl := libc++ |
| 12 | ifdef LOCAL_IS_HOST_MODULE |
| 13 | ifneq (,$(BUILD_HOST_static)) |
| 14 | my_cxx_stl := libc++_static |
Dan Albert | 8bf4cc9 | 2015-03-03 14:10:27 -0800 | [diff] [blame] | 15 | endif |
Dan Albert | 88a8ce6 | 2015-05-04 16:34:19 -0700 | [diff] [blame] | 16 | |
Dan Willemsen | 1ca3b70 | 2015-08-13 17:41:56 -0700 | [diff] [blame] | 17 | ifeq ($($(my_prefix)OS),windows) |
Pirama Arumuga Nainar | 80ba345 | 2018-08-08 10:29:00 -0700 | [diff] [blame] | 18 | my_cxx_stl := libc++_static |
Dan Albert | 88a8ce6 | 2015-05-04 16:34:19 -0700 | [diff] [blame] | 19 | endif |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 20 | endif |
| 21 | else |
| 22 | my_cxx_stl := ndk |
| 23 | endif |
| 24 | else |
| 25 | my_cxx_stl := $(strip $(LOCAL_CXX_STL)) |
Dan Albert | ef3e7cf | 2015-07-27 14:14:56 -0700 | [diff] [blame] | 26 | ifdef LOCAL_SDK_VERSION |
| 27 | # The NDK has historically used LOCAL_NDK_STL_VARIANT to specify the |
| 28 | # STL. An Android.mk that specifies both LOCAL_CXX_STL and |
| 29 | # LOCAL_SDK_VERSION will incorrectly try (and most likely fail) to use |
| 30 | # the platform STL in an NDK binary. Emit an error to direct the user |
| 31 | # toward the correct option. |
| 32 | # |
| 33 | # Note that we could also accept LOCAL_CXX_STL as an alias for |
| 34 | # LOCAL_NDK_STL_VARIANT (and in fact soong does use the same name), but |
| 35 | # the two options use different names for the STLs. |
| 36 | $(error $(LOCAL_PATH): $(LOCAL_MODULE): Must use LOCAL_NDK_STL_VARIANT rather than LOCAL_CXX_STL for NDK binaries) |
| 37 | endif |
Dan Willemsen | 1ca3b70 | 2015-08-13 17:41:56 -0700 | [diff] [blame] | 38 | ifdef LOCAL_IS_HOST_MODULE |
| 39 | ifeq ($($(my_prefix)OS),windows) |
Pirama Arumuga Nainar | 80ba345 | 2018-08-08 10:29:00 -0700 | [diff] [blame] | 40 | ifneq ($(filter $(my_cxx_stl),libc++),) |
| 41 | # only libc++_static is supported on mingw. |
| 42 | my_cxx_stl := libc++_static |
Dan Willemsen | 1ca3b70 | 2015-08-13 17:41:56 -0700 | [diff] [blame] | 43 | endif |
| 44 | endif |
| 45 | endif |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 46 | endif |
| 47 | |
Dan Albert | 4f2afde | 2015-03-03 17:42:28 -0800 | [diff] [blame] | 48 | # Yes, this is actually what the clang driver does. |
Dan Albert | d1d68b1 | 2015-09-11 10:57:14 -0700 | [diff] [blame] | 49 | linux_dynamic_gcclibs := -lgcc_s -lgcc -lc -lgcc_s -lgcc |
| 50 | linux_static_gcclibs := -Wl,--start-group -lgcc -lgcc_eh -lc -Wl,--end-group |
| 51 | darwin_dynamic_gcclibs := -lc -lSystem |
| 52 | darwin_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_DARWIN |
| 53 | windows_dynamic_gcclibs := \ |
Pirama Arumuga Nainar | 80ba345 | 2018-08-08 10:29:00 -0700 | [diff] [blame] | 54 | -Wl,--start-group -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcr110 \ |
| 55 | -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lpsapi \ |
| 56 | -Wl,--end-group |
Dan Albert | d1d68b1 | 2015-09-11 10:57:14 -0700 | [diff] [blame] | 57 | windows_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_WINDOWS |
Dan Albert | 4f2afde | 2015-03-03 17:42:28 -0800 | [diff] [blame] | 58 | |
Dan Albert | b5eb905 | 2015-03-03 18:30:27 -0800 | [diff] [blame] | 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 | |
Dan Willemsen | c9aa6fc | 2016-09-13 10:44:44 -0700 | [diff] [blame] | 73 | my_cxx_ldlibs := |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 74 | ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),) |
| 75 | my_cflags += -D_USING_LIBCXX |
Dan Albert | 0ad5bd2 | 2015-05-06 10:08:11 -0700 | [diff] [blame] | 76 | |
Dan Albert | 9262b6f | 2018-01-11 13:24:32 -0800 | [diff] [blame] | 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 | |
Dan Albert | 2a4a023 | 2015-05-12 11:00:31 -0700 | [diff] [blame] | 87 | # Note that the structure of this means that LOCAL_CXX_STL := libc++ will |
| 88 | # use the static libc++ for static executables. |
Dan Albert | 0ad5bd2 | 2015-05-06 10:08:11 -0700 | [diff] [blame] | 89 | ifeq ($(my_link_type),dynamic) |
Dan Albert | 2a4a023 | 2015-05-12 11:00:31 -0700 | [diff] [blame] | 90 | ifeq ($(my_cxx_stl),libc++) |
| 91 | my_shared_libraries += libc++ |
| 92 | else |
| 93 | my_static_libraries += libc++_static |
| 94 | endif |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 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 |
Dan Willemsen | c9aa6fc | 2016-09-13 10:44:44 -0700 | [diff] [blame] | 102 | my_cxx_ldlibs += $($($(my_prefix)OS)_$(my_link_type)_gcclibs) |
Pirama Arumuga Nainar | 80ba345 | 2018-08-08 10:29:00 -0700 | [diff] [blame] | 103 | |
| 104 | ifeq ($($(my_prefix)OS),windows) |
| 105 | # Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj |
| 106 | # exception model for 32-bit. |
| 107 | ifeq (x86,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) |
| 108 | my_cppflags += -fsjlj-exceptions |
| 109 | endif |
| 110 | # Disable visibility annotations since we're using libc++ static |
| 111 | # library. |
| 112 | my_cppflags += -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS |
| 113 | my_cppflags += -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS |
| 114 | # Use Win32 threads in libc++. |
| 115 | my_cppflags += -D_LIBCPP_HAS_THREAD_API_WIN32 |
| 116 | endif |
Dan Albert | 5036729 | 2015-03-31 15:18:17 -0700 | [diff] [blame] | 117 | else |
| 118 | ifeq (arm,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) |
| 119 | my_static_libraries += libunwind_llvm |
Dan Albert | 686a557 | 2015-06-23 13:32:30 -0700 | [diff] [blame] | 120 | my_ldflags += -Wl,--exclude-libs,libunwind_llvm.a |
Dan Albert | 5036729 | 2015-03-31 15:18:17 -0700 | [diff] [blame] | 121 | endif |
| 122 | |
| 123 | ifeq ($(my_link_type),static) |
Dan Albert | 0ad5bd2 | 2015-05-06 10:08:11 -0700 | [diff] [blame] | 124 | my_static_libraries += libm libc libdl |
Dan Albert | 5036729 | 2015-03-31 15:18:17 -0700 | [diff] [blame] | 125 | endif |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 126 | endif |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 127 | else ifeq ($(my_cxx_stl),ndk) |
Dan Albert | 3a360a7 | 2015-05-06 10:08:32 -0700 | [diff] [blame] | 128 | # Using an NDK STL. Handled in binary.mk. |
Dan Albert | 93e8cf7 | 2014-10-16 21:18:15 -0700 | [diff] [blame] | 129 | else ifeq ($(my_cxx_stl),libstdc++) |
Pirama Arumuga Nainar | 80ba345 | 2018-08-08 10:29:00 -0700 | [diff] [blame] | 130 | $(error $(LOCAL_PATH): $(LOCAL_MODULE): libstdc++ is not supported) |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 131 | else ifeq ($(my_cxx_stl),none) |
| 132 | ifdef LOCAL_IS_HOST_MODULE |
| 133 | my_cppflags += -nostdinc++ |
Dan Albert | 8bf4cc9 | 2015-03-03 14:10:27 -0800 | [diff] [blame] | 134 | my_ldflags += -nodefaultlibs |
Dan Willemsen | c9aa6fc | 2016-09-13 10:44:44 -0700 | [diff] [blame] | 135 | my_cxx_ldlibs += $($($(my_prefix)OS)_$(my_link_type)_gcclibs) |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 136 | endif |
| 137 | else |
Dan Albert | 3a360a7 | 2015-05-06 10:08:32 -0700 | [diff] [blame] | 138 | $(error $(LOCAL_PATH): $(LOCAL_MODULE): $(my_cxx_stl) is not a supported STL.) |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 139 | endif |