git: 9c6954329a92 - main - bsd.compiler.mk: Detect distribution-provided GCC when executed as cc
Jessica Clarke
jrtc27 at FreeBSD.org
Tue Feb 9 21:42:01 UTC 2021
The branch main has been updated by jrtc27:
URL: https://cgit.FreeBSD.org/src/commit/?id=9c6954329a9285547881ddd60e393b7c55ed30c4
commit 9c6954329a9285547881ddd60e393b7c55ed30c4
Author: Jessica Clarke <jrtc27 at FreeBSD.org>
AuthorDate: 2021-02-09 21:40:24 +0000
Commit: Jessica Clarke <jrtc27 at FreeBSD.org>
CommitDate: 2021-02-09 21:40:24 +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
---
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)
More information about the dev-commits-src-all
mailing list