You may want to control various aspects
of your build by allowing the user
values on the command line.
For example, suppose you
want users to be able to
build a debug version of a program
by running SCons as follows:
% scons -Q debug=1
SCons provides an
that stores all of the
assignments from the command line.
This allows you to modify
aspects of your build in response
to specifications on the command line.
(Note that unless you want to require
that users always
specify an option,
you probably want to use
which allows you to specify a default value
to be used if there is no specification
on the command line.)
The following code sets the
variable in response to the
flag being set in the
env = Environment() debug = ARGUMENTS.get('debug', 0) if int(debug): env.Append(CCFLAGS = '-g') env.Program('prog.c')
This results in the
compiler option being used when
is used on the command line:
% scons -Q debug=0 cc -o prog.o -c prog.c cc -o prog prog.o % scons -Q debug=0 scons: `.' is up to date. % scons -Q debug=1 cc -o prog.o -c -g prog.c cc -o prog prog.o % scons -Q debug=1 scons: `.' is up to date.
Notice that SCons keeps track of the last values used to build the object files, and as a result correctly rebuilds the object and executable files only when the value of the debug argument has changed.