build(autoconf): check if we have ctdb_protocol.h in the cluster checks
[Samba/gebeck_regimport.git] / buildtools / wafadmin / Tools / perl.py
bloba6787a86ecfa86d41593fb01c561e145d6825738
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # andersg at 0x63.nu 2007
5 import os
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}'
11 EXT_XS = ['.xs']
13 @before('apply_incpaths', 'apply_type_vars', 'apply_lib_vars')
14 @feature('perlext')
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']
21 @extension(EXT_XS)
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)
29 @conf
30 def check_perl_version(conf, minver=None):
31 """
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
38 """
40 if getattr(Options.options, 'perlbinary', None):
41 conf.env.PERL = Options.options.perlbinary
42 else:
43 conf.find_program('perl', var='PERL', mandatory=True)
45 try:
46 version = Utils.cmd_output([conf.env.PERL, '-e', 'printf "%vd",$^V'])
47 except:
48 conf.fatal('could not determine the perl version')
50 conf.env.PERL_VERSION = version
51 cver = ''
52 if minver:
53 try:
54 ver = tuple(map(int, version.split('.')))
55 except:
56 conf.fatal('unsupported perl version %r' % version)
57 if ver < minver:
58 conf.fatal('perl is too old')
60 cver = '.'.join(map(str,minver))
61 conf.check_message('perl', cver, True, version)
63 @conf
64 def check_perl_module(conf, module):
65 """
66 Check if specified perlmodule is installed.
68 Minimum version can be specified by specifying it after modulename
69 like this:
71 conf.check_perl_module("Some::Module 2.92")
72 """
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)
76 return r
78 @conf
79 def check_perl_ext_devel(conf):
80 """
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
87 """
88 if not conf.env.PERL:
89 conf.fatal('perl detection is required first')
91 def read_out(cmd):
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
103 else:
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)