Please note:The SCons wiki is in read-only mode due to ongoing spam/DoS issues. Also, new account creation is currently disabled. We are looking into alternative wiki hosts.

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

   1 # specify the name of the file in which variables are/will be stored
   2 vars = Variables('build-setup.conf')
   3 
   4 # Register which variables we're interested in and
   5 # get values from a saved file if any (defaults, which are
   6 # specified in the last argument, are used otherwise)
   7 vars.Add('config', '', 'release')
   8 vars.Add('prefix', '', '/usr/local')
   9 vars.Add('platform', '', 'auto')
  10 vars.Add('glut_enabled', '', False)
  11 vars.Add('havegettext', '', '')
  12 
  13 # update these variables in your environment
  14 vars.Update(env)
  15 
  16 # do your stuff with the variables
  17 
  18 if env['config'] == "debug":
  19     env.Append(CCFLAGS=['-g','-Wfatal-errors']) 
  20 elif env['config'] == "release":
  21      env.Append(CCFLAGS=['-O3','-DNDEBUG'])
  22 
  23 # change variables if needed (e.g. if you're running a
  24 #'configure' step, or if environment changed)
  25 if changing_values:
  26     env['platform'] = "unix"
  27     # save new values
  28     vars.Save('build-setup.conf', env)

SavingVariablesToAFile (last edited 2009-06-01 14:32:56 by MarianneGagnon)