views:

172

answers:

1

After many years of using make, I've just started using jam (actually ftjam) for my projects.

In my project workspaces, I have two directories:

  • src where I build executables and libraries
  • test where my test programs are

I'm trying to set up a dependency on test programs so that each time I compile them, the libraries will be recompiled as well (if they need to).

Any suggestion on how to do it?

+1  A: 

Ok this seems to be not an as easy question as I thought so I worked out a solution on my own. It uses a script to achieve the end result so I still hope that a Jam guru will have a jam-only solution.

  • Create a Jamrules in the root directory of the project with the common definitions.

  • Create a Jamfile in the root directory of the project with the following content:


    SubDir . ;
    SubInclude . src ;
    SubInclude . test ;

  • Create a Jamfile in the src directory

    SubDir .. src ;
    Library mylib : mylib.c ; 

  • Create a Jamfile in the test directory

    SubDir .. test ;
    Main mytest : mytest.c ; 
    Depends mytest :  mylib$(SUFLIB) ;

With this setting, as long as I am in the root directory, whenever I try to build mytest the library will also be recompiled (if needed). I found an old message on the jammer mailing list describing it.

Alas this doesn't work if I'm in the test subdirectory since jam can only look down into subdirectories.

So, I created a simple script called jmk and put it together with the jam executable (so that both are in the path):

if [ "$JMKROOT" = "" ] ; then
   JMKROOT=`pwd`
   export JMKROOT
fi
cd $JMKROOT
jam $*

and I set the JMKROOT environment variable to the root of my project.

For when I compile in a Windows shell (that's why I want to use Jam) I simply use this small jmk.bat batch file:

@echo off
if "%JMKROOT%" EQU "" set JMKROOT=%CD%

set OLDCD=%CD%
cd %JMKROOT%
jam %1 %2 %3 %4 %5 %6 %7 %8 %9

cd %OLDCD%
Remo.D