lmi
[Top][All Lists]
Advanced

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

Re: [lmi] [lmi-commits] master e4abb6e1 14/17: Don't specify nonempty $C


From: Greg Chicares
Subject: Re: [lmi] [lmi-commits] master e4abb6e1 14/17: Don't specify nonempty $CFLAGS or $CXXFLAGS
Date: Tue, 5 Jul 2022 10:11:27 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0

On 7/3/22 17:36, Vadim Zeitlin wrote:
> On Sat,  2 Jul 2022 21:42:15 -0400 (EDT) Greg Chicares 
> <gchicares@sbcglobal.net> wrote:
[...]
> GC>     Don't specify nonempty $CFLAGS or $CXXFLAGS
> GC>     
> GC>     The GNU coding standards
> GC>       https://www.gnu.org/prep/standards/html_node/Command-Variables.html
> GC>     suggest specifying "CFLAGS = -g" in makefiles. Until now, lmi had
> GC>     followed that rule (if not quite literally) by setting $CFLAGS and
> GC>     $CXXFLAGS to a default value of '-ggdb'. Now, this makefile assigns
> GC>     them no value, so that overriding them doesn't discard any default.
> 
>  FWIW there is also a school of thought which says that these flags should
> never be overridden, but only appended to. I'm relatively sympathetic to
> this idea because it's not nice when you're trying to compile some package
> with "make CPPFLAGS=-I/some/path/to/non/system/headers" only for the build
> to fail because the flags get clobbered somewhere in the makefiles. And it
> still allows overriding the optimization flags just as easily, knowing that
> only the last -Ox occurrence is taken into account.
> 
>  So perhaps there should be no assignments to C*FLAGS and += should always
> be used for them?

Let's try a concrete example, taking care to follow this advice:

https://www.gnu.org/software/make/manual/make.html#Overriding
| The makefile probably specifies the usual value for CFLAGS, like this:
| CFLAGS=-g

This makefile's author successfully forces "-fno-omit-frame-pointer",
but less successfully hopes also to specify a default flag '-g' that
is intended to persist when the user overrides $CFLAGS using "+=".

$ cat eraseme.make
CFLAGS=-g
ALL_CFLAGS = -std=c99 $(CFLAGS) -fno-omit-frame-pointer

%.o: %.c
        $(CC) $(ALL_CFLAGS) $< -o$@

test_flags:
        @echo "CFLAGS is $(CFLAGS)"
        @echo "ALL_CFLAGS is $(ALL_CFLAGS)"

With no command-line override, '-g' is used, of course:

$ make -f eraseme.make test_flags
CFLAGS is -g
ALL_CFLAGS is -std=c99 -g -fno-omit-frame-pointer

With a command-line override, '-g' vanishes:

$ make CFLAGS+="-O3 -fomit-frame-pointer" -f eraseme.make test_flags
CFLAGS is -O3 -fomit-frame-pointer
ALL_CFLAGS is -std=c99 -O3 -fomit-frame-pointer -fno-omit-frame-pointer

Writing "=" instead of "+=" produces the same outcome:

$ make CFLAGS="-O3 -fomit-frame-pointer" -f eraseme.make test_flags
CFLAGS is -O3 -fomit-frame-pointer
ALL_CFLAGS is -std=c99 -O3 -fomit-frame-pointer -fno-omit-frame-pointer


reply via email to

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