fork of capisuite ( with some fixes to make it build on modern Linux
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

# -*- python -*-
File-Content Substitution builder for SCons
__author__ = "Hartmut Goebel <>"
import os, re
import SCons
def _action(target, source, env):
def _substitute(matchobj, env=env):
sym =
return env.subst(str(env[sym]))
except: # TypeError: # sym not a string
txt = # the string matched
print 'Not substituting', txt
return txt
delim = re.escape(env['FILESUBSTDELIM'])
# compile a non-greedy pattern
subst_pattern = re.compile('%s(.*?)%s' % (delim, delim))
for t, s in zip(target, source):
t = str(t)
s = s.rstr()
text = open(s, 'rb').read()
text = subst_pattern.sub(_substitute, text)
open(t, 'wb').write(text)
os.chmod(t, os.stat(s)[0])
return None
def _strfunc(target, source, env):
return "generating '%s' from '%s'" % (target[0], source[0])
_builder = SCons.Builder.Builder(
action = SCons.Action.Action(_action, _strfunc),
src_suffix = '.in',
def generate(env):
env['BUILDERS']['FileSubst'] = _builder
def exists(env):
return 1