Hello, everyone.
Here's my second attempt at improving version checks
in toolchain-funcs.eclass. Currently the functions use $(tc-getCPP)
to determine gcc version. This doesn't trigger expected results when CC
& CXX are overriden but CPP is not which is a common case -- it causes
the eclass to fallback to 'cpp' and therefore use active gcc version
rather than the CC being used.
My initial fix was limited to defaulting the preprocessor to '$(CC) -E'
rather than 'cpp'. However, as eroen pointed out clang reports gcc
version 4.2 which would cause numerous ebuild checks to fail. Therefore,
I've decided to extend the patchset with means to prevent that.
Aside to fixing tc-getCPP and therefore gcc-*version functions to use
the active compiler, it also introduces a generic tc-get-compiler-type
function that identifies the compiler as either gcc and clang (support
for more compilers welcome). Two friendly wrappers are provided as well:
tc-is-gcc and tc-is-clang.
Note that unlike common less and more successful CC/CXX comparisons,
the functions actually use preprocessor macros to identify the compiler.
The common use cases:
a. checking for a specific gcc version:
[[ $(gcc-major-version) = 5 && $(gcc-minor-version) -le 2 ]]
would become:
tc-is-gcc && [[ $(gcc-major-version) = 5 && $(gcc-minor-version) -le 2 ]]
i.e. it would not trigger for clang.
b. applying clang-specific quirks (discouraged but people still do
that):
[[ ${CC} == *clang* ]] && ...
would become:
tc-is-clang && ...
Michał Górny (4):
toolchain-funcs.eclass: Fix _tc-getPROG with multi-parameter defaults
toolchain-funcs.eclass: Assume CPP="$(tc-getCC) -E" when unset,
#582822
toolchain-funcs.eclass: Add tc-get-compiler-type()
toolchain-funcs.eclass: Add helpful tc-is-{gcc,clang} wrappers
eclass/tests/toolchain-funcs.sh | 15 ++++++++++++++
eclass/toolchain-funcs.eclass | 43 ++++++++++++++++++++++++++++++++++++-----
2 files changed, 53 insertions(+), 5 deletions(-)
--
2.9.0