1 # handle substitution of variables in pc files
5 from samba_utils
import SUBST_VARS_RECURSIVE
, TO_LIST
7 def subst_at_vars(task
):
8 '''substiture @VAR@ style variables in a file'''
10 s
= task
.inputs
[0].read()
12 a
= re
.split('(@\w+@)', s
)
15 back_sub
= [ ('PREFIX', '${prefix}'), ('EXEC_PREFIX', '${exec_prefix}')]
17 if re
.match('@\w+@', v
):
19 if not vname
in task
.env
and vname
.upper() in task
.env
:
21 if not vname
in task
.env
:
22 Logs
.error("Unknown substitution %s in %s" % (v
, task
.name
))
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
:
30 # we don't want to substitute the first usage
36 contents
= ''.join(out
)
37 task
.outputs
[0].write(contents
)
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
,
51 bld
.add_manual_dependency(bld
.path
.find_or_declare(f
), bld
.env
['PREFIX'])
53 if t
.env
.RPATH_ON_INSTALL
:
54 t
.env
.LIB_RPATH
= t
.env
.RPATH_ST
% t
.env
.LIBDIR
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