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