Boost logo

Boost-Build :

Subject: Re: [Boost-build] Generated header files.
From: Vladimir Prus (ghost_at_[hidden])
Date: 2008-12-04 04:04:39


On Thursday 04 December 2008 11:34:42 Mathias Lorente wrote:
> Vladimir Prus wrote:
> > On Wednesday 03 December 2008 19:09:16 Mathias Lorente wrote:
> >
> >> Vladimir Prus wrote:
> >>
> >>> On Wednesday 03 December 2008 17:36:05 Mathias Lorente wrote:
> >>>
> >>>
> >>>> Dear list,
> >>>>
> >>>> I use bjam to build a library which relies on some generated header files.
> >>>> These files are generated by a specific application which is also built
> >>>> using bjam.
> >>>> I added a dependency for my library so that the application is built
> >>>> before the library.
> >>>> But:
> >>>> - I didn't manage to launch the application in order to generate the
> >>>> necessary header files before the library is being built.
> >>>>
> >>>>
> >>> Hi Mathias,
> >>>
> >>> it's generally best to show what approaches you've tried, so that you
> >>> get help about your specific issue, not some approximation. Generally,
> >>> something like this should work:
> >>>
> >>>
> >>> exe header_generator : header_generator.cpp ;
> >>> make header.h : header_generator : @generate-header ;
> >>> actions generate-header
> >>> {
> >>> $(>) > $(<)
> >>> }
> >>> lib header_user : header_user.cpp : <implicit-dependency>header.h ;
> >>>
> >>> - Volodya
> >>>
> >>>
> >> Hello Volodya,
> >>
> >> Thanks for your reply.
> >> In fact my 'header generator' uses input files (let's say .txt) which
> >> are parsed/modified/... to make the corresponding .h files.
> >> Until now, I was launching the generator by hand and it was working on
> >> all files in the specified directory (as command line parameter).
> >> I suppose I would have to modify it in order to make it take one file at
> >> a time.
> >>
> >
> > For dependency tracking, it's best if each invocation takes specific input
> > and produces a single file. Otherwise, Boost.Build or you would have to run
> > your tool on all files. Here's how to modify my code to make it accept a source:
> >
> > make header.h : header_generator input.txt : @generate-header ;
> > actions generate-header
> > {
> > $(>[1]) $(>[2]) > $(<)
> > }
> >
> I have modified my header generator which takes one input file and
> writes the corresponding header file in the same directory as the input
> file. So I have the following bjam script:
>
> make header.h
> : ../utils//gen header.txt
> : @generate-header
> ;
>
> actions generate-header
> {
> $(>[1]) $(>[2])
> }
>
> But this solution does not meet some requirements:
> - Each time I launch bjam, the header generator is launched even if
> header.txt has not been modified.

This means that your tool generates header not where Boost.Build wants
it to be -- which I've mentioned in the previous email.
Add

        echo $(<)

to your actions. This will print the location where the header *should* be generated.
And then check if that location actually has the file. If you want the file to
be located somewhere else, use:

     make header.h
       : ../utils//gen header.txt
       : @generate-header
       : <location>somewhere
       ;

> - My library (which relies on generated header) is rebuilt only the
> second time I launch bjam: first time, headers are generated, second
> time, headers are generated and the library is rebuilt. I suspect that
> bjam checks the timestamp of the header files before they are generated
> again...
> Here is the definition to build my library:
>
> lib my_lib
> : [ glob-tree *.cpp : .svn ]
> : <link>static
> <define>BUILDING_LIBRARY
> <variant>debug:<define>ENABLE_DEBUG_LOG
> ;

This lacks <implicit-dependency> -- which I've mentioned previously as well.
You can read about that in the docs:

        http://www.boost.org/boost-build2/doc/html/bbv2/reference/generated_headers.html

- Volodya


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