Discussion:
how to detect gcc version in configure.ac
Minxuan Zhuang
2014-07-04 05:38:42 UTC
Permalink
a project needs to satisfy both gcc 4.1.2 and gcc 4.7.3, but some options
in the latter one(like -Wno-narrowing and Wno-unused-result) cannot be used
in the former one. So I need to test the cutrrent gcc version and decide
what can of option can be assigned to CFLAGS, sth like:

if gcc version == 4.1.2
CFLAGS=....
else
CFLAGS =.....

how can I implement it in configure.ac?
Eric Blake
2014-07-04 12:59:22 UTC
Permalink
Post by Minxuan Zhuang
a project needs to satisfy both gcc 4.1.2 and gcc 4.7.3, but some options
in the latter one(like -Wno-narrowing and Wno-unused-result) cannot be used
in the former one. So I need to test the cutrrent gcc version and decide
No. You _don't_ want to test the compiler version. Instead, you want
to test the compiler feature (as features can be backported across
versions).
Post by Minxuan Zhuang
if gcc version == 4.1.2
CFLAGS
else
CFLAGS =.....
how can I implement it in configure.ac?
Look at how gnulib does it:

http://git.savannah.gnu.org/cgit/gnulib.git/tree/m4/manywarnings.m4
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
David A. Wheeler
2014-07-04 16:18:53 UTC
Permalink
This does not help you right now, but Dale Visser posted a patch to autoconf a few months ago that would solve your problem correctly. His patch adds the ability to check if a compiler supports a particular flag. My hope is that this ability will soon be added to autoconf. Clearly some people want it.
--- David A.Wheeler
Mike Frysinger
2014-08-01 09:52:49 UTC
Permalink
Post by David A. Wheeler
This does not help you right now, but Dale Visser posted a patch to autoconf
a few months ago that would solve your problem correctly. His patch adds
the ability to check if a compiler supports a particular flag. My hope is
that this ability will soon be added to autoconf. Clearly some people want
it. --- David A.Wheeler
macros are available in the autoconf-archive project. i think it's reasonable
to point people to that instead for things like this.
-mike

Loading...