Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 1 | ############################################################# |
| 2 | ## Set up flags based on LOCAL_CXX_STL. |
| 3 | ## Input variables: LOCAL_CXX_STL |
| 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 | |
| 17 | ifdef USE_MINGW |
| 18 | # libc++ is not supported on mingw. |
| 19 | my_cxx_stl := libstdc++ |
| 20 | endif |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 21 | endif |
| 22 | else |
| 23 | my_cxx_stl := ndk |
| 24 | endif |
| 25 | else |
| 26 | my_cxx_stl := $(strip $(LOCAL_CXX_STL)) |
Dan Albert | ef3e7cf | 2015-07-27 14:14:56 -0700 | [diff] [blame^] | 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 |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 39 | endif |
| 40 | |
Dan Albert | 4f2afde | 2015-03-03 17:42:28 -0800 | [diff] [blame] | 41 | # Yes, this is actually what the clang driver does. |
Dan Albert | d666bb1 | 2015-03-03 21:47:04 -0800 | [diff] [blame] | 42 | HOST_linux_dynamic_gcclibs := -lgcc_s -lgcc -lc -lgcc_s -lgcc |
| 43 | HOST_linux_static_gcclibs := -Wl,--start-group -lgcc -lgcc_eh -lc -Wl,--end-group |
| 44 | HOST_darwin_dynamic_gcclibs := -lc -lSystem |
| 45 | HOST_darwin_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_DARWIN |
Dan Albert | 4f2afde | 2015-03-03 17:42:28 -0800 | [diff] [blame] | 46 | |
Dan Albert | b5eb905 | 2015-03-03 18:30:27 -0800 | [diff] [blame] | 47 | my_link_type := dynamic |
| 48 | ifdef LOCAL_IS_HOST_MODULE |
| 49 | ifneq (,$(BUILD_HOST_static)) |
| 50 | my_link_type := static |
| 51 | endif |
| 52 | ifeq (-static,$(filter -static,$(my_ldflags))) |
| 53 | my_link_type := static |
| 54 | endif |
| 55 | else |
| 56 | ifeq (true,$(LOCAL_FORCE_STATIC_EXECUTABLE)) |
| 57 | my_link_type := static |
| 58 | endif |
| 59 | endif |
| 60 | |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 61 | ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),) |
| 62 | my_cflags += -D_USING_LIBCXX |
| 63 | my_c_includes += external/libcxx/include |
Dan Albert | 0ad5bd2 | 2015-05-06 10:08:11 -0700 | [diff] [blame] | 64 | |
Dan Albert | 2a4a023 | 2015-05-12 11:00:31 -0700 | [diff] [blame] | 65 | # Note that the structure of this means that LOCAL_CXX_STL := libc++ will |
| 66 | # use the static libc++ for static executables. |
Dan Albert | 0ad5bd2 | 2015-05-06 10:08:11 -0700 | [diff] [blame] | 67 | ifeq ($(my_link_type),dynamic) |
Dan Albert | 2a4a023 | 2015-05-12 11:00:31 -0700 | [diff] [blame] | 68 | ifeq ($(my_cxx_stl),libc++) |
| 69 | my_shared_libraries += libc++ |
| 70 | else |
| 71 | my_static_libraries += libc++_static |
| 72 | endif |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 73 | else |
| 74 | my_static_libraries += libc++_static |
| 75 | endif |
| 76 | |
| 77 | ifdef LOCAL_IS_HOST_MODULE |
| 78 | my_cppflags += -nostdinc++ |
| 79 | my_ldflags += -nodefaultlibs |
Dan Albert | 8bf4cc9 | 2015-03-03 14:10:27 -0800 | [diff] [blame] | 80 | my_ldlibs += -lpthread -lm |
Dan Albert | d666bb1 | 2015-03-03 21:47:04 -0800 | [diff] [blame] | 81 | my_ldlibs += $($(my_prefix)$(HOST_OS)_$(my_link_type)_gcclibs) |
Dan Albert | 5036729 | 2015-03-31 15:18:17 -0700 | [diff] [blame] | 82 | else |
| 83 | ifeq (arm,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) |
| 84 | my_static_libraries += libunwind_llvm |
Dan Albert | 686a557 | 2015-06-23 13:32:30 -0700 | [diff] [blame] | 85 | my_ldflags += -Wl,--exclude-libs,libunwind_llvm.a |
Dan Albert | 5036729 | 2015-03-31 15:18:17 -0700 | [diff] [blame] | 86 | endif |
| 87 | |
| 88 | ifeq ($(my_link_type),static) |
Dan Albert | 0ad5bd2 | 2015-05-06 10:08:11 -0700 | [diff] [blame] | 89 | my_static_libraries += libm libc libdl |
Dan Albert | 5036729 | 2015-03-31 15:18:17 -0700 | [diff] [blame] | 90 | else |
| 91 | my_shared_libraries += libdl |
| 92 | endif |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 93 | endif |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 94 | else ifeq ($(my_cxx_stl),ndk) |
Dan Albert | 3a360a7 | 2015-05-06 10:08:32 -0700 | [diff] [blame] | 95 | # Using an NDK STL. Handled in binary.mk. |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 96 | ifndef LOCAL_IS_HOST_MODULE |
| 97 | my_system_shared_libraries += libstdc++ |
| 98 | endif |
Dan Albert | 93e8cf7 | 2014-10-16 21:18:15 -0700 | [diff] [blame] | 99 | else ifeq ($(my_cxx_stl),libstdc++) |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 100 | # Using bionic's basic libstdc++. Not actually an STL. Only around until the |
| 101 | # tree is in good enough shape to not need it. |
| 102 | ifndef LOCAL_IS_HOST_MODULE |
| 103 | my_c_includes += bionic/libstdc++/include |
| 104 | my_system_shared_libraries += libstdc++ |
| 105 | endif |
| 106 | # Host builds will use GNU libstdc++. |
| 107 | else ifeq ($(my_cxx_stl),none) |
| 108 | ifdef LOCAL_IS_HOST_MODULE |
| 109 | my_cppflags += -nostdinc++ |
Dan Albert | 8bf4cc9 | 2015-03-03 14:10:27 -0800 | [diff] [blame] | 110 | my_ldflags += -nodefaultlibs |
Dan Albert | d666bb1 | 2015-03-03 21:47:04 -0800 | [diff] [blame] | 111 | my_ldlibs += $($(my_prefix)$(HOST_OS)_$(my_link_type)_gcclibs) |
Ying Wang | 75e8fcb | 2014-10-07 13:03:29 -0700 | [diff] [blame] | 112 | endif |
| 113 | else |
Dan Albert | 3a360a7 | 2015-05-06 10:08:32 -0700 | [diff] [blame] | 114 | $(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] | 115 | endif |