[jamming] trouble with rule that generates a .cpp file
Ingo Weinhold
bonefish at cs.tu-berlin.de
Thu Jul 5 17:00:38 PDT 2007
On 2007-07-05 at 22:21:51 [+0200], Joshua ChaitinPollak
<jpollak at kivasystems.com> wrote:
>
> I have a rule, WriteRevision, in my Jamrules file that polls my revision
> control system and generates a file called revision.cpp. I'm having
> trouble getting it to work reliably with multiple sub executables.
> Either the revision.cpp file is created in an unexpected directory, or
> jam can't find it correctly. What I would like is to make my
> WriteRevision rule alway create revision.cpp in $(TOP), and have jam
> know to look there for revision.cpp when I include it in my binaries
> with the Main rule.
>
> Can someone help? Examples and my WriteRevision rule are below.
When you use an own rule with actions to generate a file, you have to set
the LOCATE variable on the generated target (since you define the interface
to your rule, you can as well require the caller to do that, of course).
E.g. if you want your WriteRevision rule to place things in TOP, you'd need
to add:
LOCATE on $(<) = $(TOP) ;
Your second problem is that Main automatically (and uncircumventably) adds
grist to the source files you supply. The grist is different in each
subdirectory, so you've got an individual revision.cpp target per
subdirectory, each being different from the revision.cpp you generate
(which has no grist at the moment).
You could add something like this in each subdirectory after the Main
invocation:
Depends [ FGristFiles revision.cpp ] : revision.cpp ;
LOCATE on [ FGristFiles revision.cpp ] = $(TOP) ;
This should work, though it's a little ugly. I'd recommend to build a
static library from revision.cpp instead and link your executables against
this library. Note, that just as Main the Library rule also adds grist to
the supplied sources, so best simply invoke WriteRevision with a gristed
source file in the same Jamfile you're building the library:
WriteRevision [ FGristFiles revision.cpp ] ;
Library librevision.a : revision.cpp ;
CU, Ingo
More information about the jamming
mailing list