If you're used to build systems like Make
you've already figured out that the
is the SCons equivalent of a
That is, the
SConstruct file is the input file
that SCons reads to control the build.
There is, however, an important difference between
SConstruct file and a
SConstruct file is actually a Python script.
If you're not already familiar with Python, don't worry.
This User's Guide will introduce you step-by-step
to the relatively small amount of Python you'll
need to know to be able to use SCons effectively.
And Python is very easy to learn.
One aspect of using Python as the
scripting language is that you can put comments
SConstruct file using Python's commenting convention;
that is, everything between a '#' and the end of the line
will be ignored:
# Arrange to build the "hello" program. Program('hello.c') # "hello.c" is the source file.
You'll see throughout the remainder of this Guide that being able to use the power of a real scripting language can greatly simplify the solutions to complex requirements of real-world builds.
One important way in which the
file is not exactly like a normal Python script,
and is more like a
is that the order in which
the SCons functions are called in
affect the order in which SCons
actually builds the programs and object files
you want it to build.
In other words, when you call the
(or any other builder method),
you're not telling SCons to build
the program at the instant the builder method is called.
Instead, you're telling SCons to build the program
that you want, for example,
a program built from a file named
and it's up to SCons to build that program
(and any other files) whenever it's necessary.
(We'll learn more about how
SCons decides when building or rebuilding a file
is necessary in Chapter 6, Dependencies, below.)
SCons reflects this distinction between
calling a builder method like
and actually building the program
by printing the status messages that indicate
when it's "just reading" the
and when it's actually building the target files.
This is to make it clear when SCons is
executing the Python statements that make up the
and when SCons is actually executing the
commands or other actions to
build the necessary files.
Let's clarify this with an example.
Python has a
Program builder method:
print "Calling Program('hello.c')" Program('hello.c') print "Calling Program('goodbye.c')" Program('goodbye.c') print "Finished calling Program()"
Then when we execute SCons,
we see the output from the
indicating that that is when the
Python statements are being executed:
sconsscons: Reading SConscript files ... Calling Program('hello.c') Calling Program('goodbye.c') Finished calling Program() scons: done reading SConscript files. scons: Building targets ... cc -o goodbye.o -c goodbye.c cc -o goodbye goodbye.o cc -o hello.o -c hello.c cc -o hello hello.o scons: done building targets.
Notice also that SCons built the
goodbye program first,
even though the "reading
shows that we called
first in the
 In programming parlance,
SConstruct file is
meaning you tell SCons what you want done
and let it figure out the order in which to do it,
rather than strictly imperative,
where you specify explicitly the order in
which to do things.