summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2022-10-07 17:22:01 +0200
committerMichał Górny <mgorny@gentoo.org>2022-10-10 22:52:35 +0200
commit96ddadb40ddba1bfdba68ff8f2fd889cfd004f03 (patch)
tree38c8a573ea589e7ca9cf94a53c316b0459dcc12b
parenttoolchain-funcs.eclass: Add tc-get-cxx-stdlib() to get C++ stdlib (diff)
downloadgentoo-96ddadb40ddba1bfdba68ff8f2fd889cfd004f03.tar.gz
gentoo-96ddadb40ddba1bfdba68ff8f2fd889cfd004f03.tar.bz2
gentoo-96ddadb40ddba1bfdba68ff8f2fd889cfd004f03.zip
toolchain-funcs.eclass: Add tc-get-c-rtlib() to get CC runtime
Add a new tc-get-c-rtlib() that attempts to get the runtime used by the current C compiler. Currently it supports compiler-rt and libgcc. Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rwxr-xr-xeclass/tests/toolchain-funcs.sh10
-rw-r--r--eclass/toolchain-funcs.eclass28
2 files changed, 38 insertions, 0 deletions
diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
index 5a35a44ce018..d8a357fb24fe 100755
--- a/eclass/tests/toolchain-funcs.sh
+++ b/eclass/tests/toolchain-funcs.sh
@@ -202,6 +202,10 @@ if type -P gcc &>/dev/null; then
tbegin "tc-get-cxx-stdlib (gcc)"
[[ $(CXX=g++ tc-get-cxx-stdlib) == libstdc++ ]]
tend $?
+
+ tbegin "tc-get-c-rtlib (gcc)"
+ [[ $(CC=gcc tc-get-c-rtlib) == libgcc ]]
+ tend $?
fi
if type -P clang &>/dev/null; then
@@ -218,6 +222,12 @@ if type -P clang &>/dev/null; then
tbegin "tc-get-cxx-stdlib (clang, invalid)"
! CXX=clang++ CXXFLAGS="-stdlib=invalid" tc-get-cxx-stdlib
tend $?
+
+ for rtlib in compiler-rt libgcc; do
+ tbegin "tc-get-c-rtlib (clang, ${rtlib})"
+ [[ $(CC=clang CFLAGS="--rtlib=${rtlib}" tc-get-c-rtlib) == ${rtlib} ]]
+ tend $?
+ done
fi
texit
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 92494158201e..32e446cb2368 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -1209,4 +1209,32 @@ tc-get-cxx-stdlib() {
return 0
}
+# @FUNCTION: tc-get-c-rtlib
+# @DESCRIPTION:
+# Attempt to identify the runtime used by the C/C++ compiler.
+# If the runtime is identifed, the function returns 0 and prints one
+# of the following:
+#
+# - ``compiler-rt`` for ``sys-libs/compiler-rt``
+# - ``libgcc`` for ``sys-devel/gcc``'s libgcc
+#
+# If the runtime is not recognized, the function returns 1.
+tc-get-c-rtlib() {
+ local res=$(
+ $(tc-getCC) ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} \
+ -print-libgcc-file-name 2>/dev/null
+ )
+
+ case ${res} in
+ *libclang_rt*)
+ echo compiler-rt;;
+ *libgcc*)
+ echo libgcc;;
+ *)
+ return 1;;
+ esac
+
+ return 0
+}
+
fi