2010-11-03 03:14:40 +03:00
# handle substitution of variables in pc files
2015-10-27 22:46:46 +03:00
import os , re , sys
2018-01-31 12:48:43 +03:00
from waflib import Build , Logs
2015-10-27 22:46:46 +03:00
from samba_utils import SUBST_VARS_RECURSIVE , TO_LIST
2010-11-03 03:14:40 +03:00
def subst_at_vars ( task ) :
''' substiture @VAR@ style variables in a file '''
2015-06-26 21:48:43 +03:00
s = task . inputs [ 0 ] . read ( )
2010-11-03 03:14:40 +03:00
# split on the vars
a = re . split ( ' (@ \ w+@) ' , s )
out = [ ]
done_var = { }
back_sub = [ ( ' PREFIX ' , ' $ {prefix} ' ) , ( ' EXEC_PREFIX ' , ' $ {exec_prefix} ' ) ]
for v in a :
if re . match ( ' @ \ w+@ ' , v ) :
vname = v [ 1 : - 1 ]
if not vname in task . env and vname . upper ( ) in task . env :
vname = vname . upper ( )
if not vname in task . env :
Logs . error ( " Unknown substitution %s in %s " % ( v , task . name ) )
sys . exit ( 1 )
v = SUBST_VARS_RECURSIVE ( task . env [ vname ] , task . env )
# now we back substitute the allowed pc vars
for ( b , m ) in back_sub :
s = task . env [ b ]
if s == v [ 0 : len ( s ) ] :
if not b in done_var :
# we don't want to substitute the first usage
done_var [ b ] = True
else :
v = m + v [ len ( s ) : ]
break
out . append ( v )
contents = ' ' . join ( out )
2015-06-26 21:48:43 +03:00
task . outputs [ 0 ] . write ( contents )
2010-11-03 03:14:40 +03:00
return 0
2017-03-06 09:25:13 +03:00
def PKG_CONFIG_FILES ( bld , pc_files , vnum = None , extra_name = None ) :
2010-11-03 03:14:40 +03:00
''' install some pkg_config pc files '''
dest = ' $ {PKGCONFIGDIR} '
dest = bld . EXPAND_VARIABLES ( dest )
for f in TO_LIST ( pc_files ) :
2017-03-06 09:25:13 +03:00
if extra_name :
target = f . split ( ' .pc ' ) [ 0 ] + extra_name + " .pc "
else :
target = f
base = os . path . basename ( target )
2010-11-03 03:14:40 +03:00
t = bld . SAMBA_GENERATOR ( ' PKGCONFIG_ %s ' % base ,
rule = subst_at_vars ,
source = f + ' .in ' ,
2017-03-06 09:25:13 +03:00
target = target )
2018-09-26 18:26:45 +03:00
bld . add_manual_dependency ( bld . path . find_or_declare ( f ) , bld . env [ ' PREFIX ' ] . encode ( ' utf8 ' ) )
2010-11-03 03:30:23 +03:00
t . vars = [ ]
2010-12-08 10:47:39 +03:00
if t . env . RPATH_ON_INSTALL :
t . env . LIB_RPATH = t . env . RPATH_ST % t . env . LIBDIR
else :
t . env . LIB_RPATH = ' '
2010-11-03 03:14:40 +03:00
if vnum :
t . env . PACKAGE_VERSION = vnum
2010-12-08 10:47:39 +03:00
for v in [ ' PREFIX ' , ' EXEC_PREFIX ' , ' LIB_RPATH ' ] :
t . vars . append ( t . env [ v ] )
2017-03-06 09:25:13 +03:00
bld . INSTALL_FILES ( dest , target , flat = True , destname = base )
2010-11-03 03:14:40 +03:00
Build . BuildContext . PKG_CONFIG_FILES = PKG_CONFIG_FILES