As mentioned previously,
&SCons; will build every target
in or below the current directory
by default--that is, when you don't
explicitly specify one or more targets
on the command line.
Sometimes, however, you may want
to specify explicitly that only
certain programs should be built by default.
You do this with the &Default; function:
env = Environment()
hello = env.Program('hello.c')
env.Program('goodbye.c')
Default(hello)
This &SConstruct; file knows how to build two programs,
&hello; and &goodbye;,
but only builds the
&hello program by default:
% scons
cc -c hello.c -o hello.o
cc -o hello hello.o
% scons
% scons goodbye
cc -c goodbye.c -o goodbye.o
cc -o goodbye goodbye.o
%
Note that, even when you use the &Default;
function in your &SConstruct; file,
you can still explicitly specify the current directory
(.) on the command line
to tell &SCons; to build
everything in (or below) the current directory:
% scons .
cc -c goodbye.c -o goodbye.o
cc -o goodbye goodbye.o
cc -c hello.c -o hello.o
cc -o hello hello.o
%
You can also call the &Default;
function more than once,
in which case each call
adds to the list of targets to be built by default:
env = Environment()
prog1 = env.Program('prog1.c')
Default(prog1)
prog2 = env.Program('prog2.c')
prog3 = env.Program('prog3.c')
Default(prog3)
Or you can specify more than one target
in a single call to the &Default; function:
env = Environment()
prog1 = env.Program('prog1.c')
prog2 = env.Program('prog2.c')
prog3 = env.Program('prog3.c')
Default(prog1, prog3)
Either of these last two examples
will build only the
prog1
and
prog3
programs by default:
% scons
cc -c prog1.c -o prog1.o
cc -o prog1 prog1.o
cc -c prog3.c -o prog3.o
cc -o prog3 prog3.o
% scons .
cc -c prog2.c -o prog2.o
cc -o prog2 prog2.o
%
Lastly, if for some reason you don't want
any targets built by default,
you can use the Python None
variable:
env = Environment()
prog1 = env.Program('prog1.c')
prog2 = env.Program('prog2.c')
Default(None)
Which would produce build output like:
% scons
scons: *** No targets specified and no Default() targets found. Stop.
% scons .
cc -c prog1.c -o prog1.o
cc -o prog1 prog1.o
cc -c prog2.c -o prog2.o
cc -o prog2 prog2.o
%