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
        gcc -DDEFINE2 -c bar.c -o bar.o
        gcc -o bar bar.o
        gcc -DDEFINE2 -c foo.c -o foo.o
        gcc -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
        gcc -DMY_VALUE -DLAST -c foo.c -o foo.o
        gcc -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
        gcc -DFIRST -DMY_VALUE -c foo.c -o foo.o
        gcc -o foo foo.o