Wrong order of preprocessor and compiler flags

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

 



Hello,

I've found that everywhere in autoconf scripts flags are used like:
$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD
while automake and libtool use flags in the other order:
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)

Autoconf uses CFLAGS before CPPFLAGS during configure, but during compile-time flags are used in another order: CPPFLAGS are followed by CFLAGS. This can easily create hard-to-find problems, for example:
CFLAGS=-UENABLE_HEADERS_FEATURE
CPPFLAGS=-DENABLE_HEADERS_FEATURE=1
During configure, the macro ENABLE_HEADERS_FEATURE will be defined in tests so some features can be detected by configure, but during the compile time the macro ENABLE_HEADERS_FEATURE will be undefined.

It's not uncommon to use CFLAGS for macros or for '-I' flags.
I think it's easy to imagine other conflicting situation where the order of used flags is significant.

Usage of CPPFLAGS before CFLAGS looks logical for me, I think autoconf should be fixed.

The list of lines to be fixed in autoconf for (Obj)C/C++:
https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/autoconf/c.m4;hb=00358457d09c19ff6b5ec7ed98708540d1994a5f#l64
https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/autoconf/c.m4;hb=00358457d09c19ff6b5ec7ed98708540d1994a5f#l65
https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/autoconf/c.m4;hb=00358457d09c19ff6b5ec7ed98708540d1994a5f#l240
https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/autoconf/c.m4;hb=00358457d09c19ff6b5ec7ed98708540d1994a5f#l241
https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/autoconf/c.m4;hb=00358457d09c19ff6b5ec7ed98708540d1994a5f#l282
https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/autoconf/c.m4;hb=00358457d09c19ff6b5ec7ed98708540d1994a5f#l283
https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/autoconf/c.m4;hb=00358457d09c19ff6b5ec7ed98708540d1994a5f#l304
https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/autoconf/c.m4;hb=00358457d09c19ff6b5ec7ed98708540d1994a5f#l305
https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/autoconf/c.m4;hb=00358457d09c19ff6b5ec7ed98708540d1994a5f#l1757

Example of how flags are used by automake:
https://git.savannah.gnu.org/cgit/automake.git/tree/bin/automake.in?id=fee9a828bcc968656edfc89e38b157c28d6335f0#n700

If you agree, I will send the patch for autoconf.

--
Evgeny

PS I have tried to post it to bugs-autoconf, but failed for some reason.

Attachment: OpenPGP_0x460A317C3326D2AE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


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

  Powered by Linux