diff options
author | Michał Górny <mgorny@gentoo.org> | 2016-06-22 21:50:21 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2016-06-26 17:34:47 +0200 |
commit | 2fea606eba41d9246f510814ce833879368bd835 (patch) | |
tree | 98345156df535f81b749e0f5b9162f7e6f0e494f /eclass | |
parent | toolchain-funcs.eclass: Assume CPP="$(tc-getCC) -E" when unset, #582822 (diff) | |
download | gentoo-2fea606eba41d9246f510814ce833879368bd835.tar.gz gentoo-2fea606eba41d9246f510814ce833879368bd835.tar.bz2 gentoo-2fea606eba41d9246f510814ce833879368bd835.zip |
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.
Diffstat (limited to 'eclass')
-rwxr-xr-x | eclass/tests/toolchain-funcs.sh | 40 | ||||
-rw-r--r-- | eclass/toolchain-funcs.eclass | 22 |
2 files changed, 62 insertions, 0 deletions
diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh index 41c1ae59306b..6f3799679a00 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 1baab96aeb70..a29784cd14a4 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 |