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