[dpdk-dev] [PATCH] mk: toolchain: gcc: query the compiler macros to obtain the gcc version

Thomas Monjalon thomas.monjalon at 6wind.com
Wed Mar 23 10:49:27 CET 2016


2016-03-22 22:50, Markos Chandras:
> On 22/03/16 22:34, Thomas Monjalon wrote:
> > 2016-03-22 17:13, Markos Chandras:
> >> This is similar to what's being used in the Linux kernel. Querying the
> >> GCC macros directly gives more accurate results compared to -dumpversion
> >> which could vary across distributions.
> >>
> >> Signed-off-by: Markos Chandras <mchandras at suse.de>
> >> ---
> >> In openSUSE Tumbleweed (and in any other SUSE distribution which
> >> uses (or will use) gcc >= 5), gcc -dumpversion returns '5'. This is on
> >> purpose as discussed in https://bugzilla.opensuse.org/show_bug.cgi?id=941428
> > 
> > Good to know. It could be in the commit log.
> 
> I can add this information to the commit message and send a v2 if needed.

I will apply with this info.

> >> -GCC_VERSION = $(subst .,,$(shell $(CC) -dumpversion | cut -f1-2 -d.))
> >> +GCC_MAJOR = $(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
> >> +GCC_MINOR = $(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)
> >> +GCC_VERSION = $(GCC_MAJOR)$(GCC_MINOR)
> > 
> > Are we sure the minor will always be only one digit?
> 
> Well, I can't be sure but minor has always been a single digit since gcc
> >= 3 if I am not mistaken. But does it matter? What if it is two or more
> digits? The previous code did something similar so if you had gcc
> 5.12.34 installed (and lets assume this is what is being returned by
> -dumpversion), it would have returned 512. The comparison would still
> work as it is at the moment no?

Yes, I was asking for an improvement in case it could happen.
But GCC is probably conservative with numbering so we can keep only one digit.


More information about the dev mailing list