JCons is a Make replacement, i.e. a program for building other programs. JCons is designed to build C/C++ programs, but any files that are produced in a well defined manner can be created under the control of JCons. As can be guessed from the name, JCons’ main inspiration is Cons, the make tool written in Perl (described in the Spring 1998 issue of “The Perl Journal”). To my knowledge Cons was the first make tool to combine a number of interesting ideas:
JCons tries to steal most of the good ideas of Cons. But there are important differences too, for example:
The ideas pioneered by Cons are not so special today over fifteen years later. A number of similar tools exist, most notably SCons (also inspired by Cons). Compared to SCons, JCons is quite minimalistic and lacks many features.
So why develop JCons? First, because it was fun. Writing a make tool seems quite easy in the beginning. But to get a reliable, fast and useful tool requires attention to many small details. This has been an interesting challenge. Second, because I believe JCons does some things better than both Cons and SCons. JCons is for example much faster than both Cons and SCons.
The rest of this document tries to describe how to use JCons. First a simple example will be given to illustrate the overall way JCons works. Then a guide to the different JCons features follows. And finally a reference part will describe all the details.
If you have used Cons before, you should recognize many things. The biggest difference from Cons is of course that JCons uses Python as scripting language instead of Perl.
The examples in the text have actually been executed as real commands. This should ensure that they stay correct at all times.
A minimal example of using JCons is given below:
# construct.py
e = Cons()
e.command("readme.pdf", "readme.ps", "ps2pdf %INPUT %OUTPUT")
e.command("readme.ps", "readme.txt", "enscript -q %INPUT -o %OUTPUT")
The calls to Cons.command() tells JCons how the output files can be produced from the input files:
$ echo a line of text > readme.txt # create source file
$ jcons
enscript -q readme.txt -o readme.ps
ps2pdf readme.ps readme.pdf
$ jcons # nothing to do 2nd time
jcons: up-to-date: .
$ echo one more line >> readme.txt
$ jcons # input file has changed
enscript -q readme.txt -o readme.ps
ps2pdf readme.ps readme.pdf
All methods of the Cons class are of this type. Each method is useful in a different situation: program to build a program, static_library to create a library, etc. But all methods could in principle have been implemented on top of the command method.