[Top][All Lists]

[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 <> 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.


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:

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.



PS Let's move this discussion to the 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]