blob: 0baec26e17eb02640cf390a6e8e071cb3a9fbbc1 [file] [log] [blame]
Ying Wang75e8fcb2014-10-07 13:03:29 -07001#############################################################
2## Set up flags based on LOCAL_CXX_STL.
Dan Willemsen057aaea2015-08-14 12:59:50 -07003## Input variables: LOCAL_CXX_STL, my_prefix
Ying Wang75e8fcb2014-10-07 13:03:29 -07004## Output variables: My_cflags, my_c_includes, my_shared_libraries, etc.
5#############################################################
6
Ying Wang75e8fcb2014-10-07 13:03:29 -07007# Select the appropriate C++ STL
8ifeq ($(strip $(LOCAL_CXX_STL)),default)
9 ifndef LOCAL_SDK_VERSION
Dan Albert93766b22014-10-16 19:07:41 -070010 # Platform code. Select the appropriate STL.
Dan Albert88a8ce62015-05-04 16:34:19 -070011 my_cxx_stl := libc++
12 ifdef LOCAL_IS_HOST_MODULE
13 ifneq (,$(BUILD_HOST_static))
14 my_cxx_stl := libc++_static
Dan Albert8bf4cc92015-03-03 14:10:27 -080015 endif
Dan Albert88a8ce62015-05-04 16:34:19 -070016
Dan Willemsen1ca3b702015-08-13 17:41:56 -070017 ifeq ($($(my_prefix)OS),windows)
Dan Albert88a8ce62015-05-04 16:34:19 -070018 # libc++ is not supported on mingw.
19 my_cxx_stl := libstdc++
20 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -070021 endif
22 else
23 my_cxx_stl := ndk
24 endif
25else
26 my_cxx_stl := $(strip $(LOCAL_CXX_STL))
Dan Albertef3e7cf2015-07-27 14:14:56 -070027 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
Dan Willemsen1ca3b702015-08-13 17:41:56 -070039 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
Ying Wang75e8fcb2014-10-07 13:03:29 -070047endif
48
Dan Albert4f2afde2015-03-03 17:42:28 -080049# Yes, this is actually what the clang driver does.
Dan Albertd1d68b12015-09-11 10:57:14 -070050linux_dynamic_gcclibs := -lgcc_s -lgcc -lc -lgcc_s -lgcc
51linux_static_gcclibs := -Wl,--start-group -lgcc -lgcc_eh -lc -Wl,--end-group
52darwin_dynamic_gcclibs := -lc -lSystem
53darwin_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_DARWIN
54windows_dynamic_gcclibs := \
55 -lmsvcr110 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 \
56 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt
57windows_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_WINDOWS
Dan Albert4f2afde2015-03-03 17:42:28 -080058
Dan Albertb5eb9052015-03-03 18:30:27 -080059my_link_type := dynamic
60ifdef 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
67else
68 ifeq (true,$(LOCAL_FORCE_STATIC_EXECUTABLE))
69 my_link_type := static
70 endif
71endif
72
Dan Willemsenc9aa6fc2016-09-13 10:44:44 -070073my_cxx_ldlibs :=
Ying Wang75e8fcb2014-10-07 13:03:29 -070074ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),)
75 my_cflags += -D_USING_LIBCXX
Dan Albert0ad5bd22015-05-06 10:08:11 -070076
Dan Albert2a4a0232015-05-12 11:00:31 -070077 # Note that the structure of this means that LOCAL_CXX_STL := libc++ will
78 # use the static libc++ for static executables.
Dan Albert0ad5bd22015-05-06 10:08:11 -070079 ifeq ($(my_link_type),dynamic)
Dan Albert2a4a0232015-05-12 11:00:31 -070080 ifeq ($(my_cxx_stl),libc++)
81 my_shared_libraries += libc++
82 else
83 my_static_libraries += libc++_static
84 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -070085 else
86 my_static_libraries += libc++_static
87 endif
88
89 ifdef LOCAL_IS_HOST_MODULE
90 my_cppflags += -nostdinc++
91 my_ldflags += -nodefaultlibs
Dan Albert8bf4cc92015-03-03 14:10:27 -080092 my_ldlibs += -lpthread -lm
Dan Willemsenc9aa6fc2016-09-13 10:44:44 -070093 my_cxx_ldlibs += $($($(my_prefix)OS)_$(my_link_type)_gcclibs)
Dan Albert50367292015-03-31 15:18:17 -070094 else
95 ifeq (arm,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
96 my_static_libraries += libunwind_llvm
Dan Albert686a5572015-06-23 13:32:30 -070097 my_ldflags += -Wl,--exclude-libs,libunwind_llvm.a
Dan Albert50367292015-03-31 15:18:17 -070098 endif
99
100 ifeq ($(my_link_type),static)
Dan Albert0ad5bd22015-05-06 10:08:11 -0700101 my_static_libraries += libm libc libdl
Dan Albert50367292015-03-31 15:18:17 -0700102 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -0700103 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -0700104else ifeq ($(my_cxx_stl),ndk)
Dan Albert3a360a72015-05-06 10:08:32 -0700105 # Using an NDK STL. Handled in binary.mk.
Dan Albert93e8cf72014-10-16 21:18:15 -0700106else ifeq ($(my_cxx_stl),libstdc++)
Ying Wang75e8fcb2014-10-07 13:03:29 -0700107 ifndef LOCAL_IS_HOST_MODULE
Colin Cross50a81202016-03-17 12:56:25 -0700108 $(error $(LOCAL_PATH): $(LOCAL_MODULE): libstdc++ is not supported for device modules)
Dan Willemsen327fa9c2016-06-15 13:41:45 -0700109 else ifneq ($($(my_prefix)OS),windows)
110 $(error $(LOCAL_PATH): $(LOCAL_MODULE): libstdc++ is not supported on $($(my_prefix)OS))
Ying Wang75e8fcb2014-10-07 13:03:29 -0700111 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -0700112else ifeq ($(my_cxx_stl),none)
113 ifdef LOCAL_IS_HOST_MODULE
114 my_cppflags += -nostdinc++
Dan Albert8bf4cc92015-03-03 14:10:27 -0800115 my_ldflags += -nodefaultlibs
Dan Willemsenc9aa6fc2016-09-13 10:44:44 -0700116 my_cxx_ldlibs += $($($(my_prefix)OS)_$(my_link_type)_gcclibs)
Ying Wang75e8fcb2014-10-07 13:03:29 -0700117 endif
118else
Dan Albert3a360a72015-05-06 10:08:32 -0700119 $(error $(LOCAL_PATH): $(LOCAL_MODULE): $(my_cxx_stl) is not a supported STL.)
Ying Wang75e8fcb2014-10-07 13:03:29 -0700120endif