help-make
[Top][All Lists]
Advanced

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

Multiple targets generated by one rule


From: Ben Wilhelm
Subject: Multiple targets generated by one rule
Date: Mon, 09 Apr 2007 16:20:40 -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


My build process includes a step which generates multiple output files from a set of input files and a single command. For example:

a b c d: source
blackbox_generate a b c d # pretend that, for some reason, these can't be split up.

The problem is that when make realizes it needs to build a, b, c, and d, it runs the command four times, once for each file it needs. Obviously this isn't really necessary. Worse than that, when I run it with -j3 it's occasionally causing build problems as three separate versions of the program attempt to execute at once.

The only solution I came up with was to create a flag file, and change the dependencies:

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.)

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.

Thanks,

-Ben




reply via email to

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