commit: 6984a5b149a215dd96a9759d3d1f251354faf38f
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 22 19:54:44 2016 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Jun 26 15:34:47 2016 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6984a5b1
toolchain-funcs.eclass: Add helpful tc-is-{gcc,clang} wrappers
eclass/tests/toolchain-funcs.sh | 28 ++++++++++++++++++++++++++++
eclass/toolchain-funcs.eclass | 12 ++++++++++++
2 files changed, 40 insertions(+)
diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
index 6f37996..e6a1538 100755
--- a/eclass/tests/toolchain-funcs.sh
+++ b/eclass/tests/toolchain-funcs.sh
@@ -120,6 +120,20 @@ export CC=gcc
)
tend $?
+tbegin "tc-is-gcc (gcc)"
+(
+export CC=gcc
+tc-is-gcc
+)
+tend $?
+
+tbegin "! tc-is-clang (gcc)"
+(
+export CC=gcc
+! tc-is-clang
+)
+tend $?
+
if type -P clang &>/dev/null; then
tbegin "tc-get-compiler-type (clang)"
(
@@ -127,6 +141,20 @@ if type -P clang &>/dev/null; then
[[ $(tc-get-compiler-type) == clang ]]
)
tend $?
+
+ tbegin "! tc-is-gcc (clang)"
+ (
+ export CC=clang
+ ! tc-is-gcc
+ )
+ tend $?
+
+ tbegin "tc-is-clang (clang)"
+ (
+ export CC=clang
+ tc-is-clang
+ )
+ tend $?
fi
if type -P pathcc &>/dev/null; then
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index a29784c..d3abfb5 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -607,6 +607,18 @@ tc-get-compiler-type() {
esac
}
+# @FUNCTION: tc-is-gcc
+# @RETURN: Shell true if the current compiler is GCC, false otherwise.
+tc-is-gcc() {
+ [[ $(tc-get-compiler-type) == gcc ]]
+}
+
+# @FUNCTION: tc-is-clang
+# @RETURN: Shell true if the current compiler is clang, false otherwise.
+tc-is-clang() {
+ [[ $(tc-get-compiler-type) == clang ]]
+}
+
# 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