bug-make
[Top][All Lists]
Advanced

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

inconsistent use of CFLAGS in the GNU make manual


From: Vincent Lefevre
Subject: inconsistent use of CFLAGS in the GNU make manual
Date: Mon, 8 Jul 2024 17:17:25 +0200
User-agent: Mutt/2.2.13+76 (1f3da810) vl-167818 (2024-04-20)

In the GNU make manual 0.77 as found at

  https://www.gnu.org/software/make/manual/make.html

the implicit rule for linking is, as given in Section 10.2:

  n is made automatically from n.o by running the C compiler to
  link the program. The precise recipe used is
  ‘$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)’.

There is no $(CFLAGS). But examples given earlier in the manual could
make the user think that it is present in the implicit rule.

Section 4.4.2 contains the example

objects = *.o

foo : $(objects)
        cc -o foo $(CFLAGS) $(objects)

This is misleading because $(CFLAGS) is not used in the implicit rule.

In Section 6.6:

CFLAGS += -pg # enable profiling

is a bad advice, as the gcc man page says:

  -pg Generate  extra  code  to write profile information suitable for the
      analysis program prof (for -p) or gprof (for  -pg).   You  must  use
      this option when compiling the source files you want data about, and
      you must also use it when linking.
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

while CFLAGS is *not* used when linking.

In Section 6.14, about .EXTRA_PREREQS:

myprog: myprog.o file1.o file2.o
       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)

and ditto in the subsequent examples.

Again, this is inconsistent with the implicit rule.

In Section 10.1:

foo : foo.o bar.o
        cc -o foo foo.o bar.o $(CFLAGS) $(LDFLAGS)

Same issue.

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.

-- 
Vincent Lefèvre <vincent@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

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