From: Andrew Tridgell Date: Sat, 27 Mar 2010 09:00:01 +0000 (+1100) Subject: build: substitute @VAR@ variables in pkgconfig .pc.in files X-Git-Tag: samba-3.6.0pre1~3386 X-Git-Url: http://git.samba.org/samba.git/?p=nivanova%2Fsamba-autobuild%2F.git;a=commitdiff_plain;h=91d604add3691e05c0ac1e96d3e2ab223e0b28d5;hp=5b572f1bd8505b0e2d1758d868ae0dec80c5719d;ds=sidebyside build: substitute @VAR@ variables in pkgconfig .pc.in files --- diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py index 1d0b1ba3c19..1fc7f8ca549 100644 --- a/buildtools/wafsamba/wafsamba.py +++ b/buildtools/wafsamba/wafsamba.py @@ -1,7 +1,7 @@ # a waf tool to add autoconf-like macros to the configure section # and for SAMBA_ macros for building libraries, binaries etc -import Build, os, Options, Task, Utils, cc, TaskGen, fnmatch +import Build, os, Options, Task, Utils, cc, TaskGen, fnmatch, re from Configure import conf from Logs import debug from samba_utils import SUBST_VARS_RECURSIVE @@ -475,7 +475,7 @@ def SAMBA_GENERATOR(bld, name, rule, source, target, rule=rule, source=bld.EXPAND_VARIABLES(source, vars=vars), target=target, - shell=True, + shell=isinstance(rule, str), on_results=True, before='cc', ext_out='.c', @@ -713,12 +713,44 @@ def PUBLIC_HEADERS(bld, public_headers, header_path=None): Build.BuildContext.PUBLIC_HEADERS = PUBLIC_HEADERS +def subst_at_vars(task): + '''substiture @VAR@ style variables in a file''' + src = task.inputs[0].srcpath(task.env) + tgt = task.outputs[0].bldpath(task.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: + print "Unknown substitution %s in %s" % (v, task.name) + raise + v = task.env[vname] + out.append(v) + contents = ''.join(out) + f = open(tgt, 'w') + s = f.write(contents) + f.close() + return 0 + + + def PKG_CONFIG_FILES(bld, pc_files): '''install some pkg_config pc files''' - # TODO: replace the @VAR@ variables dest = '${PKGCONFIGDIR}' dest = bld.EXPAND_VARIABLES(dest) for f in TO_LIST(pc_files): - INSTALL_FILES(bld, dest, f+'.in', flat=True, - destname=os.path.basename(f)) + base=os.path.basename(f) + bld.SAMBA_GENERATOR('PKGCONFIG_%s' % base, + rule=subst_at_vars, + source=f+'.in', + target=f) + INSTALL_FILES(bld, dest, f, flat=True, destname=base) Build.BuildContext.PKG_CONFIG_FILES = PKG_CONFIG_FILES