Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: toolchain@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 2/2] toolchain-funcs.eclass: Add helpful tc-is-{gcc,clang} wrappers
Date: Thu, 23 Jun 2016 09:19:45
Message-Id: 20160623091826.13631-3-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 0/2] v3: tc-get-compiler-type() & wrappers by "Michał Górny"
1 ---
2 eclass/tests/toolchain-funcs.sh | 28 ++++++++++++++++++++++++++++
3 eclass/toolchain-funcs.eclass | 14 ++++++++++++++
4 2 files changed, 42 insertions(+)
5
6 diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
7 index 0b9b7d7..d86eee4 100755
8 --- a/eclass/tests/toolchain-funcs.sh
9 +++ b/eclass/tests/toolchain-funcs.sh
10 @@ -118,6 +118,20 @@ export CC=gcc
11 )
12 tend $?
13
14 +tbegin "tc-is-gcc (gcc)"
15 +(
16 +export CC=gcc
17 +tc-is-gcc
18 +)
19 +tend $?
20 +
21 +tbegin "! tc-is-clang (gcc)"
22 +(
23 +export CC=gcc
24 +! tc-is-clang
25 +)
26 +tend $?
27 +
28 if type -P clang &>/dev/null; then
29 tbegin "tc-get-compiler-type (clang)"
30 (
31 @@ -125,6 +139,20 @@ if type -P clang &>/dev/null; then
32 [[ $(tc-get-compiler-type) == clang ]]
33 )
34 tend $?
35 +
36 + tbegin "! tc-is-gcc (clang)"
37 + (
38 + export CC=clang
39 + ! tc-is-gcc
40 + )
41 + tend $?
42 +
43 + tbegin "tc-is-clang (clang)"
44 + (
45 + export CC=clang
46 + tc-is-clang
47 + )
48 + tend $?
49 fi
50
51 texit
52 diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
53 index 4a45f78..67eab38 100644
54 --- a/eclass/toolchain-funcs.eclass
55 +++ b/eclass/toolchain-funcs.eclass
56 @@ -604,6 +604,20 @@ tc-get-compiler-type() {
57 esac
58 }
59
60 +# @FUNCTION: tc-is-gcc
61 +# @DESCRIPTION:
62 +# Return true if the current compiler is pure GCC.
63 +tc-is-gcc() {
64 + [[ $(tc-get-compiler-type) == gcc ]]
65 +}
66 +
67 +# @FUNCTION: tc-is-clang
68 +# @DESCRIPTION:
69 +# Return true if the current compiler is clang.
70 +tc-is-clang() {
71 + [[ $(tc-get-compiler-type) == clang ]]
72 +}
73 +
74 # Internal func. The first argument is the version info to expand.
75 # Query the preprocessor to improve compatibility across different
76 # compilers rather than maintaining a --version flag matrix. #335943
77 --
78 2.9.0