2014-10-08 04:03:29 +08:00
|
|
|
#############################################################
|
|
|
|
## Set up flags based on LOCAL_CXX_STL.
|
2015-08-15 03:59:50 +08:00
|
|
|
## Input variables: LOCAL_CXX_STL, my_prefix
|
2014-10-08 04:03:29 +08:00
|
|
|
## Output variables: My_cflags, my_c_includes, my_shared_libraries, etc.
|
|
|
|
#############################################################
|
|
|
|
|
|
|
|
# Select the appropriate C++ STL
|
|
|
|
ifeq ($(strip $(LOCAL_CXX_STL)),default)
|
|
|
|
ifndef LOCAL_SDK_VERSION
|
2014-10-17 10:07:41 +08:00
|
|
|
# Platform code. Select the appropriate STL.
|
2015-05-05 07:34:19 +08:00
|
|
|
my_cxx_stl := libc++
|
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
|
|
|
ifneq (,$(BUILD_HOST_static))
|
|
|
|
my_cxx_stl := libc++_static
|
|
|
|
endif
|
2014-10-08 04:03:29 +08:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
my_cxx_stl := ndk
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
my_cxx_stl := $(strip $(LOCAL_CXX_STL))
|
2015-07-28 05:14:56 +08:00
|
|
|
ifdef LOCAL_SDK_VERSION
|
|
|
|
# The NDK has historically used LOCAL_NDK_STL_VARIANT to specify the
|
|
|
|
# STL. An Android.mk that specifies both LOCAL_CXX_STL and
|
|
|
|
# LOCAL_SDK_VERSION will incorrectly try (and most likely fail) to use
|
|
|
|
# the platform STL in an NDK binary. Emit an error to direct the user
|
|
|
|
# toward the correct option.
|
|
|
|
#
|
|
|
|
# Note that we could also accept LOCAL_CXX_STL as an alias for
|
|
|
|
# LOCAL_NDK_STL_VARIANT (and in fact soong does use the same name), but
|
|
|
|
# the two options use different names for the STLs.
|
|
|
|
$(error $(LOCAL_PATH): $(LOCAL_MODULE): Must use LOCAL_NDK_STL_VARIANT rather than LOCAL_CXX_STL for NDK binaries)
|
|
|
|
endif
|
2014-10-08 04:03:29 +08:00
|
|
|
endif
|
|
|
|
|
2015-03-04 10:30:27 +08:00
|
|
|
my_link_type := dynamic
|
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
|
|
|
ifneq (,$(BUILD_HOST_static))
|
|
|
|
my_link_type := static
|
|
|
|
endif
|
|
|
|
ifeq (-static,$(filter -static,$(my_ldflags)))
|
|
|
|
my_link_type := static
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
ifeq (true,$(LOCAL_FORCE_STATIC_EXECUTABLE))
|
|
|
|
my_link_type := static
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2016-09-14 01:44:44 +08:00
|
|
|
my_cxx_ldlibs :=
|
2014-10-08 04:03:29 +08:00
|
|
|
ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),)
|
2018-01-12 05:24:32 +08:00
|
|
|
ifeq ($($(my_prefix)OS),darwin)
|
|
|
|
# libc++'s headers are annotated with availability macros that indicate
|
|
|
|
# which version of Mac OS was the first to ship with a libc++ feature
|
|
|
|
# available in its *system's* libc++.dylib. We do not use the system's
|
|
|
|
# library, but rather ship our own. As such, these availability
|
|
|
|
# attributes are meaningless for us but cause build breaks when we try
|
|
|
|
# to use code that would not be available in the system's dylib.
|
|
|
|
my_cppflags += -D_LIBCPP_DISABLE_AVAILABILITY
|
|
|
|
endif
|
|
|
|
|
2015-05-13 02:00:31 +08:00
|
|
|
# Note that the structure of this means that LOCAL_CXX_STL := libc++ will
|
|
|
|
# use the static libc++ for static executables.
|
2015-05-07 01:08:11 +08:00
|
|
|
ifeq ($(my_link_type),dynamic)
|
2015-05-13 02:00:31 +08:00
|
|
|
ifeq ($(my_cxx_stl),libc++)
|
|
|
|
my_shared_libraries += libc++
|
|
|
|
else
|
|
|
|
my_static_libraries += libc++_static
|
|
|
|
endif
|
2014-10-08 04:03:29 +08:00
|
|
|
else
|
|
|
|
my_static_libraries += libc++_static
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
|
|
|
my_cppflags += -nostdinc++
|
2019-10-04 07:04:52 +08:00
|
|
|
my_ldflags += -nostdlib++
|
2015-04-01 06:18:17 +08:00
|
|
|
else
|
2019-08-14 04:15:04 +08:00
|
|
|
my_static_libraries += libc++demangle
|
2015-04-01 06:18:17 +08:00
|
|
|
ifeq (arm,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
|
|
|
|
my_static_libraries += libunwind_llvm
|
2015-06-24 04:32:30 +08:00
|
|
|
my_ldflags += -Wl,--exclude-libs,libunwind_llvm.a
|
2015-04-01 06:18:17 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(my_link_type),static)
|
Stop linking libdl.a into static bins
libdl.a has a no-op dlopen, which breaks static libraries that need a real
dlopen. Instead of automatically linking libdl.a into static executables,
make it optional.
Until recently, the libunwind_llvm.a unwinder, used on arm32, needed the
no-op dladdr, but it's now built using -D_LIBUNWIND_USE_DLADDR=0.
The HWASan run-time uses dlsym and dladdr, so add a libdl dependency for
HWASan-built static binaries. We could also remove the dependency from
libclang_rt.hwasan_static-*.a, but this is also easy to do.
Bug: http://b/141485154
Test: bionic unit tests, device boots, verify that static and dynamic
executables can throw/catch an exception
Test: verify that a static executable using dlopen doesn't link (unless it
adds an explicit dependency on libdl)
Change-Id: Id26741f79dca50256a2dc23453af3026a6c88dca
2019-10-22 11:47:53 +08:00
|
|
|
my_static_libraries += libm libc
|
2015-04-01 06:18:17 +08:00
|
|
|
endif
|
2014-10-08 04:03:29 +08:00
|
|
|
endif
|
|
|
|
else ifeq ($(my_cxx_stl),ndk)
|
2015-05-07 01:08:32 +08:00
|
|
|
# Using an NDK STL. Handled in binary.mk.
|
2014-10-17 12:18:15 +08:00
|
|
|
else ifeq ($(my_cxx_stl),libstdc++)
|
2018-08-09 01:29:00 +08:00
|
|
|
$(error $(LOCAL_PATH): $(LOCAL_MODULE): libstdc++ is not supported)
|
2014-10-08 04:03:29 +08:00
|
|
|
else ifeq ($(my_cxx_stl),none)
|
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
|
|
|
my_cppflags += -nostdinc++
|
2019-10-04 07:04:52 +08:00
|
|
|
my_ldflags += -nostdlib++
|
2014-10-08 04:03:29 +08:00
|
|
|
endif
|
|
|
|
else
|
2015-05-07 01:08:32 +08:00
|
|
|
$(error $(LOCAL_PATH): $(LOCAL_MODULE): $(my_cxx_stl) is not a supported STL.)
|
2014-10-08 04:03:29 +08:00
|
|
|
endif
|