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
)
15 a
= re
.split('(@\w+@)', s
)
18 back_sub
= [ ('PREFIX', '${prefix}'), ('EXEC_PREFIX', '${exec_prefix}')]
20 if re
.match('@\w+@', v
):
22 if not vname
in task
.env
and vname
.upper() in task
.env
:
24 if not vname
in task
.env
:
25 Logs
.error("Unknown substitution %s in %s" % (v
, task
.name
))
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
:
33 # we don't want to substitute the first usage
39 contents
= ''.join(out
)
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
,
56 bld
.add_manual_dependency(bld
.path
.find_or_declare(f
), bld
.env
['PREFIX'])
58 if t
.env
.RPATH_ON_INSTALL
:
59 t
.env
.LIB_RPATH
= t
.env
.RPATH_ST
% t
.env
.LIBDIR
63 t
.env
.PACKAGE_VERSION
= vnum
64 for v
in [ 'PREFIX', 'EXEC_PREFIX', 'LIB_RPATH' ]:
65 t
.vars.append(t
.env
[v
])
66 bld
.INSTALL_FILES(dest
, f
, flat
=True, destname
=base
)
67 Build
.BuildContext
.PKG_CONFIG_FILES
= PKG_CONFIG_FILES