Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: Fabian Groffen <grobian@g.o>
Cc: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH 3/4] toolchain-funcs.eclass: Add tc-get-compiler-type()
Date: Thu, 23 Jun 2016 09:02:17
Message-Id: 20160623110157.28876761.mgorny@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH 3/4] toolchain-funcs.eclass: Add tc-get-compiler-type() by Fabian Groffen
1 On Thu, 23 Jun 2016 08:52:20 +0200
2 Fabian Groffen <grobian@g.o> wrote:
3
4 > On 22-06-2016 22:06:53 +0200, Michał Górny wrote:
5 > > +# @FUNCTION: tc-get-compiler-type
6 > > +# @RETURN: keyword identifying the compiler: gcc, clang, unknown
7 > > +tc-get-compiler-type() {
8 > > + set -- $($(tc-getCPP "$@") -E -P - <<<"CPP_WORKS __GNUC__ __clang__")
9 >
10 > % echo "CPP_WORKS __GNUC__ __clang__" | clang -E -P -
11 > CPP_WORKS 4 1
12 >
13 > The logic below does the right thing, but it might be good for future
14 > reference to make note of this (clang).
15
16 I'm actually thinking of moving the whole logic into cpp using '#if
17 defined', and just matching the output for the result. This would be
18 easier to maintain in the future, I guess.
19
20 > > +
21 > > + # CPP_WORKS shouldn't be substituted -- so if it's not there,
22 > > + # cpp is probably broken
23 > > + if [[ $1 != CPP_WORKS ]]; then
24 > > + echo unknown
25 > > + # Check which of the defines were substituted
26 > > + elif [[ $3 != __clang__ ]]; then
27 > > + echo clang
28 > > + elif [[ $2 != __GNUC__ ]]; then
29 > > + echo gcc
30 > > + else
31 > > + echo unknown
32 > > + fi
33 > > +}
34 >
35
36
37
38 --
39 Best regards,
40 Michał Górny
41 <http://dev.gentoo.org/~mgorny/>