thirdparty:waf: New files for waf 1.9.10
[Samba.git] / third_party / waf / waflib / Tools / perl.py
blobcc8fe478bf0082ec8a81fc0f884b8420cb3a25a7
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
5 #!/usr/bin/env python
6 # encoding: utf-8
7 # andersg at 0x63.nu 2007
8 # Thomas Nagy 2016 (ita)
10 """
11 Support for Perl extensions. A C/C++ compiler is required::
13 def options(opt):
14 opt.load('compiler_c perl')
15 def configure(conf):
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')
21 def build(bld):
22 bld(
23 features = 'c cshlib perlext',
24 source = 'Mytest.xs',
25 target = 'Mytest',
26 install_path = '${ARCHDIR_PERL}/auto')
27 bld.install_files('${ARCHDIR_PERL}', 'Mytest.pm')
28 """
30 import os
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')
36 @feature('perlext')
37 def init_perlext(self):
38 """
39 Change the values of *cshlib_PATTERN* and *cxxshlib_PATTERN* to remove the
40 *lib* prefix from library names.
41 """
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
46 @extension('.xs')
47 def xsubpp_file(self, node):
48 """
49 Create :py:class:`waflib.Tools.perl.xsubpp` tasks to process *.xs* files
50 """
51 outnode = node.change_ext('.c')
52 self.create_task('xsubpp', node, outnode)
53 self.source.append(outnode)
55 class xsubpp(Task.Task):
56 """
57 Process *.xs* files
58 """
59 run_str = '${PERL} ${XSUBPP} -noprototypes -typemap ${EXTUTILS_TYPEMAP} ${SRC} > ${TGT}'
60 color = 'BLUE'
61 ext_out = ['.h']
63 @conf
64 def check_perl_version(self, minver=None):
65 """
66 Check if Perl is installed, and set the variable PERL.
67 minver is supposed to be a tuple
68 """
69 res = True
70 if minver:
71 cver = '.'.join(map(str,minver))
72 else:
73 cver = ''
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'])
79 if not version:
80 res = False
81 version = "Unknown"
82 elif not minver is None:
83 ver = tuple(map(int, version.split(".")))
84 if ver < minver:
85 res = False
87 self.end_msg(version, color=res and 'GREEN' or 'YELLOW')
88 return res
90 @conf
91 def check_perl_module(self, module):
92 """
93 Check if specified perlmodule is installed.
95 The minimum version can be specified by specifying it after modulename
96 like this::
98 def configure(conf):
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)
103 try:
104 r = self.cmd_and_log(cmd)
105 except Exception:
106 self.end_msg(False)
107 return None
108 self.end_msg(r or True)
109 return r
111 @conf
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.
122 env = self.env
123 perl = env.PERL
124 if not perl:
125 self.fatal('find perl first')
127 def cmd_perl_config(s):
128 return perl + ['-MConfig', '-e', 'print \"%s\"' % s]
129 def cfg_str(cfg):
130 return self.cmd_and_log(cmd_perl_config(cfg))
131 def cfg_lst(cfg):
132 return Utils.to_list(cfg_str(cfg))
133 def find_xsubpp():
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]):
137 return xsubpp
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}')
148 else:
149 env.ARCHDIR_PERL = getattr(Options.options, 'perlarchdir')
151 env.perlext_PATTERN = '%s.' + cfg_str('$Config{dlext}')
153 def options(opt):
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)