2

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?

Remo.D
  • 15,217
  • 5
  • 41
  • 70

2 Answers2

2

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
  • 15,217
  • 5
  • 41
  • 70
0

I'm using Jam in one of my projects, and I am encountering your very situation. I have my executable programs in the bin subdirectory, and my static libraries are kept in the lib subdirectory.

In my top-level Jamfile, I type in SubDir TOP ;. This initializes the $(TOP) variable to point to the directory containing this Jamfile. I then add lines such as SubInclude TOP bin llvm-tblgen and SubInclude TOP lib Support, which adds the contents of the Jamfiles in bin/llvm-tblgen and lib/Support to the build.

In the Jamfile in bin/llvm-tblgen, I type in SubDir TOP bin llvm-tblgen ;. I do the same in the Jamfile in lib/Support, but I use SubDir TOP lib Support ; instead. The key when entering SubDir rules is to type in the names of each subdirectory from the TOP to the directory containing this Jamfile.

Then, when it is time to set the linkline of my executable target, I reference the support library like this: $(TOP)/lib/Support/libLLVMSupport.a. Jam expands this path into the location of libLLVMSupport.a, relative to where I run Jam, even if I cd into the bin/llvm-tblgen directory and run Jam manually from there.

This makes it very easy to manage large projects that contain cross-directory dependencies. This solution, unlike your earlier one, lets you run Jam directly. Hope it helps you!

wjk
  • 1,077
  • 7
  • 21