ctdb: Avoid a talloc in ctdb_queue_send
[Samba.git] / buildtools / wafsamba / pkgconfig.py
blob8a3f807dc5530c1709b6a8653e07b707eacb69b2
1 # handle substitution of variables in pc files
3 import Build, sys, Logs
4 from samba_utils import *
6 def subst_at_vars(task):
7 '''substiture @VAR@ style variables in a file'''
8 src = task.inputs[0].srcpath(task.env)
9 tgt = task.outputs[0].bldpath(task.env)
11 f = open(src, 'r')
12 s = f.read()
13 f.close()
14 # split on the vars
15 a = re.split('(@\w+@)', s)
16 out = []
17 done_var = {}
18 back_sub = [ ('PREFIX', '${prefix}'), ('EXEC_PREFIX', '${exec_prefix}')]
19 for v in a:
20 if re.match('@\w+@', v):
21 vname = v[1:-1]
22 if not vname in task.env and vname.upper() in task.env:
23 vname = vname.upper()
24 if not vname in task.env:
25 Logs.error("Unknown substitution %s in %s" % (v, task.name))
26 sys.exit(1)
27 v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
28 # now we back substitute the allowed pc vars
29 for (b, m) in back_sub:
30 s = task.env[b]
31 if s == v[0:len(s)]:
32 if not b in done_var:
33 # we don't want to substitute the first usage
34 done_var[b] = True
35 else:
36 v = m + v[len(s):]
37 break
38 out.append(v)
39 contents = ''.join(out)
40 f = open(tgt, 'w')
41 s = f.write(contents)
42 f.close()
43 return 0
46 def PKG_CONFIG_FILES(bld, pc_files, vnum=None):
47 '''install some pkg_config pc files'''
48 dest = '${PKGCONFIGDIR}'
49 dest = bld.EXPAND_VARIABLES(dest)
50 for f in TO_LIST(pc_files):
51 base=os.path.basename(f)
52 t = bld.SAMBA_GENERATOR('PKGCONFIG_%s' % base,
53 rule=subst_at_vars,
54 source=f+'.in',
55 target=f)
56 bld.add_manual_dependency(bld.path.find_or_declare(f), bld.env['PREFIX'])
57 t.vars = []
58 if t.env.RPATH_ON_INSTALL:
59 t.env.LIB_RPATH = t.env.RPATH_ST % t.env.LIBDIR
60 else:
61 t.env.LIB_RPATH = ''
62 if vnum:
63 t.env.PACKAGE_VERSION = vnum
64 for v in [ 'PREFIX', 'EXEC_PREFIX', 'LIB_RPATH' ]:
65 t.vars.append(t.env[v])
66 bld.INSTALL_FILES(dest, f, flat=True, destname=base)
67 Build.BuildContext.PKG_CONFIG_FILES = PKG_CONFIG_FILES