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'''
9 s = task.inputs[0].read()
11 a = re.split('(@\w+@)', s)
14 back_sub = [ ('PREFIX', '${prefix}'), ('EXEC_PREFIX', '${exec_prefix}')]
16 if re.match('@\w+@', v):
18 if not vname in task.env and vname.upper() in task.env:
20 if not vname in task.env:
21 Logs.error("Unknown substitution %s in %s" % (v, task.name))
23 v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
24 # now we back substitute the allowed pc vars
25 for (b, m) in back_sub:
29 # we don't want to substitute the first usage
35 contents = ''.join(out)
36 task.outputs[0].write(contents)
40 def PKG_CONFIG_FILES(bld, pc_files, vnum=None):
41 '''install some pkg_config pc files'''
42 dest = '${PKGCONFIGDIR}'
43 dest = bld.EXPAND_VARIABLES(dest)
44 for f in TO_LIST(pc_files):
45 base=os.path.basename(f)
46 t = bld.SAMBA_GENERATOR('PKGCONFIG_%s' % base,
50 bld.add_manual_dependency(bld.path.find_or_declare(f), bld.env['PREFIX'])
52 if t.env.RPATH_ON_INSTALL:
53 t.env.LIB_RPATH = t.env.RPATH_ST % t.env.LIBDIR
57 t.env.PACKAGE_VERSION = vnum
58 for v in [ 'PREFIX', 'EXEC_PREFIX', 'LIB_RPATH' ]:
59 t.vars.append(t.env[v])
60 bld.INSTALL_FILES(dest, f, flat=True, destname=base)
61 Build.BuildContext.PKG_CONFIG_FILES = PKG_CONFIG_FILES