1 |
Add a tc-get-compiler-type() function that can be used to identify |
2 |
the compiler being used, using the preprocessor defines. Alike |
3 |
gcc-*version() routines, it uses CPP (which in turn uses CC). |
4 |
|
5 |
The major usage would be applying compiler-specific quirks and limiting |
6 |
gcc version checks to compilers that actually are gcc, since e.g. clang |
7 |
reports gcc version 4.2 -- which would incorrectly cause numerous gcc |
8 |
version checks in ebuilds to fail. |
9 |
--- |
10 |
eclass/tests/toolchain-funcs.sh | 40 ++++++++++++++++++++++++++++++++++++++++ |
11 |
eclass/toolchain-funcs.eclass | 22 ++++++++++++++++++++++ |
12 |
2 files changed, 62 insertions(+) |
13 |
|
14 |
diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh |
15 |
index 41c1ae5..6f37996 100755 |
16 |
--- a/eclass/tests/toolchain-funcs.sh |
17 |
+++ b/eclass/tests/toolchain-funcs.sh |
18 |
@@ -111,5 +111,45 @@ tc-ld-disable-gold |
19 |
) |
20 |
tend $? |
21 |
|
22 |
+unset CPP |
23 |
+ |
24 |
+tbegin "tc-get-compiler-type (gcc)" |
25 |
+( |
26 |
+export CC=gcc |
27 |
+[[ $(tc-get-compiler-type) == gcc ]] |
28 |
+) |
29 |
+tend $? |
30 |
+ |
31 |
+if type -P clang &>/dev/null; then |
32 |
+ tbegin "tc-get-compiler-type (clang)" |
33 |
+ ( |
34 |
+ export CC=clang |
35 |
+ [[ $(tc-get-compiler-type) == clang ]] |
36 |
+ ) |
37 |
+ tend $? |
38 |
+fi |
39 |
+ |
40 |
+if type -P pathcc &>/dev/null; then |
41 |
+ tbegin "tc-get-compiler-type (pathcc)" |
42 |
+ ( |
43 |
+ export CC=pathcc |
44 |
+ [[ $(tc-get-compiler-type) == pathcc ]] |
45 |
+ ) |
46 |
+ tend $? |
47 |
+ |
48 |
+ tbegin "! tc-is-gcc (pathcc)" |
49 |
+ ( |
50 |
+ export CC=pathcc |
51 |
+ ! tc-is-gcc |
52 |
+ ) |
53 |
+ tend $? |
54 |
+ |
55 |
+ tbegin "! tc-is-clang (pathcc)" |
56 |
+ ( |
57 |
+ export CC=pathcc |
58 |
+ ! tc-is-clang |
59 |
+ ) |
60 |
+ tend $? |
61 |
+fi |
62 |
|
63 |
texit |
64 |
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass |
65 |
index 1baab96..a29784c 100644 |
66 |
--- a/eclass/toolchain-funcs.eclass |
67 |
+++ b/eclass/toolchain-funcs.eclass |
68 |
@@ -585,6 +585,28 @@ tc-endian() { |
69 |
esac |
70 |
} |
71 |
|
72 |
+# @FUNCTION: tc-get-compiler-type |
73 |
+# @RETURN: keyword identifying the compiler: gcc, clang, pathcc, unknown |
74 |
+tc-get-compiler-type() { |
75 |
+ local code=' |
76 |
+#if defined(__PATHSCALE__) |
77 |
+ HAVE_PATHCC |
78 |
+#elif defined(__clang__) |
79 |
+ HAVE_CLANG |
80 |
+#elif defined(__GNUC__) |
81 |
+ HAVE_GCC |
82 |
+#endif |
83 |
+' |
84 |
+ local res=$($(tc-getCPP "$@") -E -P - <<<"${code}") |
85 |
+ |
86 |
+ case ${res} in |
87 |
+ *HAVE_PATHCC*) echo pathcc;; |
88 |
+ *HAVE_CLANG*) echo clang;; |
89 |
+ *HAVE_GCC*) echo gcc;; |
90 |
+ *) echo unknown;; |
91 |
+ esac |
92 |
+} |
93 |
+ |
94 |
# Internal func. The first argument is the version info to expand. |
95 |
# Query the preprocessor to improve compatibility across different |
96 |
# compilers rather than maintaining a --version flag matrix. #335943 |
97 |
-- |
98 |
2.9.0 |