&SCons; provides the ability to build a lot of different
types of files right "out of the box."
So far, we've been using &SCons;' ability to build
programs, objects and libraries to
illustrate much of the underlying functionality of &SCons;
This section will describe all of the different
types of files that you can build with &SCons;,
and the built-in &Builder; objects used to build them.
Programs: the &Program; Builder
As we've seen, the &Program; Builder
is used to build an executable program.
The &source; argument is one or more
source-code files or object files,
and the ⌖ argument is the
name of the executable program name to be created.
For example:
env = Environment()
env.Program('prog', 'file1.o')
Will create the &prog;
executable on a POSIX system,
the &prog_exe; executable on a Windows system.
The target file's prefix and suffix may be omitted,
and the values from the
$PROGPREFIX
and
$PROGSUFFIX
construction variables
will be appended appropriately.
For example:
env = Environment(PROGPREFIX='my', PROGSUFFIX='.xxx')
env.Program('prog', ['file1.o', 'file2.o'])
Will create a program named
myprog.xxx
regardless of the system on which it is run.
If you omit the ⌖,
the base of the first input
file name specified
because the base of the target
program created.
For example:
env = Environment()
env.Program(['hello.c', 'goodbye.c'])
Will create the &hello;
executable on a POSIX system,
the &hello_exe; executable on a Windows system.
Object-File Builders
&SCons; provides separate Builder objects
to create both static and shared object files.
The &StaticObject; Builder
XXX
XXX
XXX
The &SharedObject; Builder
XXX
XXX
XXX
The &Object; Builder
XXX
XXX
Creates a static object file.
Library Builders
&SCons; provides separate Builder objects
to create both static and shared libraries.
The &StaticLibrary; Builder
XXX
XXX
XXX
The &SharedLibrary; Builder
XXX
The &Library; Builder
XXX
XXX
XXX
Creates a static library file.
Pre-Compiled Headers: the &PCH; Builder
XXX
Microsoft Visual C++ Resource Files: the &RES; Builder
XXX
Source Files
By default
&SCons; supports two Builder objects
that know how to build source files
from other input files.
The &CFile; Builder
XXX
XXX
XXX
The &CXXFile; Builder
XXX
XXX
XXX
Documents
&SCons; provides a number of Builder objects
for creating different types of documents.
The &DVI; Builder
XXX
XXX
XXX
The &PDF; Builder
XXX
The &PostScript; Builder
XXX
XXX
XXX
Archives
&SCons; provides Builder objects
for creating two different types of archive files.
The &Tar; Builder
The &Tar; Builder object uses the &tar;
utility to create archives of files
and/or directory trees:
env = Environment()
env.Tar('out1.tar', ['file1', 'file2'])
env.Tar('out2', 'directory')
% scons .
tar -c -f out1.tar file1 file2
tar -c -f out2.tar directory
One common requirement when creating a &tar; archive
is to create a compressed archive using the
option.
This is easily handled by specifying
the value of the &TARFLAGS; variable
when you create the construction environment.
Note, however, that the used to
to instruct &tar; to create the archive
is part of the default value of &TARFLAGS;,
so you need to set it both options:
env = Environment(TARFLAGS = '-c -z')
env.Tar('out.tar.gz', 'directory')
% scons .
tar -c -z -f out.tar.gz directory
you may also wish to set the value of the
&TARSUFFIX; construction variable
to your desired suffix for compress &tar; archives,
so that &SCons; can append it to the target file name
without your having to specify it explicitly:
env = Environment(TARFLAGS = '-c -z',
TARSUFFIX = '.tgz')
env.Tar('out', 'directory')
% scons .
tar -c -z -f out.tgz directory
The &Zip; Builder
The &Zip; Builder object creates archives of files
and/or directory trees in the ZIP file format.
Python versions 1.6 or later
contain an internal &zipfile; module
that &SCons; will use.
In this case, given the following
&SConstruct; file:
env = Environment()
env.Zip('out', ['file1', 'file2'])
Your output will reflect the fact
that an internal Python function
is being used to create the output ZIP archive:
% scons .
zip("out.zip", ["file1", "file2"])
If you're using Python version 1.5.2 to run &SCons;,
then &SCons; will try to use an external
&zip; program as follows:
% scons .
zip /home/my/project/zip.out file1 file2
Java
&SCons; provides Builder objects
for creating various types of Java output files.
Building Class Files: the &Java; Builder
The &Java; builder takes one or more input
.java files
and turns them into one or more
.class files
Unlike most builders, however,
the &Java; builder takes
target and source directories,
not files, as input.
env = Environment()
env.Java(target = 'classes', source = 'src')
The &Java; builder will then
search the specified source directory
tree for all .java files,
and pass any out-of-date
XXX
The &Jar; Builder
The &Jar; builder object XXX
env = Environment()
env.Java(target = 'classes', source = 'src')
env.Jar(target = '', source = 'classes')
XXX
Building C header and stub files: the &JavaH; Builder
XXX
XXX
XXX
Building RMI stub and skeleton class files: the &RMIC; Builder
XXX
XXX
XXX