From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 477E81382D5 for ; Sun, 26 Jun 2016 15:36:17 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1068CE0B2B; Sun, 26 Jun 2016 15:36:16 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B1B3AE0B2B for ; Sun, 26 Jun 2016 15:36:14 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B0469340CF1 for ; Sun, 26 Jun 2016 15:36:13 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 96C162433 for ; Sun, 26 Jun 2016 15:36:11 +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: <1466955287.2fea606eba41d9246f510814ce833879368bd835.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/tests/ eclass/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 2fea606eba41d9246f510814ce833879368bd835 X-VCS-Branch: master Date: Sun, 26 Jun 2016 15:36:11 +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-Archives-Salt: 334f09a3-18f5-409a-9f76-b5c669e5af9d X-Archives-Hash: 671a50159985f71776feacc8159b44b5 commit: 2fea606eba41d9246f510814ce833879368bd835 Author: Michał Górny gentoo org> AuthorDate: Wed Jun 22 19:50:21 2016 +0000 Commit: Michał Górny gentoo org> CommitDate: Sun Jun 26 15:34:47 2016 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2fea606e toolchain-funcs.eclass: Add tc-get-compiler-type() Add a tc-get-compiler-type() function that can be used to identify the compiler being used, using the preprocessor defines. Alike gcc-*version() routines, it uses CPP (which in turn uses CC). The major usage would be applying compiler-specific quirks and limiting gcc version checks to compilers that actually are gcc, since e.g. clang reports gcc version 4.2 -- which would incorrectly cause numerous gcc version checks in ebuilds to fail. eclass/tests/toolchain-funcs.sh | 40 ++++++++++++++++++++++++++++++++++++++++ eclass/toolchain-funcs.eclass | 22 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh index 41c1ae5..6f37996 100755 --- a/eclass/tests/toolchain-funcs.sh +++ b/eclass/tests/toolchain-funcs.sh @@ -111,5 +111,45 @@ tc-ld-disable-gold ) tend $? +unset CPP + +tbegin "tc-get-compiler-type (gcc)" +( +export CC=gcc +[[ $(tc-get-compiler-type) == gcc ]] +) +tend $? + +if type -P clang &>/dev/null; then + tbegin "tc-get-compiler-type (clang)" + ( + export CC=clang + [[ $(tc-get-compiler-type) == clang ]] + ) + tend $? +fi + +if type -P pathcc &>/dev/null; then + tbegin "tc-get-compiler-type (pathcc)" + ( + export CC=pathcc + [[ $(tc-get-compiler-type) == pathcc ]] + ) + tend $? + + tbegin "! tc-is-gcc (pathcc)" + ( + export CC=pathcc + ! tc-is-gcc + ) + tend $? + + tbegin "! tc-is-clang (pathcc)" + ( + export CC=pathcc + ! tc-is-clang + ) + tend $? +fi texit diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass index 1baab96..a29784c 100644 --- a/eclass/toolchain-funcs.eclass +++ b/eclass/toolchain-funcs.eclass @@ -585,6 +585,28 @@ tc-endian() { esac } +# @FUNCTION: tc-get-compiler-type +# @RETURN: keyword identifying the compiler: gcc, clang, pathcc, unknown +tc-get-compiler-type() { + local code=' +#if defined(__PATHSCALE__) + HAVE_PATHCC +#elif defined(__clang__) + HAVE_CLANG +#elif defined(__GNUC__) + HAVE_GCC +#endif +' + local res=$($(tc-getCPP "$@") -E -P - <<<"${code}") + + case ${res} in + *HAVE_PATHCC*) echo pathcc;; + *HAVE_CLANG*) echo clang;; + *HAVE_GCC*) echo gcc;; + *) echo unknown;; + esac +} + # Internal func. The first argument is the version info to expand. # Query the preprocessor to improve compatibility across different # compilers rather than maintaining a --version flag matrix. #335943