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: Vadim Zeitlin
Subject: Re: [lmi] [lmi-commits] master e4abb6e1 14/17: Don't specify nonempty $CFLAGS or $CXXFLAGS
Date: Wed, 6 Jul 2022 15:35:38 +0200

On Wed, 6 Jul 2022 01:48:39 +0000 Greg Chicares <gchicares@sbcglobal.net> wrote:

GC> I thought you meant that the makefile user should use "+=", but
GC> instead you mean that the makefile author should use "+="
GC> (whereas the GNU make manual prescribes a simple "=" here).

 Yes, with a slight extra twist, please see below.

GC> >  The idea would rather be to write "CFLAGS += -g" in the makefile itself,
GC> > wouldn't it?
GC> 
GC> I'm not convinced, but let's try:
GC> 
GC> /opt/lmi/src/lmi[0]$cat eraseme.make                                        
     
GC> CFLAGS += -g
GC> 
GC> test_flags:
GC>         @echo "CFLAGS is $(CFLAGS)"
GC> /opt/lmi/src/lmi[0]$make -f eraseme.make test_flags                         
         
GC> CFLAGS is -g
GC> /opt/lmi/src/lmi[0]$make CFLAGS="-O3" -f eraseme.make test_flags 
GC> CFLAGS is -O3
GC> 
GC> If I override CFLAGS on the command line, then "CFLAGS += -g"
GC> in the makefile has no effect.

 That's correct. However please consider this command

        % CFLAGS=-O3 make -f eraseme.make test_flags
        CFLAGS is -O3 -g

I.e. this works when CFLAGS is specified in the environment, which is a
relatively common use case, I think (at least it is for me).

GC> I don't see any benefit to specifying CFLAGS in the makefile.

 IMHO using "+=" like this is nice because it allows to append to the flags
specified in the environment, while still allowing to fully override them,
if really necessary, by specifying them on make command line. But I admit
that this might be too subtle, which is another word for "confusing".

 So another alternative is to use

        override CFLAGS += -g

as this allows to always add "-g" to CFLAGS, even if it's specified on make
command line.

GC> I think the best technique is to define ALL_CFLAGS in terms
GC> of CFLAGS, thus:
GC>   ALL_CFLAGS = overridable_flags $(CFLAGS) non_overridable_flags

 This seems equivalent to

        CFLAGS := overridable_flags
        override CFLAGS += non_overridable_flags

with the advantage of not multiplying the variables needlessly. However the
former approach might be more clear.

 Regards,
VZ

Attachment: pgpBiIvtNqARZ.pgp
Description: PGP signature


reply via email to

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