Re: How to get autoconf to respect CC="gcc -std=c89"?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On 11.10.2023 17:10, Zack Weinberg wrote:
On Wed, Oct 11, 2023, at 9:34 AM, Evgeny Grin wrote:
It works, actually. ./configure CC=gcc CFLAGS=-std=c89

C99 check would fail, compiler would be accepted as C89-compatible.

This only works if both and all the Makefiles have been
written "correctly".  I put "correctly" in quotes because, yes, it *is*
how you should write them, and it *is* what you get if you aren't trying
to do anything complicated -- but if you *do* need to do something
complicated, it is very easy to break this property by accident and
without noticing.  And I don't think everything you need to do to avoid
breaking it is documented, so we can't even claim that we warned people.

It can be broken if:
* CFLAGS are filtered by 'configure' / Makefiles
* CFLAGS value is not passed to Makefiles / not unsed in Makefiles
* Some '-std=xxx' flag is added *after* user CFLAGS in configure / Makefiles

The first case is an intentional break of autoconf design.
The second option is very badly designed configuration, not supported at all. The last one is incorrect as well and intentional prevention of user-specified C standard.

In other cases it will work.
Configure will not add -std= overriding flags and CFLAGS are used in Makefiles.

However, I agree that current autoconf + automake design is confusing.
At first user's CFLAGS are passed to 'configure'.
The configure *must* pass the same CFLAGS to automake, so if 'make' is executed with some CFLAGS=... override, such override must replace only user-supplied (for configure) CFLAGS and not automatically added compiler flags. At the same time, user CFLAGS should be added *after* automatic/configure-detected flags to be able to override them.

Knowing that each and every configure check (for C compiler) uses CFLAGS, it is very tempting just to modify CFLAGS inside the configure.

I'm not sure whether there are any suggested way of using/passing/modifying flags, which is documented for configure. In my projects I use special variable to hold user-supplied CFLAGS, in other variable I accumulate configure-detected additional flags. Before every check I combine flags like CFLAGS="conf_CFLAGS user_CFLAGS". Finally the value of "user_CFLAGS" is passed to automake files as "CFLAGS", value of "conf_CFLAGS" is used as part of AM_CFLAGS. Not sure whether it is the best way and why it is not fully documented, but this is another story.


Attachment: OpenPGP_0x460A317C3326D2AE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux