1 # handle substitution of variables in pc files
4 from waflib
import Build
, Logs
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, extra_name
=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
):
47 target
= f
.split('.pc')[0] + extra_name
+ ".pc"
50 base
=os
.path
.basename(target
)
51 t
= bld
.SAMBA_GENERATOR('PKGCONFIG_%s' % base
,
55 bld
.add_manual_dependency(bld
.path
.find_or_declare(f
), bld
.env
['PREFIX'].encode('utf8'))
57 if t
.env
.RPATH_ON_INSTALL
:
58 t
.env
.LIB_RPATH
= t
.env
.RPATH_ST
% t
.env
.LIBDIR
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
, target
, flat
=True, destname
=base
)
66 Build
.BuildContext
.PKG_CONFIG_FILES
= PKG_CONFIG_FILES