Boost logo

Boost-Build :

Subject: Re: [Boost-build] Capture external program output using a Boost.Jam variable
From: Vladimir Prus (ghost_at_[hidden])
Date: 2008-12-01 14:52:41


On Monday 01 December 2008 15:49:20 Daniel Lidström wrote:
> Hello,

Hi Daniel,

> here's what I'm trying to do:
>
> gcc /DGR_BUILD_TIME=1228135248 ...
>
> GR_BUILD_TIME is the output of date +%s. I read the manual and tried this:
>
> local GR_BUILD_TIME = [ SHELL "date +%s" ] ;

> Now, GR_BUILD_TIME is passed to gcc but it contains a trailing newline,

As it happens, this 'date' command actually prints a trailing newline.

> How can I accomplish this? I'm using Milestone12 with Boost.Jam Version
> 3.1.13. OS=LINUX.

I'm afraid you get to strip newline. E.g.:

        ECHO "X:" ;
        local x = [ SHELL "date +%s" ] ;
        ECHO $(x) ;
        ECHO "Y:" ;
        local y = [ MATCH "(.*)[\n]" : $(x) ] ;
        ECHO $(y) ;
        ECHO "end" ;

produces the following output for me:

X:
1228161017

Y:
1228161017
end

Note that you need Boost.Jam 3.1.17 for this. In prior version, things
get a bit trickier:

nl = "
";

ECHO "X:" ;
local x = [ SHELL "date +%s" ] ;
ECHO $(x) ;
ECHO "Y:" ;
local y = [ MATCH "(.*)[$(nl)]" : $(x) ] ;
ECHO $(y) ;
ECHO "end" ;

Let me know if this helps. Maybe, we should modify 'SHELL' to (optionally)
strip the last trailing whitspace?

- 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