Gentoo Archives: gentoo-commits

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