-
-
Notifications
You must be signed in to change notification settings - Fork 321
SavingVariablesToAFile
Mats Wichmann edited this page Oct 1, 2021
·
3 revisions
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
vars.Update(env)
# do your stuff with the variables
if env['config'] == "debug":
env.Append(CCFLAGS=['-g', '-Wfatal-errors'])
elif env['config'] == "release":
env.Append(CCFLAGS=['-O3', '-DNDEBUG'])
# 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)