Boost logo

Boost-Build :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-07-08 02:51:41


Hi Thomas,

> I'm having a hard time trying to do a very simple build rule. I've been
> evaluating boost.jam for a few days now and like it a lot. However,
> documentation and examples are very terse and I haven't found any explicit
> examples of what I'm trying to do.

I'd suggest that you always start with a generator when you need a new tool,
like described in

http://zigzag.lvk.cs.msu.su/~ghost/Boost.Build.docs/bbv2.extender.html#bbv2.extender.intro

> I then try to create a rule to generate the lexer.cpp and parser.cpp:
>
> rule antlr ( lexer parser : grammar )
> {
> Depends $(lexer) $(parser) : $(grammar) ;
> }

It looks like you come with Classic Jam background, no? In V2, user never has
to write explicit Depends.

> actions antlr
> {
> java -cp antlr/antlr-2.7.3/antlr.jar antlr.Tool -o src/antlr $(<)
> }
>
> # apply the antlr rule to lexer.cpp and parser.cpp
> antlr src/antlr/lexer.cpp src/antlr/parser.cpp : antlr/csl.g ;

Here's the problem. This invocation creates Jam target called src/antlr

> The generated cpp files belong in a library.
>
> lib mylib
>
> : src/antlr/lexer.cpp
>
> src/antlr/parser.cpp

But this creates Boost.Build target "mylib". To clarify things, I might even
say "Boost.Build metatarget", because depending on build properties,
different Jam targets will be created. The sources should also be Boost.Build
targets, but you try to pass ordinary Jam target as source, and that does not
work.

> I tried making a generator but it is not suitable for what I want. Even if
> the generator could generate two files

It sure can:

generators.register-standard verbatim.inline-file
: VERBATIM : CPP(%_parser) CPP(%_lexer) ;

> I need the generated files to placed
> in src/antlr not in the build-dir tree.

Why is it needed for you? If you place then to build-dir, Boost.Build will
have no problems picking them up. Even if you really need to place them
elsewhere, we can arrange this using generators.

To help you get started with generators, I attach a toolset file for Whale, a
parser generator that I use. Hope this helps.

- Volodya
 --Boundary-00=_N0P7A48dKTa1oUy Content-Type: text/plain;
charset="koi8-r";
name="whale.jam"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="whale.jam"

# Copyright (C) Vladimir Prus 2002. Permission to copy, use, modify, sell and
# distribute this software is granted provided this copyright notice appears in
# all copies. This software is provided "as is" without express or implied
# warranty, and with no claim as to its suitability for any purpose.

# Support for Whale/Dolphin/WD parser/lexer tools.

import type ;
import generators ;
import path ;

rule init ( path # path the Whale/Dolphin/WD binaries
)
{
if $(.configured)
{
errors.error "Attempt to reconfigure Whale support" ;
}
.configured = true ;

.whale = [ path.join $(path) whale ] ;
.dolphin = [ path.join $(path) dolphin ] ;
.wd = [ path.join $(path) wd ] ;
}

type.register WHL : whl ;
type.register DLP : dlp ;
type.register WHL_LR0 : lr0 ;
type.register WD : wd ;

generators.register-standard whale.whale : WHL : CPP H H(%_symbols) WHL_LR0 ;
generators.register-standard whale.dolphin : DLP : CPP H ;
generators.register-standard whale.wd : WD : WHL(%_parser) DLP(%_lexer) ;

rule whale ( targets * : sources * : properties * )
{
}

actions whale
{
$(.whale) -d $(<[1]:D) $(>)
}

rule dolphin ( targets * : source * : properties * )
{
}

actions dolphin
{
$(.dolphin) -d $(<[1]:D) $(>)
}

rule wd ( targets * : source * : properties * )
{
}

actions wd
{
$(.wd) -d $(<[1]:D) -g $(>)
}

 --Boundary-00=_N0P7A48dKTa1oUy--


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