Modifying a Construction Environment

SCons provides various methods that support modifying existing values in a construction environment.

Replacing Values in a Construction Environment

You can replace existing construction variable values using the Replace method:

        env = Environment(CCFLAGS = '-DDEFINE1')
        env.Program('foo.c')
        env.Replace(CCFLAGS = '-DDEFINE2')
        env.Program('bar.c')
     

The replaced value completely overwrites

        % scons -Q
        cc -DDEFINE2 -c -o bar.o bar.c
        cc -o bar bar.o
        cc -DDEFINE1 -c -o foo.o foo.c
        cc -o foo foo.o
     

Appending to the End of Values in a Construction Environment

You can append a value to an existing construction variable using the Append method:

        env = Environment(CCFLAGS = '-DMY_VALUE')
        env.Append(CCFLAGS = ' -DLAST')
        env.Program('foo.c')
     

        % scons -Q
        cc -DMY_VALUE -DLAST -c -o foo.o foo.c
        cc -o foo foo.o
     

Appending to the Beginning of Values in a Construction Environment

You can append a value to the beginning an existing construction variable using the Prepend method:

        env = Environment(CCFLAGS = '-DMY_VALUE')
        env.Prepend(CCFLAGS = '-DFIRST ')
        env.Program('foo.c')
     

        % scons -Q
        cc -DFIRST -DMY_VALUE -c -o foo.o foo.c
        cc -o foo foo.o