blob: c59cd34ad8465ea81c9de151de8ea4d32ec1252d [file] [log] [blame]
Ying Wang75e8fcb2014-10-07 13:03:29 -07001#############################################################
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 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
17 ifdef USE_MINGW
18 # 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))
27endif
28
Dan Albert4f2afde2015-03-03 17:42:28 -080029# Yes, this is actually what the clang driver does.
Dan Albertd666bb12015-03-03 21:47:04 -080030HOST_linux_dynamic_gcclibs := -lgcc_s -lgcc -lc -lgcc_s -lgcc
31HOST_linux_static_gcclibs := -Wl,--start-group -lgcc -lgcc_eh -lc -Wl,--end-group
32HOST_darwin_dynamic_gcclibs := -lc -lSystem
33HOST_darwin_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_DARWIN
Dan Albert4f2afde2015-03-03 17:42:28 -080034
Dan Albertb5eb9052015-03-03 18:30:27 -080035my_link_type := dynamic
36ifdef 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
43else
44 ifeq (true,$(LOCAL_FORCE_STATIC_EXECUTABLE))
45 my_link_type := static
46 endif
47endif
48
Ying Wang75e8fcb2014-10-07 13:03:29 -070049ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),)
50 my_cflags += -D_USING_LIBCXX
51 my_c_includes += external/libcxx/include
Dan Albert0ad5bd22015-05-06 10:08:11 -070052
Dan Albert2a4a0232015-05-12 11:00:31 -070053 # Note that the structure of this means that LOCAL_CXX_STL := libc++ will
54 # use the static libc++ for static executables.
Dan Albert0ad5bd22015-05-06 10:08:11 -070055 ifeq ($(my_link_type),dynamic)
Dan Albert2a4a0232015-05-12 11:00:31 -070056 ifeq ($(my_cxx_stl),libc++)
57 my_shared_libraries += libc++
58 else
59 my_static_libraries += libc++_static
60 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -070061 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 Albert8bf4cc92015-03-03 14:10:27 -080068 my_ldlibs += -lpthread -lm
Dan Albertd666bb12015-03-03 21:47:04 -080069 my_ldlibs += $($(my_prefix)$(HOST_OS)_$(my_link_type)_gcclibs)
Dan Albert50367292015-03-31 15:18:17 -070070 else
71 ifeq (arm,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
72 my_static_libraries += libunwind_llvm
Dan Albert50367292015-03-31 15:18:17 -070073 endif
74
75 ifeq ($(my_link_type),static)
Dan Albert0ad5bd22015-05-06 10:08:11 -070076 my_static_libraries += libm libc libdl
Dan Albert50367292015-03-31 15:18:17 -070077 else
78 my_shared_libraries += libdl
79 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -070080 endif
Ying Wang75e8fcb2014-10-07 13:03:29 -070081else ifeq ($(my_cxx_stl),ndk)
Dan Albert3a360a72015-05-06 10:08:32 -070082 # Using an NDK STL. Handled in binary.mk.
Ying Wang75e8fcb2014-10-07 13:03:29 -070083 ifndef LOCAL_IS_HOST_MODULE
84 my_system_shared_libraries += libstdc++
85 endif
Dan Albert93e8cf72014-10-16 21:18:15 -070086else ifeq ($(my_cxx_stl),libstdc++)
Ying Wang75e8fcb2014-10-07 13:03:29 -070087 # Using bionic's basic libstdc++. Not actually an STL. Only around until the
88 # tree is in good enough shape to not need it.
89 ifndef LOCAL_IS_HOST_MODULE
90 my_c_includes += bionic/libstdc++/include
91 my_system_shared_libraries += libstdc++
92 endif
93 # Host builds will use GNU libstdc++.
94else ifeq ($(my_cxx_stl),none)
95 ifdef LOCAL_IS_HOST_MODULE
96 my_cppflags += -nostdinc++
Dan Albert8bf4cc92015-03-03 14:10:27 -080097 my_ldflags += -nodefaultlibs
Dan Albertd666bb12015-03-03 21:47:04 -080098 my_ldlibs += $($(my_prefix)$(HOST_OS)_$(my_link_type)_gcclibs)
Ying Wang75e8fcb2014-10-07 13:03:29 -070099 endif
100else
Dan Albert3a360a72015-05-06 10:08:32 -0700101 $(error $(LOCAL_PATH): $(LOCAL_MODULE): $(my_cxx_stl) is not a supported STL.)
Ying Wang75e8fcb2014-10-07 13:03:29 -0700102endif