* [gentoo-dev] [PATCH 1/2] toolchain-funcs.eclass: Add tc-get-compiler-type()
@ 2016-06-23 9:18 99% ` Michał Górny
0 siblings, 0 replies; 1+ results
From: Michał Górny @ 2016-06-23 9:18 UTC (permalink / raw
To: gentoo-dev; +Cc: toolchain, Michał Górny
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/tests/toolchain-funcs.sh | 15 +++++++++++++++
eclass/toolchain-funcs.eclass | 19 +++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
index 41c1ae5..0b9b7d7 100755
--- a/eclass/tests/toolchain-funcs.sh
+++ b/eclass/tests/toolchain-funcs.sh
@@ -111,5 +111,20 @@ tc-ld-disable-gold
)
tend $?
+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
texit
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 3398775..4a45f78 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -585,6 +585,25 @@ tc-endian() {
esac
}
+# @FUNCTION: tc-get-compiler-type
+# @RETURN: keyword identifying the compiler: gcc, clang, unknown
+tc-get-compiler-type() {
+ local code='
+#if defined(__clang__)
+ HAVE_CLANG
+#elif defined(__GNUC__)
+ HAVE_GCC
+#endif
+'
+ local res=$($(tc-getCPP "$@") -E -P - <<<"${code}")
+
+ case ${res} in
+ *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
--
2.9.0
^ permalink raw reply related [relevance 99%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-06-22 20:06 [gentoo-dev] [PATCH 0/4] toolchain-funcs.eclass: fix for version checks (v2) + compiler identification Michał Górny
2016-06-23 9:18 ` [gentoo-dev] [PATCH 0/2] v3: tc-get-compiler-type() & wrappers Michał Górny
2016-06-23 9:18 99% ` [gentoo-dev] [PATCH 1/2] toolchain-funcs.eclass: Add tc-get-compiler-type() Michał Górny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox