Copying Construction Environments
Sometimes you want more than one construction environment
to share the same values for one or more variables.
Rather than always having to repeat all of the common
variables when you create each construction environment,
you can use the Copy method
to create a copy of a construction environment.
Like the Environment call that creates a construction environment,
the Copy method takes construction variable assignments,
which will override the values in the copied construction environment.
For example, suppose we want to use gcc
to create three versions of a program,
one optimized, one debug, and one with neither.
We could do this by creating a "base" construction environment
that sets CC to gcc,
and then creating two copies,
one which sets CCFLAGS for optimization
and the other which sets CCFLAGS for debugging:
env = Environment(CC = 'gcc')
opt = env.Copy(CCFLAGS = '-O2')
dbg = env.Copy(CCFLAGS = '-g')
env.Program('foo', 'foo.c')
o = opt.Object('foo-opt', 'foo.c')
opt.Program(o)
d = dbg.Object('foo-dbg', 'foo.c')
dbg.Program(d)
|
Then our output would look like:
% scons -Q
gcc -c -o foo.o foo.c
gcc -o foo foo.o
gcc -g -c -o foo-dbg.o foo.c
gcc -o foo-dbg foo-dbg.o
gcc -O2 -c -o foo-opt.o foo.c
gcc -o foo-opt foo-opt.o
|