3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
7 # andersg at 0x63.nu 2007
8 # Thomas Nagy 2016 (ita)
11 Support for Perl extensions. A C/C++ compiler is required::
14 opt.load('compiler_c perl')
16 conf.load('compiler_c perl')
17 conf.check_perl_version((5,6,0))
18 conf.check_perl_ext_devel()
19 conf.check_perl_module('Cairo')
20 conf.check_perl_module('Devel::PPPort 4.89')
23 features = 'c cshlib perlext',
26 install_path = '${ARCHDIR_PERL}/auto')
27 bld.install_files('${ARCHDIR_PERL}', 'Mytest.pm')
31 from waflib
import Task
, Options
, Utils
32 from waflib
.Configure
import conf
33 from waflib
.TaskGen
import extension
, feature
, before_method
35 @before_method('apply_incpaths', 'apply_link', 'propagate_uselib_vars')
37 def init_perlext(self
):
39 Change the values of *cshlib_PATTERN* and *cxxshlib_PATTERN* to remove the
40 *lib* prefix from library names.
42 self
.uselib
= self
.to_list(getattr(self
, 'uselib', []))
43 if not 'PERLEXT' in self
.uselib
: self
.uselib
.append('PERLEXT')
44 self
.env
.cshlib_PATTERN
= self
.env
.cxxshlib_PATTERN
= self
.env
.perlext_PATTERN
47 def xsubpp_file(self
, node
):
49 Create :py:class:`waflib.Tools.perl.xsubpp` tasks to process *.xs* files
51 outnode
= node
.change_ext('.c')
52 self
.create_task('xsubpp', node
, outnode
)
53 self
.source
.append(outnode
)
55 class xsubpp(Task
.Task
):
59 run_str
= '${PERL} ${XSUBPP} -noprototypes -typemap ${EXTUTILS_TYPEMAP} ${SRC} > ${TGT}'
64 def check_perl_version(self
, minver
=None):
66 Check if Perl is installed, and set the variable PERL.
67 minver is supposed to be a tuple
71 cver
= '.'.join(map(str,minver
))
75 self
.start_msg('Checking for minimum perl version %s' % cver
)
77 perl
= self
.find_program('perl', var
='PERL', value
=getattr(Options
.options
, 'perlbinary', None))
78 version
= self
.cmd_and_log(perl
+ ["-e", 'printf \"%vd\", $^V'])
82 elif not minver
is None:
83 ver
= tuple(map(int, version
.split(".")))
87 self
.end_msg(version
, color
=res
and 'GREEN' or 'YELLOW')
91 def check_perl_module(self
, module
):
93 Check if specified perlmodule is installed.
95 The minimum version can be specified by specifying it after modulename
99 conf.check_perl_module("Some::Module 2.92")
101 cmd
= self
.env
.PERL
+ ['-e', 'use %s' % module
]
102 self
.start_msg('perl module %s' % module
)
104 r
= self
.cmd_and_log(cmd
)
108 self
.end_msg(r
or True)
112 def check_perl_ext_devel(self
):
114 Check for configuration needed to build perl extensions.
116 Sets different xxx_PERLEXT variables in the environment.
118 Also sets the ARCHDIR_PERL variable useful as installation path,
119 which can be overridden by ``--with-perl-archdir`` option.
125 self
.fatal('find perl first')
127 def cmd_perl_config(s
):
128 return perl
+ ['-MConfig', '-e', 'print \"%s\"' % s
]
130 return self
.cmd_and_log(cmd_perl_config(cfg
))
132 return Utils
.to_list(cfg_str(cfg
))
134 for var
in ('privlib', 'vendorlib'):
135 xsubpp
= cfg_lst('$Config{%s}/ExtUtils/xsubpp$Config{exe_ext}' % var
)
136 if xsubpp
and os
.path
.isfile(xsubpp
[0]):
138 return self
.find_program('xsubpp')
140 env
.LINKFLAGS_PERLEXT
= cfg_lst('$Config{lddlflags}')
141 env
.INCLUDES_PERLEXT
= cfg_lst('$Config{archlib}/CORE')
142 env
.CFLAGS_PERLEXT
= cfg_lst('$Config{ccflags} $Config{cccdlflags}')
143 env
.EXTUTILS_TYPEMAP
= cfg_lst('$Config{privlib}/ExtUtils/typemap')
144 env
.XSUBPP
= find_xsubpp()
146 if not getattr(Options
.options
, 'perlarchdir', None):
147 env
.ARCHDIR_PERL
= cfg_str('$Config{sitearch}')
149 env
.ARCHDIR_PERL
= getattr(Options
.options
, 'perlarchdir')
151 env
.perlext_PATTERN
= '%s.' + cfg_str('$Config{dlext}')
155 Add the ``--with-perl-archdir`` and ``--with-perl-binary`` command-line options.
157 opt
.add_option('--with-perl-binary', type='string', dest
='perlbinary', help = 'Specify alternate perl binary', default
=None)
158 opt
.add_option('--with-perl-archdir', type='string', dest
='perlarchdir', help = 'Specify directory where to install arch specific files', default
=None)