--- eclass/tests/toolchain-funcs.sh | 28 ++++++++++++++++++++++++++++ eclass/toolchain-funcs.eclass | 14 ++++++++++++++ 2 files changed, 42 insertions(+)
diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh index 0b9b7d7..d86eee4 100755 --- a/eclass/tests/toolchain-funcs.sh +++ b/eclass/tests/toolchain-funcs.sh @@ -118,6 +118,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)" ( @@ -125,6 +139,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 texit diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass index 4a45f78..67eab38 100644 --- a/eclass/toolchain-funcs.eclass +++ b/eclass/toolchain-funcs.eclass @@ -604,6 +604,20 @@ tc-get-compiler-type() { esac } +# @FUNCTION: tc-is-gcc +# @DESCRIPTION: +# Return true if the current compiler is pure GCC. +tc-is-gcc() { + [[ $(tc-get-compiler-type) == gcc ]] +} + +# @FUNCTION: tc-is-clang +# @DESCRIPTION: +# Return true if the current compiler is clang. +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 -- 2.9.0