Boost logo

Boost-Build :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2007-03-20 03:53:36

[CC for convenience, please reply to list]

On Thursday 22 February 2007 20:54, John Reid wrote:
> Suppose I have a tool that compiles files of type .g into .cpp .hpp and
> .txt files. The names of these generated files can not be determined
> from the filename of the source .g file.
> I can register the .g type and create a rule and an action to run the
> tool. I am having problems using custom generators to tell
> which files the tool will generate.
> I've looked at the documentation:
> and I figured the quickest and easiest way to do this is to define
> features that are set on each .g source file and then inspect them in
> the generated-targets rule of the custom generator. Does this sound
> sensible?

That might work. Another solution would be to build python-enabled bjam
write a python script that parses your .g file, and use that to generate
the list of output files. Building python-enabled jam was documented in
a post to this list, but I'll try to put together some docs.

> Given the above I've struggled to work out how to return appropriate
> values from the custom generator rule.

What do you mean by 'values'? Targets with the right names?

> The documentation does not seem
> to cover this at all. Could someone provide me with example code to
> extract a filename from a feature and build a suitable return value for
> the generated-targets rule from it?

Have you see the example/generator example in the current version (CVS HEAD)
or nightly build link at

It has this:

        if ! $(name)
                    name = [ generator.determine-output-name $(sources) ] ;

I suppose that instead of that, you can use

        name = [ $(property-set).get <whatever-you-name-your-feature> ] ;

in case you have just a single name. In fact, if you have a single name,
your generators 'run' method can just obtain right name and that call
base 'run' method.

If you have several targets with different names, then you'd have to
modify the code to read something like that:

          local a = [ new action $(sources[1])
                  : common.copy : $(property-set) ] ;
                local t1 = [ new file-target NAME1 : TYPE1 : $(project)
                  : $(a) ] ;

        local t2 = [ new file-target NAME2 : TYPE2 : $(project)
                  : $(a) ] ;

        return $(t1) $(t2) ;

Hope this helps. Ask if something is still unclear.

- Volodya

Boost-Build list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at