On 2024-07-08 11:44:45 -0400, Paul Smith wrote:
> On Mon, 2024-07-08 at 17:17 +0200, Vincent Lefevre wrote:
> > foo : $(objects)
> >         cc -o foo $(CFLAGS) $(objects)
> > 
> > This is misleading because $(CFLAGS) is not used in the implicit
> > rule.
> 
> I'm not sure I see the issue here (and with the example for
> .EXTRA_PREREQS): this is not an implicit rule, so there's no particular
> reason why it should have the exact same format as the implicit rule. 
> In this case we also omit $(LDLIBS) etc. because there are no extra
> libraries.

It falsely gives the impression that $(CFLAGS) is normally used for
linking. It should actually be $(LDFLAGS).

> > In Section 6.6:
> > 
> > CFLAGS += -pg # enable profiling
> > 
> > is a bad advice, as the gcc man page says:
> 
> I don't think this is bad advice.  This section of the manual is
> explaining the += operation and showing an example of how it works.  It
> has nothing to do with whether or not someone also added that flag to
> LDFLAGS or not: maybe they did.

Except that having to add a configuration option in two different
places is rather bad practice as being more error prone, and this
also needs to type more text (e.g. as a shell command), with an
increased risk of error. So one may not want to put such an option
in CFLAGS. I'm wondering whether such an option should rather be
added to CC.

> I guess we could choose some other option here, than -pg, but I don't
> see anything wrong particularly with this, in context.
> 
> > BTW, there should be an advice on what to do with options that are
> > needed both for C compilation and for linking (when GNU Automake
> > is not used, as Automake adds $(CFLAGS) for linking), like -pg,
> > -pthread, and sanitizer options.
> 
> I'm not sure where such advice would appear; it's not really the
> intention of the GNU Make manual to describe the ins and outs of how to
> invoke a compiler (notwithstanding all compilers are different).  The
> manual documents:
> 
> CFLAGS
>    Extra flags to give to the C compiler.
> 
> and:
> 
> LDFLAGS
>    Extra flags to give to compilers when they are supposed to invoke
>    the linker, ‘ld’, such as -L. Libraries (-lfoo) should be added to
>    the LDLIBS variable instead.
> 
> so if you have flags that need to be passed to both the compiler and
> linker you would set those flags in both variables.

The text for CFLAGS is actually ambiguous, because a C compiler
can be used to invoke the linker, but CFLAGS is not given in this
case.

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to