Page MenuHomeFreeBSD

bsd.compiler.mk: Detect distribution-provided GCC when executed as cc
ClosedPublic

Authored by jrtc27 on Jan 23 2021, 9:07 PM.

Details

Summary

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.

Diff Detail

Repository
R10 FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

This revision is now accepted and ready to land.Jan 23 2021, 11:41 PM

This is fine with me.

Perhaps we can simplify it to always use ${${cc}:N${CCACHE_BIN}} -v (instead of --version). We'd have to make sure all existing cases still work though.

This is fine with me.

Perhaps we can simplify it to always use ${${cc}:N${CCACHE_BIN}} -v (instead of --version). We'd have to make sure all existing cases still work though.

Yeah I think that should work just fine, it's what we use in our cheribuild tool for similar detection, this was just the easiest non-controversial targeted fix (in that it only changes code that currently emits an error, so surely there can't be any regressions!).

it only changes code that currently emits an error

Yeah, it's for that reason that I'm fine with it as-is if you want to leave it.