help-make
[Top][All Lists]
Advanced

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

Re: Multiple targets generated by one rule


From: Ben Wilhelm
Subject: Re: Multiple targets generated by one rule
Date: Tue, 10 Apr 2007 17:15:36 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.0


There's no pattern rule I can use that would work well, so I'm going to use the first solution, which is at least cleaner than what I was doing before. Thanks for the help. :)

-Ben

Paul Smith wrote:
On Mon, 2007-04-09 at 16:20 -0700, Ben Wilhelm wrote:

a b c d: source.flag
   @true

source.flag: source
   ( touch source.flag && blackbox_generate a b c d ) \
     || ( rm -f source.flag && false )   # eugh

but this is horribly ugly, although it does work. (I think the @true is necessary but to be honest I'm hazy as to why, although it doesn't rebuild the things that depend on a b c d without it.)

You can write this much more cleanly, like this:

        a b c d: .source_flag
                @:
.source_flag: source
                blackbox_generate a b c d
                @touch .source_flag

Is there a good solution to this? Ideally one without extra temporary files? While I know why the first case doesn't work ("A rule with multiple targets is equivalent to writing many rules, each with one target, and all identical aside from that." from 4.10 in the make manual) I haven't been able to figure out how to get the behavior I want.

There are only two ways to do what you want.  The one above works for
all types of targets.

The other way is to use pattern rules: if your targets and a
prerequisite share a stem that can be matched by a pattern ("%"), then
you can write:

        %a %b %c %d: %source
                blackbox_generate $*a $*b $*c $*d

Unlike explicit rules, pattern rules with multiple targets behave as you
are looking for: they build all the targets with one invocation of the
command script.

If you can't use pattern rules then you must use temporary files, sorry.
Although the method I show above is much cleaner, and users will
probably not notice the difference.





reply via email to

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