bug-autoconf
[Top][All Lists]
Advanced

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

Re: Wrong order of preprocessor and compiler flags


From: Evgeny Grin
Subject: Re: Wrong order of preprocessor and compiler flags
Date: Thu, 24 Mar 2022 22:30:10 +0300
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0

On 24.03.2022 21:37, Nick Bowler wrote:
On 2022-03-24, Zack Weinberg <zack@owlfolio.org> wrote:
On Thu, Mar 24, 2022, at 11:13 AM, Nick Bowler wrote:
However, GNU coding standards state that CFLAGS should be the last
item on compilation commands, so it would appear that this is a case
where traditional "make" behaviour contrasts with GNU standards (which
Automake is following).

Huh.  Is there a rationale given in the coding standard?  If not, do you
have any idea who might remember the rationale?

The GNU standards just say this[1]:

   "Put CFLAGS last in the compilation command, after other variables
    containing compiler options, so the user can use CFLAGS to override
    the others."

When it comes to C(PP)FLAGS the concept of "overriding" options is a
bit hairy -- many C compiler options do not have direct methods to undo
their effects -- but whatever.

[1] https://www.gnu.org/prep/standards/standards.html#Command-Variables


Actually example in the GNU standards doesn't use CPPFLAGS, while a few lines above it's clearly mentioned "Use CPPFLAGS in any compilation command that runs the preprocessor". Compiler runs preprocessor internally, so example should have CPPFLAGS with $(CC).

Anyway, I suggest to not read this too literally, but instead see the idea behind. The idea is to give user freedom to override any supplied flags. For automake[1] it is supported by AM_CFLAGS, foo_CFLAGS, and CFLAGS. CFLAGS must be always used after AM_CFLAGS, so user can easily override final behaviour without makefiles patching.


To align with make implementations, that never use CPPFLAGS before CFLAGS [2] and follow the GNU coding standard, I suggest to use the next combination of flags:
$(CC) $(AM_CFLAGS) $(AM_CPPFLAGS) $(CFLAGS) $(CPPFLAGS) -c

CFLAGS and CPPFLAGS are designed to be used by the user. With this combination user may override any upstream-supplied AM_CFLAGS and AM_CPPFLAGS by CFLAGS (and by CPPFLAGS as well) so GNU standards are met. At the same time all CPPFLAGS are used after CFLAGS and this is aligned with all 'make' implementations.


[1] https://www.gnu.org/software/automake/manual/automake.html#Flag-Variables-Ordering
[2] https://lists.gnu.org/archive/html/autoconf/2022-03/msg00010.html

--
Evgeny

PS Let's move this discussion to the autoconf@gnu.org list

Attachment: OpenPGP_0x460A317C3326D2AE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]