[Scons-users] tutorial

Philipp Kraus philipp.kraus at flashpixx.de
Sun May 19 07:17:11 EDT 2013


Hi,

On 2013-05-19 04:30:05 +0200, Jitterman said:

> I am trying to learn to use Scons for the first time, but I am not using it

> for C or for Java. I am finding the existing documentation a bit frustrating

> because it all seems to assume that you are using some language such as C for

> which Scons already has built in support.


Yes your're right, a little more abstract / general / structured
documentation should be better



> What I need to a tutorial for how to build a program where it is not assumed

> that Scons already has all the rules it needs because I would like to

> understand

> how to add those rules.


I would like to explain you, some important thing. If there is no
buildin structure for your
compiling problem, you need to write it yourself.

Take a look to the SCons documentation, there are three names
"scanner", "builder", "emitter".
Try to understand these things. The short view to this is, each type is
a Python function, that is
called by SCons on different timesteps eg: the emitter is run before
the builder, and it describes
a connection between an input and an output file. In C, the emitter for
c files tells, that a c file creates a o file
after the builder call.
The builder is the "command" with is run to build something.
The Scanner is also in short words a large switch statements, which
filters a list of files (sources) to the correct emitter / builder,
so you can push a list eg ["file.c", "file.cpp"] and the Scanner push
these file to the correct builder (first file to c compiler, second to
cpp compiler).



> My particular situation is that I would like to use Scons to create and compile

> a cython version of an existing python program, where some of the python files

> are generated programatically. So I need to know how to write rules like:

> generatedFile1.py: sourceFile1.py

> python sourceFile1.py

> %.pyx: %.py

> ln -s $% $@

> %.c: %.pyx

> cython $%



You can do this compile steps with the quick-and-dirty method of the
env.Command call, but IMHO you can write our own builder.
My tip to create an own builder is, that you write down, which steps
are needed to compile a source to the target, so which steps
depends on which other steps. You should also describe the information
which file is transformed to a target, so take a look to
one source file only and think about which information can you get from
the this source file to know which target file is created by the builder
(you have created your scanner).

HTH


Phil




More information about the Scons-users mailing list