From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 762C6158094 for ; Sat, 8 Oct 2022 09:44:10 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2FCCEE0A8C; Sat, 8 Oct 2022 09:43:37 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id EBC1EE0A89 for ; Sat, 8 Oct 2022 09:43:36 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH 2/3] toolchain-funcs.eclass: Add tc-get-c-rtlib() to get CC runtime Date: Sat, 8 Oct 2022 11:43:28 +0200 Message-Id: <20221008094329.316318-3-mgorny@gentoo.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221008094329.316318-1-mgorny@gentoo.org> References: <20221008094329.316318-1-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 983de741-2f00-418c-81ba-5ca2b135cef8 X-Archives-Hash: d45dceef3ccc106f1b874949bf06bf87 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 --- eclass/tests/toolchain-funcs.sh | 10 ++++++++++ eclass/toolchain-funcs.eclass | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) 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 -- 2.38.0