summaryrefslogtreecommitdiff
path: root/buildtools/wafsamba/configure_file.py
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2012-09-06 12:14:34 +0200
committerAndreas Schneider <asn@cryptomilk.org>2012-09-07 10:48:57 +0200
commit802708b410b6367c01d968565f3f5e3a8751522d (patch)
treeb5c9b27c8d6bc7babf8e44594c772cc4449c9f60 /buildtools/wafsamba/configure_file.py
parent18eb505b895efae8b723ff3ecddc7c528c34b391 (diff)
downloadsamba-802708b410b6367c01d968565f3f5e3a8751522d.tar.gz
samba-802708b410b6367c01d968565f3f5e3a8751522d.tar.bz2
samba-802708b410b6367c01d968565f3f5e3a8751522d.zip
wafsamba: Add a CONFIGURE_FILE option.
Diffstat (limited to 'buildtools/wafsamba/configure_file.py')
-rw-r--r--buildtools/wafsamba/configure_file.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/buildtools/wafsamba/configure_file.py b/buildtools/wafsamba/configure_file.py
new file mode 100644
index 0000000000..8e2ba3bc23
--- /dev/null
+++ b/buildtools/wafsamba/configure_file.py
@@ -0,0 +1,44 @@
+# handle substitution of variables in .in files
+
+import Build, sys, Logs
+from samba_utils import *
+
+def subst_at_vars(task):
+ '''substiture @VAR@ style variables in a file'''
+
+ env = task.env
+ src = task.inputs[0].srcpath(env)
+ tgt = task.outputs[0].bldpath(env)
+
+ f = open(src, 'r')
+ s = f.read()
+ f.close()
+ # split on the vars
+ a = re.split('(@\w+@)', s)
+ out = []
+ for v in a:
+ if re.match('@\w+@', v):
+ vname = v[1:-1]
+ if not vname in task.env and vname.upper() in task.env:
+ vname = vname.upper()
+ if not vname in task.env:
+ Logs.error("Unknown substitution %s in %s" % (v, task.name))
+ sys.exit(1)
+ v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
+ out.append(v)
+ contents = ''.join(out)
+ f = open(tgt, 'w')
+ s = f.write(contents)
+ f.close()
+ return 0
+
+def CONFIGURE_FILE(bld, in_file, **kwargs):
+ '''configure file'''
+
+ base=os.path.basename(in_file)
+ t = bld.SAMBA_GENERATOR('INFILE_%s' % base,
+ rule = subst_at_vars,
+ source = in_file + '.in',
+ target = in_file,
+ vars = kwargs)
+Build.BuildContext.CONFIGURE_FILE = CONFIGURE_FILE