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