I have a C++ project that compiles to different versions, including release, debug, shared library, and executable, with different compiler flags for each. I am trying out Jam as an alternative to Make, because it looks like a simpler system.
Is Jam capable of this? The main problem is that it always places the .o files into the same folder as the source file, so it overwrites them when building multiple versions.
I found a solution that seems to work. Using this file, I can build debug and release configurations of a library or executable.
Command to build release library:
jam -s config=lib -s release=1
If you only type jam
, it builds the debug executable. Here is the Jamfile:
FILES =
main.cpp
;
BASENAME = steve ;
OBJ = obj ;
if $(release)
{
OBJ = $(OBJ)r ;
}
else
{
DEFINES += DEBUG ;
OBJ = $(OBJ)d ;
}
if $(config) = lib
{
OBJ = $(OBJ)_lib ;
OUTFILE = lib$(BASENAME).so ;
DEFINES += SHARED_LIBRARY ;
LINKFLAGS +=
-shared -Wl,-soname,$(OUTFILE) -fvisibility=hidden -fPICS
;
}
else
{
OUTFILE = $(BASENAME) ;
}
LOCATE_TARGET = $(OBJ) ;
MkDir $(LOCATE_TARGET) ;
Main $(OUTFILE) : $(FILES) ;
I'm not familiar with Perforce's Jam however bjam allows this - and it's trivially easy. bjam
does not place the intermediate files in the same directory as the source; it creates debug/release/static/shared directories depending on the type of project you're building.
For example if you wanted to build release and debug version of a library and you wanted to build it statically:
bjam debug release link=static
bjam
does have some quirks but we've found it very effective. Currently we're using (almost) identical build scripts to build our system using msvc (8.0 and 9.0), gcc 4.3 on x86, gcc 3.4 on ARM and gcc 4.3 for the PowerPC. Very nice.