toolchain-funcs.eclass: Add helpful tc-is-{gcc,clang} wrappers
authorMichał Górny <mgorny@gentoo.org>
Wed, 22 Jun 2016 19:54:44 +0000 (21:54 +0200)
committerMichał Górny <mgorny@gentoo.org>
Sun, 26 Jun 2016 15:34:47 +0000 (17:34 +0200)
eclass/tests/toolchain-funcs.sh
eclass/toolchain-funcs.eclass

index 6f3799679a0057b4c63bd2a782b7b01ad81adcb3..e6a15389c91338963ff0e353b147fa4d348508dd 100755 (executable)
@@ -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
index a29784cd14a4072151c68bfc44f4e4909362fac1..d3abfb5289368c29b0593a0276a1f9812b6247dc 100644 (file)
@@ -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