help-make
[Top][All Lists]
Advanced

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

Re: Problem with Implicit Rules


From: Paul D. Smith
Subject: Re: Problem with Implicit Rules
Date: Mon, 2 Oct 2000 11:08:05 -0400

%% Regarding Problem with Implicit Rules; you wrote:

  jb> I have a problem where make fails and I don't think it's something
  jb> that I'm doing wrong.

It is, though :).

  jb> <Makefile contents>
  jb> SRCDIR=../src

  jb> all: foodir/foo.o

  jb> %.o $(SRCDIR)/%.c
  jb>   $(CC) -c -o $@ $(CFLAGS) $<

You're missing a ":" here; I assume in your real makefile it exists
otherwise you'd get a syntax error.

  jb> % make
  jb> make: *** No rule to make target `foodir/foo.o', needed by
  jb> `all'.  Stop.

Just as I'd expect.

  jb> The line that seems to indicate there's a bug in make is:

  jb> Looking for a rule with intermediate file
  jb> `foodir/../src/foo.c'.

  jb> The implicit rule that is defined in the makefile is

  jb> %.o: $(SRCDIR)/%.c

  jb> SRCDIR = ../src, so I would think that $(SRCDIR)/%.c should be
  jb> equivalent to ../src/foodir/foo.c not foodir/../src/foo.c.

No.  See the GNU make manual section "How Patterns Match".  I quote:

     When the target pattern does not contain a slash (and it usually does
  not), directory names in the file names are removed from the file name
  before it is compared with the target prefix and suffix.  After the
  comparison of the file name to the target pattern, the directory names,
  along with the slash that ends them, are added on to the prerequisite
  file names generated from the pattern rule's prerequisite patterns and
  the file name.

  jb> Is there a workaround other than using VPATH?

VPATH won't help with what you want to do anyway.  You must use a
pattern rule like this:

  $(OBJDIR)/%.o : $(SRCDIR)/%.c
            $(CC) ... -o $@

where OBJDIR = foodir.

See my discussion of VPATH below for some more details.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://www.paulandlesley.org/gmake/
 "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]