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 448BE158094 for ; Mon, 10 Oct 2022 20:52:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 86C5CE0864; Mon, 10 Oct 2022 20:52:46 +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) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 698EEE0864 for ; Mon, 10 Oct 2022 20:52:46 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6218934102F for ; Mon, 10 Oct 2022 20:52:45 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A5C055EC for ; Mon, 10 Oct 2022 20:52:43 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <1665435155.96ddadb40ddba1bfdba68ff8f2fd889cfd004f03.mgorny@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/tests/, eclass/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/tests/toolchain-funcs.sh eclass/toolchain-funcs.eclass X-VCS-Directories: eclass/ eclass/tests/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 96ddadb40ddba1bfdba68ff8f2fd889cfd004f03 X-VCS-Branch: master Date: Mon, 10 Oct 2022 20:52:43 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 72fd9a19-8b0b-444d-bf95-d064ce3720ff X-Archives-Hash: 51fef3bb2075d620ef5239d52fe71604 commit: 96ddadb40ddba1bfdba68ff8f2fd889cfd004f03 Author: Michał Górny gentoo org> AuthorDate: Fri Oct 7 15:22:01 2022 +0000 Commit: Michał Górny gentoo org> CommitDate: Mon Oct 10 20:52:35 2022 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=96ddadb4 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 gentoo.org> 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