blob: 8e4a46c436cce4ae94907a74e1d6a743d55dc467 [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
Ying Wang75e8fcb2014-10-07 13:03:29 -070016 endif
17 else
18 my_cxx_stl := ndk
19 endif
20else
21 my_cxx_stl := $(strip $(LOCAL_CXX_STL))
Dan Albertef3e7cf2015-07-27 14:14:56 -070022 ifdef LOCAL_SDK_VERSION
23 # The NDK has historically used LOCAL_NDK_STL_VARIANT to specify the
24 # STL. An Android.mk that specifies both LOCAL_CXX_STL and
25 # LOCAL_SDK_VERSION will incorrectly try (and most likely fail) to use
26 # the platform STL in an NDK binary. Emit an error to direct the user
27 # toward the correct option.
28 #
29 # Note that we could also accept LOCAL_CXX_STL as an alias for
30 # LOCAL_NDK_STL_VARIANT (and in fact soong does use the same name), but
31 # the two options use different names for the STLs.
32 $(error $(LOCAL_PATH): $(LOCAL_MODULE): Must use LOCAL_NDK_STL_VARIANT rather than LOCAL_CXX_STL for NDK binaries)
33 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -070034endif
35
Dan Albert4f2afde2015-03-03 17:42:28 -080036# Yes, this is actually what the clang driver does.
Dan Albertd1d68b12015-09-11 10:57:14 -070037linux_dynamic_gcclibs := -lgcc_s -lgcc -lc -lgcc_s -lgcc
38linux_static_gcclibs := -Wl,--start-group -lgcc -lgcc_eh -lc -Wl,--end-group
39darwin_dynamic_gcclibs := -lc -lSystem
40darwin_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_DARWIN
Dan Albert4f2afde2015-03-03 17:42:28 -080041
Dan Albertb5eb9052015-03-03 18:30:27 -080042my_link_type := dynamic
43ifdef LOCAL_IS_HOST_MODULE
44 ifneq (,$(BUILD_HOST_static))
45 my_link_type := static
46 endif
47 ifeq (-static,$(filter -static,$(my_ldflags)))
48 my_link_type := static
49 endif
50else
51 ifeq (true,$(LOCAL_FORCE_STATIC_EXECUTABLE))
52 my_link_type := static
53 endif
54endif
55
Dan Willemsenc9aa6fc2016-09-13 10:44:44 -070056my_cxx_ldlibs :=
Ying Wang75e8fcb2014-10-07 13:03:29 -070057ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),)
Dan Albert9262b6f2018-01-11 13:24:32 -080058 ifeq ($($(my_prefix)OS),darwin)
59 # libc++'s headers are annotated with availability macros that indicate
60 # which version of Mac OS was the first to ship with a libc++ feature
61 # available in its *system's* libc++.dylib. We do not use the system's
62 # library, but rather ship our own. As such, these availability
63 # attributes are meaningless for us but cause build breaks when we try
64 # to use code that would not be available in the system's dylib.
65 my_cppflags += -D_LIBCPP_DISABLE_AVAILABILITY
66 endif
67
Dan Albert2a4a0232015-05-12 11:00:31 -070068 # Note that the structure of this means that LOCAL_CXX_STL := libc++ will
69 # use the static libc++ for static executables.
Dan Albert0ad5bd22015-05-06 10:08:11 -070070 ifeq ($(my_link_type),dynamic)
Dan Albert2a4a0232015-05-12 11:00:31 -070071 ifeq ($(my_cxx_stl),libc++)
72 my_shared_libraries += libc++
73 else
74 my_static_libraries += libc++_static
75 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -070076 else
77 my_static_libraries += libc++_static
78 endif
79
80 ifdef LOCAL_IS_HOST_MODULE
81 my_cppflags += -nostdinc++
82 my_ldflags += -nodefaultlibs
Dan Willemsenc9aa6fc2016-09-13 10:44:44 -070083 my_cxx_ldlibs += $($($(my_prefix)OS)_$(my_link_type)_gcclibs)
Dan Albert50367292015-03-31 15:18:17 -070084 else
Dan Albertd892b632019-08-13 13:15:04 -070085 my_static_libraries += libc++demangle
Dan Albert50367292015-03-31 15:18:17 -070086 ifeq (arm,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
87 my_static_libraries += libunwind_llvm
Dan Albert686a5572015-06-23 13:32:30 -070088 my_ldflags += -Wl,--exclude-libs,libunwind_llvm.a
Dan Albert50367292015-03-31 15:18:17 -070089 endif
90
91 ifeq ($(my_link_type),static)
Dan Albert0ad5bd22015-05-06 10:08:11 -070092 my_static_libraries += libm libc libdl
Dan Albert50367292015-03-31 15:18:17 -070093 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -070094 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -070095else ifeq ($(my_cxx_stl),ndk)
Dan Albert3a360a72015-05-06 10:08:32 -070096 # Using an NDK STL. Handled in binary.mk.
Dan Albert93e8cf72014-10-16 21:18:15 -070097else ifeq ($(my_cxx_stl),libstdc++)
Pirama Arumuga Nainar80ba3452018-08-08 10:29:00 -070098 $(error $(LOCAL_PATH): $(LOCAL_MODULE): libstdc++ is not supported)
Ying Wang75e8fcb2014-10-07 13:03:29 -070099else ifeq ($(my_cxx_stl),none)
100 ifdef LOCAL_IS_HOST_MODULE
101 my_cppflags += -nostdinc++
Dan Albert8bf4cc92015-03-03 14:10:27 -0800102 my_ldflags += -nodefaultlibs
Dan Willemsenc9aa6fc2016-09-13 10:44:44 -0700103 my_cxx_ldlibs += $($($(my_prefix)OS)_$(my_link_type)_gcclibs)
Ying Wang75e8fcb2014-10-07 13:03:29 -0700104 endif
105else
Dan Albert3a360a72015-05-06 10:08:32 -0700106 $(error $(LOCAL_PATH): $(LOCAL_MODULE): $(my_cxx_stl) is not a supported STL.)
Ying Wang75e8fcb2014-10-07 13:03:29 -0700107endif