[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: program creating two targets
From: |
Paul Smith |
Subject: |
Re: program creating two targets |
Date: |
Tue, 02 Sep 2008 17:10:42 -0400 |
On Tue, 2008-09-02 at 10:20 -0300, Boris Godin wrote:
> Werner LEMBERG wrote:
> > assume that program `bar' creates both `file1' and `file2'. I need a
> > rule like this:
> >
> > foo: file1 file2
> > bar
You mistyped this. You mean (based on your description above), that you
need a target like this:
file1 <and> file2:
bar
foo: file1 file2
But of course, just listing both files "file1 file2" as targets won't
work since that means this:
file1:
bar
file2:
bar
foo: file1 file2
which is what you're seeing.
> Try this:
>
> foo: | file1 file2
> bar
That won't work... actually this is less good because it won't rebuild
foo when EITHER file1 or file2 are built: order-only prerequisites don't
cause the targets that depend on them to rebuild when they change.
You have a choice (maybe). GNU make supports multiple targets created
by a single invocation of a recipe ONLY for pattern rules. So, if you
can rewrite your rule as a pattern rule, you win.
Of course if your targets do not have any stem in common then you cannot
use pattern rules. In this case you have to use a trick I usually refer
to as a "sentinel file". Write your rule like this:
foo: file1 file2
file1 file2: .sentinel
.sentinel:
bar
@touch $@
It's not perfect (for example you have to remember to delete the
sentinel file when you delete the file1 and file2 files, etc.) but it
does work and it solves the issue with parallel builds.