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 4/4] toolchain-funcs.eclass: Add helpful tc-is-{gcc,clang} wrappers
Date: Fri, 24 Jun 2016 20:09:35
Message-Id: 20160624200733.8446-5-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH v4] tc-get-compiler-type() + wrappers by "Michał Górny"
1 ---
2 eclass/tests/toolchain-funcs.sh | 28 ++++++++++++++++++++++++++++
3 eclass/toolchain-funcs.eclass | 12 ++++++++++++
4 2 files changed, 40 insertions(+)
5
6 diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
7 index 6f37996..e6a1538 100755
8 --- a/eclass/tests/toolchain-funcs.sh
9 +++ b/eclass/tests/toolchain-funcs.sh
10 @@ -120,6 +120,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 @@ -127,6 +141,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 if type -P pathcc &>/dev/null; then
52 diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
53 index a29784c..d3abfb5 100644
54 --- a/eclass/toolchain-funcs.eclass
55 +++ b/eclass/toolchain-funcs.eclass
56 @@ -607,6 +607,18 @@ tc-get-compiler-type() {
57 esac
58 }
59
60 +# @FUNCTION: tc-is-gcc
61 +# @RETURN: Shell true if the current compiler is GCC, false otherwise.
62 +tc-is-gcc() {
63 + [[ $(tc-get-compiler-type) == gcc ]]
64 +}
65 +
66 +# @FUNCTION: tc-is-clang
67 +# @RETURN: Shell true if the current compiler is clang, false otherwise.
68 +tc-is-clang() {
69 + [[ $(tc-get-compiler-type) == clang ]]
70 +}
71 +
72 # Internal func. The first argument is the version info to expand.
73 # Query the preprocessor to improve compatibility across different
74 # compilers rather than maintaining a --version flag matrix. #335943
75 --
76 2.9.0