help-make
[Top][All Lists]
Advanced

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

Re: implicit rules


From: Paul D. Smith
Subject: Re: implicit rules
Date: Mon, 26 Apr 2004 15:35:42 -0400

%% Noel Yap <address@hidden> writes:

  ny> I think I meant "latter" (ie "%.mk: %.m").  How can I get make to
  ny> use the "%.mk: %.m" implicit rule to build aoeu/aoeu.mk?

You can't... at least not unless you have a file aoeu/aoeu.m that it can
be built from.

  ny> The reason one might want something like "%.mk: %.mk" (rather than
  ny> "foo.o: foo.o" which is different) is because of how implicit rule
  ny> matching treats directories.  For example, except for the spurious
  ny> "Cyclic dependency" errors, in the end, make did exactly what I
  ny> intended.

You just got lucky.  It might have chosen to drop the cycle a different
way.

  ny> IIUC, make can use "%.mk: %.mk" to match "aoeu/aoeu.mk: aoeu.mk".
  ny> OTOH, IIUC, make should use "%.mk: %.mk" to match "aoeu/aoeu.mk:
  ny> aoeu.m" so I'm clearly missing something here.

Yes: you're missing that the string that replaces the pattern ("%") has
to be THE IDENTICAL STRING in the target and the prerequisite.  These
are not globs, like shell wildcards or something, which are individually
examined.

When make sees a rule like:

    %.x : %.y

it does this: match the target pattern against the thing we're trying to
build.  If it doesn't match, go to the next one.  If it does match, then
take the string that matched the % in the target and substitute it into
the % in the prerequisite (if any).  Then try to see if _THAT_ target
can be built.

What it does _NOT_ do is this: match the target pattern against the
thing we're trying to build.  If it doesn't match, go to the next one.
If it does match, then try to find some file that might match the
prerequisite pattern or some way to build some file that might match the
prerequisite pattern.  Even writing this out it's obvious that this is
not a realistic algorithm.

  ny> This rule is now not as generic as before; one would have to write
  ny> a new rule depending on where the target will be created.

Yes, you're correct.  That's what you have to do.

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