|
Boost-Build : |
From: Jurko GospodnetiÄ (jurko.gospodnetic_at_[hidden])
Date: 2008-07-22 09:20:17
Hi Jonathan.
> I want to select a source file based on the value of <target-os>, but it
> seems rather unsatisfying to have to write an alias rule for each os I
> support.
>
> I've figured out that I can do this:
>
> os-names = [ modules.peek builtin : .os-names ] ;
>
> for local os in $(os-name)
> {
> alias target-os-source : foo-$(os).cpp : <target-os>$(os) ;
> }
>
> which saves some typing or cut & paste errors, but that's still rather
> unsatisfying.
>
> Seems to me there ought to be a better way, but I haven't found one yet.
>
Well your solution seems quick good to me :-) and could be trimmed
down to (also avoids a typo in the original example):
> for local os in [ modules.peek builtin : .os-names ]
> {
> alias target-os-source : foo-$(os).cpp : <target-os>$(os) ;
> }
But IME most often you do not have the same files on different OS's
and then it is more useful to actually have a separate alias alternative
for each OS.
There is also the option of providing the source file names lazily
using indirect conditional requirements (see
http://www.boost.org/doc/tools/build/doc/html/bbv2/advanced/targets.html#bbv2.advanced.targets.requirements)
and the <source> property. Something like (warning: untested code):
> rule add-os-specific-sources ( properties * )
> {
> local target-os = [ MATCH "^<target-os>(.*)$" : $(properties) ] ;
> return
> $(target-os)-specific-source-1
> $(target-os)-specific-source-2
> $(target-os)-specific-source-3
> $(target-os)-specific-source-4
> $(target-os)-specific-source-5 ;
> }
>
> exe my-exe
> :
> some-fixed-source-1
> some-fixed-source-2
> some-fixed-source-3
> :
> <conditional>@add-os-specific-sources ;
I guess what you would really like would be something like:
exe my-exe
:
some-fixed-source-1
some-fixed-source-2
some-fixed-source-3
{target-os}-specific-source-1
{target-os}-specific-source-2
{target-os}-specific-source-3
{target-os}-specific-source-4
{target-os}-specific-source-5 ;
and have Boost Build dynamically construct the source file names fotr
you, but I don't think that is possible with the current Boost Build.
But if you can define a clear and robust syntax for achieving this
effect feel free to suggest it on the list.
Hope this helps.
Best regards,
Jurko GospodnetiÄ
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