Page MenuHomeFreeBSD

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

Authored by jrtc27 on Jan 23 2021, 9:07 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 11, 4:59 PM
Unknown Object (File)
Mon, Dec 9, 2:16 PM
Unknown Object (File)
Nov 1 2024, 7:58 AM
Unknown Object (File)
Oct 6 2024, 6:56 AM
Unknown Object (File)
Oct 6 2024, 2:08 AM
Unknown Object (File)
Oct 5 2024, 10:39 PM
Unknown Object (File)
Oct 3 2024, 8:13 AM
Unknown Object (File)
Oct 3 2024, 12:06 AM
Subscribers

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
rG FreeBSD src repository
Lint
Lint Not Applicable
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.