[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Dealing with commands that generate more than one target with -j
From: |
Dale King |
Subject: |
Dealing with commands that generate more than one target with -j |
Date: |
Mon, 08 Aug 2005 23:45:42 -0500 |
User-agent: |
Mozilla Thunderbird 1.0.2 (Windows/20050317) |
I'm wondering if there is a better way to handle the case where multiple
files get built by the same command. One example, might be the link step
which generates both the executable and a map file, but it could be any
program that generates more than one file.
Let's take as a hypothetical example a command foo that given a file a
in some language that produces a C header and source file. One might
think you would design a rule like this:
a.h a.c : a
foo a
This is of course, the multiple targets for one rule and does not say
that both will be generated by executing the command. The above is the
equivalent of
a.h : a
foo a
a.c : a
foo a
Which says nothing about the joint nature of the two targets.
Even though the semantics are not correct under a normal make this works
and generates the files. However it does not work correctly when using
-j to do parallel make. I'm a little puzzled how to express this so that
it works with a parallel make.
The first problem is that it can try to run two copies of foo at the
same time which will not work correctly. I tried adding a rule to force
an ordering so that doesn't happen:
a.c : | a.h
That keeps it from running two copies of foo at the same time, but it
still does run foo twice and if we add a rule like this:
d : a.c
bar $< -o $@
We run into a problem that now the second running of foo can run at the
same time as bar which fails as well.
This can be fixed by adding to this rule that you have to wait on a.c:
d : a.c | a.h
bar $< -o $@
But this is cumbersome to make everything dependent on both and still
doesn't prevent the dual execution of foo.
So is there a good way out of this puzzle?
- Dealing with commands that generate more than one target with -j,
Dale King <=