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)
Jan 29 2024, 1:19 PM
Unknown Object (File)
Dec 20 2023, 3:05 AM
Unknown Object (File)
Dec 14 2023, 8:17 PM
Unknown Object (File)
Oct 16 2023, 11:43 AM
Unknown Object (File)
Aug 16 2023, 8:20 AM
Unknown Object (File)
Aug 16 2023, 7:40 AM
Unknown Object (File)
Aug 14 2023, 9:55 PM
Unknown Object (File)
Aug 6 2023, 10:32 PM
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.