[Top][All Lists]

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

Re: bug involving .SUFFIXES ?

From: Paul D. Smith
Subject: Re: bug involving .SUFFIXES ?
Date: Wed, 7 Aug 2002 19:19:10 -0400

%% Willem Vermin <address@hidden> writes:

  wv> Using this Makefile:

  wv> #
  wv> .SUFFIXES::
  wv> .SUFFIXES:: .o

  wv> all:      foo.o

  wv> %.o:
  wv>   @echo value of '$$<' is $<
  wv>   @echo value of '$$@' is $@
  wv> #

  wv> I get as expected:

  wv>   value of $< is
  wv>   value of $@ is foo.o

Actually, this may be what you expected, but it is the wrong answer.

  wv> However, when I replace the double colons (::) after .SUFFIXES in
  wv> single colons (:), I get this:

  wv>   value of $< is
  wv>   value of $@ is foo.o
  wv>   value of $< is
  wv>   value of $@ is all.o
  wv>   cc   all.o foo.o   -o all
  wv>   cc: all.o: No such file or directory
  wv>   cc: foo.o: No such file or directory
  wv>   cc: No input files
  wv>   make: *** [all] Error 1

This is what you should get.

  wv> Is this a bug, or am I missing something?

Well, there does seem to be some inconsistency with the way double-colon
versions of .SUFFIX are handled.  A line like:


appears to behave like ".SUFFIXES:" (the latter is the correct way to
write it), while a line like:

  .SUFFIXES:: .o

does _not_ behave like ".SUFFIXES: .o".  They should both either work or
not work;  I'll have to check the POSIX spec to see which is correct.

Anyway, back to your original question, why you get the latter output.

When you put back the .o suffix, all the builtin rules that use that
suffix become active again.  In particular, the rule:

        $(LD) ...

which says "given a target foo, you can build it from a target foo.o
with this command".

You have specified this rule:

  all: foo.o

and you've provided make a way to build any kind of .o file with your
%.o rule.

So, make wants to build the target "all".  That target doesn't exist and
there's no explicit rule to build it, so make looks at its implicit
rules and it sees that it can construct any target X from a prerequisite
X.o, or, in this case, "all.o".  Not only that, but it knows how to
build "all.o", using the rule you provided.

So, that implicit rule matches and make builds all.o.

Next you've told it that this target also has foo.o as a prerequisite,
so make builds that.

Finally, the implicit rule says that X can be created from X.o by
running the linker, so it tries to do that, and fails of course since
your %.o rule didn't actually create any .o files.

This is the correct behavior.  The simplest way to avoid it is to use
.PHONY, like:

  .PHONY: all
  all: foo.o


See the GNU make manual for more information.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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