0

I have a small Jamfile that I process with Boost Build that looks like this:

exe add-account    : add-account.cpp    ..//server-lib ../../shared//shared ;
exe add-deck       : add-deck.cpp       ..//server-lib ../../shared//shared ;
exe give-all-cards : give-all-cards.cpp ..//server-lib ../../shared//shared ;
exe give-card      : give-card.cpp      ..//server-lib ../../shared//shared ;

install . :
    add-account
    add-deck
    give-all-cards
    give-card
;

I feel like I should be able to do this with some sort of template. I've been looking around in the Boost Build user manual, but haven't found a language rule that will help me.

It's probably worth mentioning that I'm aware that more code is probably not the best solution here, but I'm still interested in if it can be done. It would at least be useful in cases where I want to compile an entire directory filled with single source-file programs.

vmrob
  • 2,966
  • 29
  • 40

1 Answers1

2

There are several ways to make this more concise. Just for illustration:

local exe-list = add-account add-deck give-all-cards give-card ;
for exe-file in $(exe-list)
{
    exe $(exe-file) : $(exe-file).cpp ..//server-lib ../../shared//shared ;
}

install . : $(exe-list) ;

You can also create a helper rule.

rule simple-exe ( name )
{
    exe $(name) : $(name).cpp ..//server-lib ../../shared//shared ;
}

local exe-list = add-account add-deck give-all-cards give-card ;
for exe-file in $(exe-list)
{
    simple-exe $(exe-file) ;
}

install . : $(exe-list) ;

Additionally - if same library dependencies are often used, they can be put into an alias

alias common : ..//server-lib ../../shared//shared ;

exe add-account    : add-account.cpp    common ;
exe add-deck       : add-deck.cpp       common ;
exe give-all-cards : give-all-cards.cpp common ;
exe give-card      : give-card.cpp      common ;

or in project requirements

project my-project : requirements
    <library>..//server-lib
    <library../../shared//shared
;

exe add-account    : add-account.cpp    ;
exe add-deck       : add-deck.cpp       ;
exe give-all-cards : give-all-cards.cpp ;
exe give-card      : give-card.cpp      ;

Some combination of these techniques should do the trick.

Juraj Ivančić
  • 727
  • 5
  • 8
  • Thanks for those examples! I have a really hard time with the documentation from b2 on occasion. I think I'll be able to simplify other aspects of my build files with those as well. Do you know if there's a way to do a `[ glob *.cpp ]` but return the list without the .cpp? That would simplify the first example further. – vmrob May 18 '14 at 19:15
  • 1
    You can use MATCH builtin rule. rule remove_ext ( file ) { return [ MATCH (.*)\\.[^.]* : $(file) ] ; } – Juraj Ivančić May 19 '14 at 08:09