Boost logo

Boost-Build :

Subject: [Boost-build] How to set special generation requirements for generated files
From: Moritz Hassert (mhassert_at_[hidden])
Date: 2010-07-22 13:34:43


Hi all,

I'm building a library containing several yy-files, which are converted to cpp-
files by the bison generator tool. The straight forward solution

lib foo
    : somefile.cpp
      bison1.yy
      bison2.yy
    : <define>SOME_MACRO
     <include>some/path ;

compiles the generated bison1.cpp and bison2.cpp but fails to link, as bison
uses the same names for some global symbols (for example: "yychar") in each of
the cpp-files.

The solution to this is to tell bison to use different prefixes using the
<bison-prefix> feature.

But the only way I got this working seems complicated/ugly to me:

obj bison1
    : bison1.yy
    : <bison.prefix>pre1
      <define>SOME_MACRO
      <include>some/path ;

obj bison2
    : bison2.yy
    : <bison.prefix>pre2
      <define>SOME_MACRO
      <include>some/path ;

lib foo
    : somefile.cpp
      bison1
      bison2
    : <define>SOME_MACRO
     <include>some/path ;

Note how I have to repeat the <include> and <define> requirements in all obj
targets because they don't get propagated. They are needed because an obj
target not only generates the cpp file but also compiles it. I can't put them
in the project requirements because there are other targets in that project
with different requirements.

Two things I tried without success:

1)

lib foo
    : somefile.cpp
      bison1.yy/<bison.prefix>pre1
      bison2.yy/<bison.prefix>pre2
    : <define>SOME_MACRO
     <include>some/path ;

The feature never makes it to the bison generator rule. One would expect this
to work as for example
    other_lib/<link>static
correctly builds and uses a static version of "other_lib".

2)

alias bison1
    : bison1.yy
    : <bison.prefix>pre1 ;

alias bison2
    : bison2.yy
    : <bison.prefix>pre2 ;

lib foo
    : somefile.cpp
      bison1
      bison2
    : <define>SOME_MACRO
     <include>some/path ;

Like above the feature never makes it to the bison generator rule.

I would imagine the problem in both cases is that neither bison1.yy nor
bison1.cpp are real targets. But it's the lib target that first collects all
its sources and then triggers the bison generator on the yy files from within
its own context. (which doesn't know anything of <bison.prefix>pre1).

So what is basically needed is a way to explicitly generate the cpp file as a
separate target.

Something like this would be nice:

#like obj rule, but resulting target is a CPP file
cpp bison1
   : bison1.yy
   : <bison.prefix>pre1 ;

cpp bison2
   : bison2.yy
   : <bison.prefix>pre2 ;

lib foo
    : somefile.cpp
      bison1
      bison2
    : <define>SOME_MACRO
     <include>some/path ;

Like with the obj rule, you wouldn't specify the file suffix. That way such a
target is not confused with a normal cpp-file.

Even better would probably be a more general rule "gen" that applies the
appropriate generator to its sources and yields the corresponding results.

So my questions are:

* Does anyone know a more elegant solution to this problem I completely
overlooked?

* Would anybody else like to see such a rule in boost-build?

* Could someone hint me how to create one myself?
I know of the "generate" rule. But it depends on a custom written generating
rule. That rule would have to apply the appropriate generator for each source.
But how does it know which generator for which file type?

Thanks
Moritz

Geschaeftsfuehrer: Dipl.-Inform. Christopher Asp
Amtsgericht Mannheim HRB 105845


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk