To start a build with default build options simply change to the project root directory and execute the jam binary (-q means stop on first error). The command below builds the project on Windows when executed in the 'build command shell':
jam.exe -q
Accordingly, on POSIX systems, a script named jam.sh can be used to build the jam executable first and then the project in one simple step. The script builds the jam binary the first time it is executed and passes on any command-line arguments. Th following is the equivalent to executing jam.exe on Windows:
./jam.sh -q
NOTE:
After a checkout the jam-script may needs to be made executable with the chmod command:
chmod +x ./jam.sh
jam.exe program.exe
Some important pseudo-targets are all, lib or exe. The target 'all' will build all targets in the dependency tree. 'lib' will build only libraries and 'exe' only exectuables, respectively. When jam is called without specifying any targets the pseudo-target 'all' is assumed. This is the same as explicitly calling jam to build the target 'all'. To build all libraries and their dependencies in a project, invoke jam like so:
jam.exe lib
jam.exe -a
A specific target can be rebuild by combining -a and a target name. The target program.exe will be completely rebuild with the following command:
jam.exe -a program.exe
jam.exe clean
-a Build target(s), even if they are current.
-dx Set the debug level to x
-jx Run up to x shell command concurrently
-n Don't actually execute, but show the updating actions.
-q Quit quickly as soon as a target fails.
-sx=y Set variable x=y, overriding environment.
One important jam variable is named CONFIG and can be set to 'debug' or 'release' to build either a debug or release version of a project. To build a release version of a project, use the following command:
jam.exe -sCONFIG=release
Most variables have default values or are deduced from environment variables. The default for CONFIG is 'debug'. The following table gives an overview which jam variables are used to enable certain build options:
Target Operating System (TARGET_OS): nt, linux, qnxnto, wince, macox, solarix, aix
Target Platform (TARGET_OSPLAT): x86, ppc, arm, mips, sh4, sparc
Configuration (CONFIG): debug, release
Compiler/Toolchain (TOOLSET): vc7, vc8, vc9, gcc, icpp, qcc, xlc, mingw
More than one variable can be set when jam is invoked. The following command builds a release version with the gnu compiler toolset on a POSIX host:
./jam.sh -sCONFIG=release -sTOOLSET=gcc
./jam.sh -sCONFIG=release
The default TOOLSET on a Unix host may not be gcc, but the compiler/linker of the respective vendor. For example, the default TOOLSET on AIX is the xlc compiler and the default TOOSET on Solaris is the Sun compiler. The Gnu compiler can be used on these systems by setting the TOOLSET to gcc explicitly.
jam.exe -sVISUALC="C:\Programme\Microsoft Visual Studio 2005" -sTOOLSET=vc8
If the special 'build command shell' is used, VISUALC is determined from other environment variables and does not have to be specified. Also, the TOOLSET is deduced from the environment and does not have to be specified. If the express version of Visual Studio 2005 is used, the path to the Platform SDK must be specified with -sPLATFORMSDK=C:⁄path⁄to⁄PlatformSDK. To build with VisualC++ 2003, set the TOOLSET to vc7. It is not possible to build vc7 targets from the 'build command shell' provided by a Microsoft visual studio 8 installation or vice versa.
jam.exe -sVISUALC="C:\Programme\Microsoft Visual Studio 8"
-sTOOLSET=vc8 -sTARGET_OS=wince -sTARGET_OSPLAT=arm
./jam.sh
QNX targets can be cross compiled or directly compiled on a QNX host. Cross compiling can be done on either a QNX host for another CPU or on a Windows NT/XP host. For cross compiling the TARGET_OS and TARGET_OSPLAT variables need to be set. The following command will build a project on a Windows NT/XP host for QNX systems with X86 processors.
jam.exe -sTARGET_OS=qnxnto -sTARGET_OSPLAT=x86
To cross compile for QNX on a QNX host the TARGET_OSPLAT needs to be set:
./jam.sh -sTARGET_OSPLAT=ppc
VAR = 5 ; Echo "The value is:" $(VAR) ;
The so called Jambase in the jam subdirectory and the rules taken from the file Jamrules can be used in the Jamfiles of the project to build targets. Rules can take multiple parameters which are separated by a colon. For Example the rule File, which copies files, can takes two parameters, the first is the target file, the second the source file:
File target.txt : source.txt ;
Note that the jam syntax requires all tokens to be whitespace-separated including the semicolon at the end of each line.
The SubDir rule must be the first rule invoked in a Jamfile. It specifies the path to the current directory and initializes a set of variables that are used by other rules to uniquely identify the source files and assign locations. The SubDir rule takes as its first argument the root variable's name and takes as subsequent parameters the directory names leading from the root to the directory of the current Jamfile. The following means that the Jamfile which contains the SubDir statement is in the the directory /src/util:
SubDir $(TOP) src util
The Jamfile in the project root directory therefore simply sets its directory to with the SubDir rule.
The SubInclude rule is used in a Jamfile to include another Jamfile and to build up the project directory tree this way. Its arguments are in the same format as SubDir's. The recommended practice is to include only one level of subdirectories at a time and let the Jamfile in each subdirectory include its own subdirectories. The following Jamfile includes four other Jamfiles:
SubInclude $(TOP) src SubInclude $(TOP) man SubInclude $(TOP) util SubInclude $(TOP) misc
SubDirHdrs $(TOP)/include ;
Main program : main.cpp ;
The first parameter passed to the rule is the target name, the second is the list of source files. All system specific target name decorations will be added by jam auomatically. So under windows the resulting binary will be called program.exe. Under unix it will simply be called 'program'.
Library example : example.cpp ;
The first parameter passed to the rule is the target name, the second is the list of source files. All system specific target name decorations will be added by jam auomatically. So under windows the resulting library will be called example.lib. Under unix it will be called libexample.a.
SharedLibrary example : example.cpp ;
The first parameter passed to the rule is the target name, the second is the list of source files. All system specific target name decorations will be added by jam auomatically. So under windows the resulting library will be called example.dll and a import library called example.lib will be created. Under unix, one shared library called libexample.so will be created.
Library example : example.cpp ; Main program : main.cpp ; Main_LinkLibraries program : example ;
The first parameter passed to the rule 'Main_LinkLibraries' is the name of the target the static libraries should be linked to, the second is the list of static libraries to link.
The rule Main_LinkSharedLibraries can be used to link a number of shared libraries to an executable. This example assumes that a library called example is build from a source file example.cpp and linked to a program called 'program', which is to be built from a source file called main.cpp. The Jamfile in this case looks like this:
SharedLibrary example : example.cpp ; Main program : main.cpp ; Main_LinkLibraries program : example ;
The first parameter passed to the rule 'Main_LinkSharedLibraries' is the name of the target the shared libraries should be linked to, the second is the list of shared libraries to link.
Library tire : tire.cpp ; SharedLibrary car : car.cpp ; SharedLibrary_LinkLibraries car : tire ;
The first parameter passed to the rule 'SharedLibrary_LinkLibraries' is the name of the shared library target the static libraries should be linked to, the second is the list of static libraries to link.
The rule SharedLibrary_LinkSharedLibraries can be used to link a number of shared libraries to another shared library. This example assumes that a shared library called tire is build from a source file tire.cpp and linked to a shared library called 'car', which is to be built from a source file called car.cpp. The Jamfile in this case looks like this:
SharedLibrary tire : tire.cpp ; SharedLibrary car : car.cpp ; SharedLibrary_LinkSharedLibraries car : tire ;
The first parameter passed to the rule 'SharedLibrary_LinkSharedLibraries' is the name of the target the shared libraries should be linked to, the second is the list of shared libraries to link.