3 # andersg at 0x63.nu 2007
6 import Task
, Options
, Utils
7 from Configure
import conf
8 from TaskGen
import extension
, taskgen
, feature
, before
10 xsubpp_str
= '${PERL} ${XSUBPP} -noprototypes -typemap ${EXTUTILS_TYPEMAP} ${SRC} > ${TGT}'
13 @before('apply_incpaths', 'apply_type_vars', 'apply_lib_vars')
15 def init_perlext(self
):
16 self
.uselib
= self
.to_list(getattr(self
, 'uselib', ''))
17 if not 'PERL' in self
.uselib
: self
.uselib
.append('PERL')
18 if not 'PERLEXT' in self
.uselib
: self
.uselib
.append('PERLEXT')
19 self
.env
['shlib_PATTERN'] = self
.env
['perlext_PATTERN']
22 def xsubpp_file(self
, node
):
23 outnode
= node
.change_ext('.c')
24 self
.create_task('xsubpp', node
, outnode
)
25 self
.allnodes
.append(outnode
)
27 Task
.simple_task_type('xsubpp', xsubpp_str
, color
='BLUE', before
='cc cxx', shell
=False)
30 def check_perl_version(conf
, minver
=None):
32 Checks if perl is installed.
34 If installed the variable PERL will be set in environment.
36 Perl binary can be overridden by --with-perl-binary config variable
40 if getattr(Options
.options
, 'perlbinary', None):
41 conf
.env
.PERL
= Options
.options
.perlbinary
43 conf
.find_program('perl', var
='PERL', mandatory
=True)
46 version
= Utils
.cmd_output([conf
.env
.PERL
, '-e', 'printf "%vd",$^V'])
48 conf
.fatal('could not determine the perl version')
50 conf
.env
.PERL_VERSION
= version
54 ver
= tuple(map(int, version
.split('.')))
56 conf
.fatal('unsupported perl version %r' % version
)
58 conf
.fatal('perl is too old')
60 cver
= '.'.join(map(str,minver
))
61 conf
.check_message('perl', cver
, True, version
)
64 def check_perl_module(conf
, module
):
66 Check if specified perlmodule is installed.
68 Minimum version can be specified by specifying it after modulename
71 conf.check_perl_module("Some::Module 2.92")
73 cmd
= [conf
.env
['PERL'], '-e', 'use %s' % module
]
74 r
= Utils
.pproc
.call(cmd
, stdout
=Utils
.pproc
.PIPE
, stderr
=Utils
.pproc
.PIPE
) == 0
75 conf
.check_message("perl module %s" % module
, "", r
)
79 def check_perl_ext_devel(conf
):
81 Check for configuration needed to build perl extensions.
83 Sets different xxx_PERLEXT variables in the environment.
85 Also sets the ARCHDIR_PERL variable useful as installation path,
86 which can be overridden by --with-perl-archdir
89 conf
.fatal('perl detection is required first')
92 return Utils
.to_list(Utils
.cmd_output([conf
.env
.PERL
, '-MConfig', '-e', cmd
]))
94 conf
.env
.LINKFLAGS_PERLEXT
= read_out('print $Config{lddlflags}')
95 conf
.env
.CPPPATH_PERLEXT
= read_out('print "$Config{archlib}/CORE"')
96 conf
.env
.CCFLAGS_PERLEXT
= read_out('print "$Config{ccflags} $Config{cccdlflags}"')
97 conf
.env
.XSUBPP
= read_out('print "$Config{privlib}/ExtUtils/xsubpp$Config{exe_ext}"')
98 conf
.env
.EXTUTILS_TYPEMAP
= read_out('print "$Config{privlib}/ExtUtils/typemap"')
99 conf
.env
.perlext_PATTERN
= '%s.' + read_out('print $Config{dlext}')[0]
101 if getattr(Options
.options
, 'perlarchdir', None):
102 conf
.env
.ARCHDIR_PERL
= Options
.options
.perlarchdir
104 conf
.env
.ARCHDIR_PERL
= read_out('print $Config{sitearch}')[0]
106 def set_options(opt
):
107 opt
.add_option("--with-perl-binary", type="string", dest
="perlbinary", help = 'Specify alternate perl binary', default
=None)
108 opt
.add_option("--with-perl-archdir", type="string", dest
="perlarchdir", help = 'Specify directory where to install arch specific files', default
=None)