cxx_stl_setup.mk revision 057aaea54a8dd6aa769290b1c0f471a17aaf1a22
1#############################################################
2## Set up flags based on LOCAL_CXX_STL.
3## Input variables: LOCAL_CXX_STL, my_prefix
4## Output variables: My_cflags, my_c_includes, my_shared_libraries, etc.
5#############################################################
6
7# Select the appropriate C++ STL
8ifeq ($(strip $(LOCAL_CXX_STL)),default)
9    ifndef LOCAL_SDK_VERSION
10        # Platform code. Select the appropriate STL.
11        my_cxx_stl := libc++
12        ifdef LOCAL_IS_HOST_MODULE
13            ifneq (,$(BUILD_HOST_static))
14                my_cxx_stl := libc++_static
15            endif
16
17            ifeq ($($(my_prefix)OS),windows)
18                # libc++ is not supported on mingw.
19                my_cxx_stl := libstdc++
20            endif
21        endif
22    else
23        my_cxx_stl := ndk
24    endif
25else
26    my_cxx_stl := $(strip $(LOCAL_CXX_STL))
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
39    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
47endif
48
49# Yes, this is actually what the clang driver does.
50HOST_linux_dynamic_gcclibs := -lgcc_s -lgcc -lc -lgcc_s -lgcc
51HOST_linux_static_gcclibs := -Wl,--start-group -lgcc -lgcc_eh -lc -Wl,--end-group
52HOST_darwin_dynamic_gcclibs := -lc -lSystem
53HOST_darwin_static_gcclibs := NO_STATIC_HOST_BINARIES_ON_DARWIN
54
55my_link_type := dynamic
56ifdef LOCAL_IS_HOST_MODULE
57    ifneq (,$(BUILD_HOST_static))
58        my_link_type := static
59    endif
60    ifeq (-static,$(filter -static,$(my_ldflags)))
61        my_link_type := static
62    endif
63else
64    ifeq (true,$(LOCAL_FORCE_STATIC_EXECUTABLE))
65        my_link_type := static
66    endif
67endif
68
69ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),)
70    my_cflags += -D_USING_LIBCXX
71    my_c_includes += external/libcxx/include
72
73    # Note that the structure of this means that LOCAL_CXX_STL := libc++ will
74    # use the static libc++ for static executables.
75    ifeq ($(my_link_type),dynamic)
76        ifeq ($(my_cxx_stl),libc++)
77            my_shared_libraries += libc++
78        else
79            my_static_libraries += libc++_static
80        endif
81    else
82        my_static_libraries += libc++_static
83    endif
84
85    ifdef LOCAL_IS_HOST_MODULE
86        my_cppflags += -nostdinc++
87        my_ldflags += -nodefaultlibs
88        my_ldlibs += -lpthread -lm
89        my_ldlibs += $($(my_prefix)$(HOST_OS)_$(my_link_type)_gcclibs)
90    else
91        ifeq (arm,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
92            my_static_libraries += libunwind_llvm
93            my_ldflags += -Wl,--exclude-libs,libunwind_llvm.a
94        endif
95
96        ifeq ($(my_link_type),static)
97            my_static_libraries += libm libc libdl
98        else
99            my_shared_libraries += libdl
100        endif
101    endif
102else ifeq ($(my_cxx_stl),ndk)
103    # Using an NDK STL. Handled in binary.mk.
104    ifndef LOCAL_IS_HOST_MODULE
105        my_system_shared_libraries += libstdc++
106    endif
107else ifeq ($(my_cxx_stl),libstdc++)
108    # Using bionic's basic libstdc++. Not actually an STL. Only around until the
109    # tree is in good enough shape to not need it.
110    ifndef LOCAL_IS_HOST_MODULE
111        my_c_includes += bionic/libstdc++/include
112        my_system_shared_libraries += libstdc++
113    endif
114    # Host builds will use GNU libstdc++.
115else ifeq ($(my_cxx_stl),none)
116    ifdef LOCAL_IS_HOST_MODULE
117        my_cppflags += -nostdinc++
118        my_ldflags += -nodefaultlibs
119        my_ldlibs += $($(my_prefix)$(HOST_OS)_$(my_link_type)_gcclibs)
120    endif
121else
122    $(error $(LOCAL_PATH): $(LOCAL_MODULE): $(my_cxx_stl) is not a supported STL.)
123endif
124