Jam build tool (转载)
Posted on September 7, 2014 by jeffreyzksun
Overview
Jam is a small open-source build tool that can be used as a replacement for Make. Its original Jam author is Perforce.
The main differences between Jam and Make are as follows.
- Jam uses ‘Jamfiles’ instead of ‘Makefiles’.
- Jamfiles do not normally contain toolset-specific rules or actions. They are thus portable among distinct compilers.
- Jamfiles are a lot simpler than Makefiles to write and understand, while providing the same functionality, and much, much more.
Language
Jam requires whitespace (blanks, tabs, or newlines) to surround all tokens, including the colon : and semicolon ; tokens. like rulename field1 : field2 : … : fieldN ;
Rule
It defines the dependency graph for targets.
Rule语法定义了构建目标的依赖关系。
It doesn’t specify the execution commands like actions does.
Rule语法不像actions语法,它不需要具体的执行指令。
There would be or not be an updating actions defined for it.
Rule语法可能有,也可能没有对应的updating actions语法。
updating actions
- Updating actions are the OS shell commands to execute when updating the built targets of the rule. [1]
When you call a rule, the commands of the corresponding actions block are added to every element of the rule’s first argument. At the updating stage, the commands are executed to update the target.- When an rule with updating actions is invoked, those actions are added to those associated with its built targets ($(1)) before the rule's procedure is run.
- Each target can record a set of commands to be sent to the shell. This is generally used to ‘build’ file targets like object files or executables.
- actions [ modifiers ] rulename
Example [3]
rule Compile
{
Depends $(1) : $(2) ;
}
actions Compile
{
gcc -o $(1) $(2)
}
Compile hello : hello.c ;
This script can compile the source file hello.c into the executable “hello”.
- When the
rule Compilestatement is parsed, Jam records the definition of theCompilerule, but doesn’t execute it. - When the
actions Compilestatement is parsed, Jam records the commands inside the curly braces as a single string, and associate them to theCompilerule. It doesn’t expand or execute them however. - When the
Compile hello : hello.c ;statement is parsed, Jam does two things: - first, and before anything else, it creates a
hellotarget in the dependency graph, then associates the action commands of the Compile rule to it, using the parameter valueshelloandhello.cfor$(1)and$(2), respectively. - then it executes the
Compilerule, whose Depends statement will create a hello.c target, then add a dependency from hello to hello.c
Note that at the end of the parsing, no commands will be sent to the command shell yet. Instead, we will have the following dependency graph built:

You will need to invoke jam hello to tell Jam to rebuild the ‘hello’ program when needed.
Reference
[1] https://swarm.workshop.perforce.com/view/guest/perforce_software/jam/src/Jam.html
[2] http://jamplus.org/git/jamplus/docs/html/jambase_rules.html#rule_FGristDirectories
[3] http://david.freetype.org/jam/jam-language-3.html

浙公网安备 33010602011771号