WHATSNEW: Add changes since 3.6.15.
[Samba.git] / buildtools / wafsamba / pkgconfig.py
blob09bfcb9c6beae581168961f544ad8ffe4dbef351
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 t.vars = []
57 if t.env.RPATH_ON_INSTALL:
58 t.env.LIB_RPATH = t.env.RPATH_ST % t.env.LIBDIR
59 else:
60 t.env.LIB_RPATH = ''
61 if vnum:
62 t.env.PACKAGE_VERSION = vnum
63 for v in [ 'PREFIX', 'EXEC_PREFIX', 'LIB_RPATH' ]:
64 t.vars.append(t.env[v])
65 bld.INSTALL_FILES(dest, f, flat=True, destname=base)
66 Build.BuildContext.PKG_CONFIG_FILES = PKG_CONFIG_FILES