# -*-python-*- ''' Options (see scons -h) scons build=DIR # clean srcdir build, output below DIR scons out=DIR # write output for alterative config to DIR ''' import os srcdir = Dir ('.').srcnode ().abspath env = Environment () config_cache = 'scons.cache' opts = Options ([config_cache, 'custom.py'], ARGUMENTS) opts.Add ('prefix', 'Install prefix', '/usr/') opts.Add ('out', 'Output directory', 'out-scons') opts.Add ('build', 'Build directory', '.') usage = 'help' Help (usage + opts.GenerateHelpText (env)) config_vars = ['PYTHON'] # Add all config_vars to opts, so that they will be read and saved # together with the other configure options. map (lambda x: opts.AddOptions ((x,)), config_vars) opts.Update (env) atvars = ['PYTHON'] def at_copy_ext (target, source, env): n = str (source[0]) s = open (n).read () for i in atvars: if env.has_key (i): s = s.replace ('@%s@'% i, env[i]) e = os.path.splitext (n)[1] t = str (target[0]) + e open (t, 'w').write (s) AT_COPY_EXT = Builder (action = at_copy_ext, src_suffix=['.py', '.sh',]) env.Append (BUILDERS = {'AT_COPY_EXT': AT_COPY_EXT}) env.Alias ('minimal', ['python']) env.Alias ('all', ['minimal', '.']) Export ('env') # Without target arguments, do minimal build if not COMMAND_LINE_TARGETS: env.Default (['minimal']) subdirs = ['python'] if not os.path.isdir ('python'): os.mkdir ('python') s = ''' Import ('env') py = ['foo.py'] pym = map (env.AT_COPY_EXT, py) pym ''' open ('python/SConscript', 'w').write (s) open ('python/foo.py', 'w').write ('#! @PYTHON@') print 'build:', env['build'] # Note: SConscripts are only needed in directories where something needs # to be done, building or installing for d in subdirs: if os.path.exists (os.path.join (d, 'SConscript')): b = os.path.join (env['build'], d, env['out']) # Support clean sourcetree build (--srcdir build) # and ./out build. if os.path.abspath (b) != os.path.abspath (d): env.BuildDir (b, d, duplicate = 0) SConscript (os.path.join (b, 'SConscript'))