help-make
[Top][All Lists]
Advanced

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

Re: Multiple target rule


From: Paul D. Smith
Subject: Re: Multiple target rule
Date: Fri, 16 Jul 2004 17:49:16 -0400

%% Samya DasSarma <address@hidden> writes:

  sd> Assume the makefile is:

  sd> targs = %.x %.z
  sd> $(targs):
  sd>       echo "$(@) $(suffix $(@))"
  sd> all:a.x a.z

  sd> Now, if I do gmake all, the output is:

  sd> echo "a.x .x"
  sd> a.x .x

  sd> Question is, why is it not trying to build a.z? There is no
  sd> a.x/a.z files present in my current directory.

It is.

You wrote:

    %.x %.z:
        <command>

That tells make that if it invokes your <command> one time, that one
invocation will build both targets.  So, it's invoking your command one
time.  When it does, $@ is set to whatever target caused the command to
be invoked (it can't be set to both at the same time of course!).  In
this case since a.x is the first one make considers, that's what $@ is
set to.

Pattern rules don't behave like explicit rules in this respect: check
out the description in the GNU make manual.

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