From 2fea606eba41d9246f510814ce833879368bd835 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Wed, 22 Jun 2016 21:50:21 +0200 Subject: 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/toolchain-funcs.eclass | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'eclass/toolchain-funcs.eclass') 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 -- cgit v1.2.3-65-gdbad