Please note:The SCons wiki is now restored from the attack in March 2013. All old passwords have been invalidated. Please reset your password if you have an account. If you note missing pages, please report them to Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).

* Also see SavingVariablesToAFile

It's very common practice (and useful for sysadmins) to allow users to be able to specify a base directory to install a package into. This base directory is known as the prefix. Common prefixes on UNIX systems are /usr, /usr/local, /opt/appname/, or ~/.local/ .

Here's how I set up my builds to allow installation to custom prefixes:

   1 # SConstruct file for WidgetMaster
   2 env = Environment()
   4 # Get our configuration options:
   5 opts = Variables('wm.conf') # Change wm to the name of your app
   6 opts.Add(PathVariable('PREFIX', 'Directory to install under', '/usr', PathVariable.PathIsDir))
   7 opts.Update(env)
   8 opts.Save('wm.conf', env) # Save, so user doesn't have to 
   9                           # specify PREFIX every time
  11 Help(opts.GenerateHelpText(env))
  13 # ... put your configuration here ...
  15 # Here are our installation paths:
  16 idir_prefix = '$PREFIX'
  17 idir_lib    = '$PREFIX/lib'
  18 idir_bin    = '$PREFIX/bin'
  19 idir_inc    = '$PREFIX/include'
  20 idir_data   = '$PREFIX/share'
  21 Export('env idir_prefix idir_lib idir_bin idir_inc idir_data')
  23 # ... build your program here, or call SConscript files ...
  25 libwm = env.SharedLibrary('wm', ['widget.c', 'master.c'])
  27 env.Install(idir_lib, libwm)
  28 env.Install(idir_inc, ['widget.h', 'master.h'])
  29 env.Alias('install', idir_prefix)

If you call SConscript files, this is what one would look like:

   1 # SConstruct file for WidgetMaster
   2 Import('env idir_bin')
   3 wm = env.Program('wm', ['widget.c', 'master.c', 'sprocket.c'])
   5 env.Install(idir_bin, wm)
   6 env.Alias('install', idir_prefix)

Now, the first time a user builds your application, they specify the prefix like this:

$ scons -Q PREFIX=/opt/wm install
$ scons -Q PREFIX=/usr;scons -Q install

They only have to specify the PREFIX variable the first time they call scons, because subsequent builds read it from the file "wm.conf" which is generated automatically by the Save() function.


1. Using PathVariable by default makes scons fail if the user specifies a path that doesn't yet exist. Look in the man page under PathVariable for details about PathAccept (don't do validation) and other possibilities such as PathIsDirCreate (validate directory and create if not existing).

2. Normally, autoconf and friends allow the user to specify different paths for installing binaries, libraries, etc. You could use this template to support this, if you think it is necessary.

InstallationPrefix (last edited 2011-09-19 19:19:40 by MarcoMolteni)