Clone wiki

SCons / SavingVariablesToAFile

The SCons wiki has moved to

SCons has built-in facilities to save variables to a file and load them back - especially useful to store information like installation prefix (if you want to make an uninstall target, for instance), or the results of a configure step.

First create a Variables object


# specify the name of the file in which variables are/will be stored
vars = Variables('build-setup.conf')

# Register which variables we're interested in and
# get values from a saved file if any (defaults, which are
# specified in the last argument, are used otherwise)
vars.Add('config', '', 'release')
vars.Add('prefix', '', '/usr/local')
vars.Add('platform', '', 'auto')
vars.Add('glut_enabled', '', False)
vars.Add('havegettext', '', '')

# update these variables in your environment

# do your stuff with the variables

if env['config'] == "debug":
elif env['config'] == "release":

# change variables if needed (e.g. if you're running a
#'configure' step, or if environment changed)
if changing_values:
    env['platform'] = "unix"
    # save new values
    vars.Save('build-setup.conf', env)