SCons supports a COMMAND_LINE_TARGETS variable
that lets you fetch the list of targets that the
user specified on the command line.
You can use the targets to manipulate the
build in any way you wish.
As a simple example,
suppose that you want to print a reminder
to the user whenever a specific program is built.
You can do this by checking for the
target in the COMMAND_LINE_TARGETS list:

if 'bar' in COMMAND_LINE_TARGETS:
print "Don't forget to copy `bar' to the archive!"
Default(Program('foo.c'))
Program('bar.c')

Then, running SCons with the default target
works as it always does,
but explicity specifying the bar target
on the command line generates the warning message:

One of the most basic things you can control
is which targets SCons will build by default--that is,
when there are no targets specified on the command line.
As mentioned previously,
SCons will normally 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, or programs in certain directories,
should be built by default.
You do this with the Default function:

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 supports a DEFAULT_TARGETS variable
that lets you get at the current list of default targets.
The DEFAULT_TARGETS variable has
two important differences from the COMMAND_LINE_TARGETS variable.
First, the DEFAULT_TARGETS variable is a list of
internal SCons nodes,
so you need to convert the list elements to strings
if you want to print them or look for a specific target name.
Fortunately, you can do this easily
by using the Python map function
to run the list through str:

(Keep in mind that all of the manipulation of the
DEFAULT_TARGETS list takes place during the
first phase when SCons is reading up the SConscript files,
which is obvious if
we leave off the -Q flag when we run SCons:)

In practice, this simply means that you
need to pay attention to the order in
which you call the Default function
and refer to the DEFAULT_TARGETS list,
to make sure that you don't examine the
list before you've added the default targets
you expect to find in it.

We've already been introduced to the
COMMAND_LINE_TARGETS variable,
which contains a list of targets specified on the command line,
and the DEFAULT_TARGETS variable,
which contains a list of targets specified
via calls to the Default method or function.
Sometimes, however,
you want a list of whatever targets
SCons will try to build,
regardless of whether the targets came from the
command line or a Default call.
You could code this up by hand, as follows:

SCons, however, provides a convenient
BUILD_TARGETS variable
that eliminates the need for this by-hand manipulation.
Essentially, the BUILD_TARGETS variable
contains a list of the command-line targets,
if any were specified,
and if no command-line targets were specified,
it contains a list of the targets specified
via the Default method or function.

Because BUILD_TARGETS may contain a list of SCons nodes,
you must convert the list elements to strings
if you want to print them or look for a specific target name,
just like the DEFAULT_TARGETS list: