Date: Sat, 10 Apr 2021 13:29:57 GMT From: Alex Richardson <arichardson@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 57971fe46793 - stable/13 - bsd.compiler.mk: Detect distribution-provided GCC when executed as cc Message-ID: <202104101329.13ADTvEV001920@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by arichardson: URL: https://cgit.FreeBSD.org/src/commit/?id=57971fe46793911bcd976928fed8b19df4497a0b commit 57971fe46793911bcd976928fed8b19df4497a0b Author: Jessica Clarke <jrtc27@FreeBSD.org> AuthorDate: 2021-02-09 21:40:24 +0000 Commit: Alex Richardson <arichardson@FreeBSD.org> CommitDate: 2021-04-10 12:55:29 +0000 bsd.compiler.mk: Detect distribution-provided GCC when executed as cc Clang always prints "clang $VERSION" regardless of the name used to execute it, whereas GCC prints "$progname $VERSION", meaning if CC is set to cc and cc is GCC it will print "cc $VERSION". We are able to detect some of those cases since it then prints "($PKGVERSION)", where the default is "GCC", but many distributions override that to print their name and the package version number (e.g. "Debian 10.2.1-6"), so nothing tells us it's GCC other than the fact that it's not Clang (and that there's an FSF copyright disclaimer). However, GCC's -v option will always print "gcc version $VERSION", so fall back on using that to detect GCC. Whilst Clang also supports this option, we should never get here, so Clang handling is not added. Reviewed by: brooks, emaste, arichardson Differential Revision: https://reviews.freebsd.org/D28315 (cherry picked from commit 9c6954329a9285547881ddd60e393b7c55ed30c4) --- share/mk/bsd.compiler.mk | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/share/mk/bsd.compiler.mk b/share/mk/bsd.compiler.mk index 8253669fe279..fa8e6c44a17e 100644 --- a/share/mk/bsd.compiler.mk +++ b/share/mk/bsd.compiler.mk @@ -187,7 +187,16 @@ ${X_}COMPILER_TYPE:= gcc . elif ${_v:Mclang} || ${_v:M(clang-*.*.*)} ${X_}COMPILER_TYPE:= clang . else +# With GCC, cc --version prints "cc $VERSION ($PKGVERSION)", so if a +# distribution overrides the default GCC PKGVERSION it is not identified. +# However, its -v output always says "gcc version" in it, so fall back on that. +_gcc_version!= ${${cc}:N${CCACHE_BIN}} -v 2>&1 | grep "gcc version" +. if !empty(_gcc_version) +${X_}COMPILER_TYPE:= gcc +. else .error Unable to determine compiler type for ${cc}=${${cc}}. Consider setting ${X_}COMPILER_TYPE. +. endif +.undef _gcc_version . endif .endif .if !defined(${X_}COMPILER_VERSION)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104101329.13ADTvEV001920>