5
import Task,Options,Utils
6
from Configure import conf
7
from TaskGen import extension,taskgen,feature,before
8
xsubpp_str='${PERL} ${XSUBPP} -noprototypes -typemap ${EXTUTILS_TYPEMAP} ${SRC} > ${TGT}'
10
def init_perlext(self):
11
self.uselib=self.to_list(getattr(self,'uselib',''))
12
if not'PERL'in self.uselib:self.uselib.append('PERL')
13
if not'PERLEXT'in self.uselib:self.uselib.append('PERLEXT')
14
self.env['shlib_PATTERN']=self.env['perlext_PATTERN']
15
def xsubpp_file(self,node):
16
outnode=node.change_ext('.c')
17
self.create_task('xsubpp',node,outnode)
18
self.allnodes.append(outnode)
19
Task.simple_task_type('xsubpp',xsubpp_str,color='BLUE',before='cc cxx',shell=False)
20
def check_perl_version(conf,minver=None):
21
if getattr(Options.options,'perlbinary',None):
22
conf.env.PERL=Options.options.perlbinary
24
conf.find_program('perl',var='PERL',mandatory=True)
26
version=Utils.cmd_output([conf.env.PERL,'-e','printf "%vd",$^V'])
28
conf.fatal('could not determine the perl version')
29
conf.env.PERL_VERSION=version
33
ver=tuple(map(int,version.split('.')))
35
conf.fatal('unsupported perl version %r'%version)
37
conf.fatal('perl is too old')
38
cver='.'.join(map(str,minver))
39
conf.check_message('perl',cver,True,version)
40
def check_perl_module(conf,module):
41
cmd=[conf.env['PERL'],'-e','use %s'%module]
42
r=Utils.pproc.call(cmd,stdout=Utils.pproc.PIPE,stderr=Utils.pproc.PIPE)==0
43
conf.check_message("perl module %s"%module,"",r)
45
def check_perl_ext_devel(conf):
47
conf.fatal('perl detection is required first')
49
return Utils.to_list(Utils.cmd_output([conf.env.PERL,'-MConfig','-e',cmd]))
50
conf.env.LINKFLAGS_PERLEXT=read_out('print $Config{lddlflags}')
51
conf.env.CPPPATH_PERLEXT=read_out('print "$Config{archlib}/CORE"')
52
conf.env.CCFLAGS_PERLEXT=read_out('print "$Config{ccflags} $Config{cccdlflags}"')
53
conf.env.XSUBPP=read_out('print "$Config{privlib}/ExtUtils/xsubpp$Config{exe_ext}"')
54
conf.env.EXTUTILS_TYPEMAP=read_out('print "$Config{privlib}/ExtUtils/typemap"')
55
conf.env.perlext_PATTERN='%s.'+read_out('print $Config{dlext}')[0]
56
if getattr(Options.options,'perlarchdir',None):
57
conf.env.ARCHDIR_PERL=Options.options.perlarchdir
59
conf.env.ARCHDIR_PERL=read_out('print $Config{sitearch}')[0]
61
opt.add_option("--with-perl-binary",type="string",dest="perlbinary",help='Specify alternate perl binary',default=None)
62
opt.add_option("--with-perl-archdir",type="string",dest="perlarchdir",help='Specify directory where to install arch specific files',default=None)
64
before('apply_incpaths','apply_type_vars','apply_lib_vars')(init_perlext)
65
feature('perlext')(init_perlext)
66
extension(EXT_XS)(xsubpp_file)
67
conf(check_perl_version)
68
conf(check_perl_module)
69
conf(check_perl_ext_devel)