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>
This commit is contained in:
Michał Górny
2022-10-10 22:52:35 +02:00
parent 2170307e8e
commit 96ddadb40d
2 changed files with 38 additions and 0 deletions
+10
View File
@@ -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
+28
View File
@@ -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