Blame third_party/waf/waflib/Tools/perl.py

rpm-build 95f51c
#!/usr/bin/env python
rpm-build 95f51c
# encoding: utf-8
rpm-build 95f51c
# andersg at 0x63.nu 2007
rpm-build 95f51c
# Thomas Nagy 2016-2018 (ita)
rpm-build 95f51c
rpm-build 95f51c
"""
rpm-build 95f51c
Support for Perl extensions. A C/C++ compiler is required::
rpm-build 95f51c
rpm-build 95f51c
	def options(opt):
rpm-build 95f51c
		opt.load('compiler_c perl')
rpm-build 95f51c
	def configure(conf):
rpm-build 95f51c
		conf.load('compiler_c perl')
rpm-build 95f51c
		conf.check_perl_version((5,6,0))
rpm-build 95f51c
		conf.check_perl_ext_devel()
rpm-build 95f51c
		conf.check_perl_module('Cairo')
rpm-build 95f51c
		conf.check_perl_module('Devel::PPPort 4.89')
rpm-build 95f51c
	def build(bld):
rpm-build 95f51c
		bld(
rpm-build 95f51c
			features     = 'c cshlib perlext',
rpm-build 95f51c
			source       = 'Mytest.xs',
rpm-build 95f51c
			target       = 'Mytest',
rpm-build 95f51c
			install_path = '${ARCHDIR_PERL}/auto')
rpm-build 95f51c
		bld.install_files('${ARCHDIR_PERL}', 'Mytest.pm')
rpm-build 95f51c
"""
rpm-build 95f51c
rpm-build 95f51c
import os
rpm-build 95f51c
from waflib import Task, Options, Utils, Errors
rpm-build 95f51c
from waflib.Configure import conf
rpm-build 95f51c
from waflib.TaskGen import extension, feature, before_method
rpm-build 95f51c
rpm-build 95f51c
@before_method('apply_incpaths', 'apply_link', 'propagate_uselib_vars')
rpm-build 95f51c
@feature('perlext')
rpm-build 95f51c
def init_perlext(self):
rpm-build 95f51c
	"""
rpm-build 95f51c
	Change the values of *cshlib_PATTERN* and *cxxshlib_PATTERN* to remove the
rpm-build 95f51c
	*lib* prefix from library names.
rpm-build 95f51c
	"""
rpm-build 95f51c
	self.uselib = self.to_list(getattr(self, 'uselib', []))
rpm-build 95f51c
	if not 'PERLEXT' in self.uselib:
rpm-build 95f51c
		self.uselib.append('PERLEXT')
rpm-build 95f51c
	self.env.cshlib_PATTERN = self.env.cxxshlib_PATTERN = self.env.perlext_PATTERN
rpm-build 95f51c
rpm-build 95f51c
@extension('.xs')
rpm-build 95f51c
def xsubpp_file(self, node):
rpm-build 95f51c
	"""
rpm-build 95f51c
	Create :py:class:`waflib.Tools.perl.xsubpp` tasks to process *.xs* files
rpm-build 95f51c
	"""
rpm-build 95f51c
	outnode = node.change_ext('.c')
rpm-build 95f51c
	self.create_task('xsubpp', node, outnode)
rpm-build 95f51c
	self.source.append(outnode)
rpm-build 95f51c
rpm-build 95f51c
class xsubpp(Task.Task):
rpm-build 95f51c
	"""
rpm-build 95f51c
	Process *.xs* files
rpm-build 95f51c
	"""
rpm-build 95f51c
	run_str = '${PERL} ${XSUBPP} -noprototypes -typemap ${EXTUTILS_TYPEMAP} ${SRC} > ${TGT}'
rpm-build 95f51c
	color   = 'BLUE'
rpm-build 95f51c
	ext_out = ['.h']
rpm-build 95f51c
rpm-build 95f51c
@conf
rpm-build 95f51c
def check_perl_version(self, minver=None):
rpm-build 95f51c
	"""
rpm-build 95f51c
	Check if Perl is installed, and set the variable PERL.
rpm-build 95f51c
	minver is supposed to be a tuple
rpm-build 95f51c
	"""
rpm-build 95f51c
	res = True
rpm-build 95f51c
	if minver:
rpm-build 95f51c
		cver = '.'.join(map(str,minver))
rpm-build 95f51c
	else:
rpm-build 95f51c
		cver = ''
rpm-build 95f51c
rpm-build 95f51c
	self.start_msg('Checking for minimum perl version %s' % cver)
rpm-build 95f51c
rpm-build 95f51c
	perl = self.find_program('perl', var='PERL', value=getattr(Options.options, 'perlbinary', None))
rpm-build 95f51c
	version = self.cmd_and_log(perl + ["-e", 'printf \"%vd\", $^V'])
rpm-build 95f51c
	if not version:
rpm-build 95f51c
		res = False
rpm-build 95f51c
		version = "Unknown"
rpm-build 95f51c
	elif not minver is None:
rpm-build 95f51c
		ver = tuple(map(int, version.split(".")))
rpm-build 95f51c
		if ver < minver:
rpm-build 95f51c
			res = False
rpm-build 95f51c
rpm-build 95f51c
	self.end_msg(version, color=res and 'GREEN' or 'YELLOW')
rpm-build 95f51c
	return res
rpm-build 95f51c
rpm-build 95f51c
@conf
rpm-build 95f51c
def check_perl_module(self, module):
rpm-build 95f51c
	"""
rpm-build 95f51c
	Check if specified perlmodule is installed.
rpm-build 95f51c
rpm-build 95f51c
	The minimum version can be specified by specifying it after modulename
rpm-build 95f51c
	like this::
rpm-build 95f51c
rpm-build 95f51c
		def configure(conf):
rpm-build 95f51c
			conf.check_perl_module("Some::Module 2.92")
rpm-build 95f51c
	"""
rpm-build 95f51c
	cmd = self.env.PERL + ['-e', 'use %s' % module]
rpm-build 95f51c
	self.start_msg('perl module %s' % module)
rpm-build 95f51c
	try:
rpm-build 95f51c
		r = self.cmd_and_log(cmd)
rpm-build 95f51c
	except Errors.WafError:
rpm-build 95f51c
		self.end_msg(False)
rpm-build 95f51c
		return None
rpm-build 95f51c
	self.end_msg(r or True)
rpm-build 95f51c
	return r
rpm-build 95f51c
rpm-build 95f51c
@conf
rpm-build 95f51c
def check_perl_ext_devel(self):
rpm-build 95f51c
	"""
rpm-build 95f51c
	Check for configuration needed to build perl extensions.
rpm-build 95f51c
rpm-build 95f51c
	Sets different xxx_PERLEXT variables in the environment.
rpm-build 95f51c
rpm-build 95f51c
	Also sets the ARCHDIR_PERL variable useful as installation path,
rpm-build 95f51c
	which can be overridden by ``--with-perl-archdir`` option.
rpm-build 95f51c
	"""
rpm-build 95f51c
rpm-build 95f51c
	env = self.env
rpm-build 95f51c
	perl = env.PERL
rpm-build 95f51c
	if not perl:
rpm-build 95f51c
		self.fatal('find perl first')
rpm-build 95f51c
rpm-build 95f51c
	def cmd_perl_config(s):
rpm-build 95f51c
		return perl + ['-MConfig', '-e', 'print \"%s\"' % s]
rpm-build 95f51c
	def cfg_str(cfg):
rpm-build 95f51c
		return self.cmd_and_log(cmd_perl_config(cfg))
rpm-build 95f51c
	def cfg_lst(cfg):
rpm-build 95f51c
		return Utils.to_list(cfg_str(cfg))
rpm-build 95f51c
	def find_xsubpp():
rpm-build 95f51c
		for var in ('privlib', 'vendorlib'):
rpm-build 95f51c
			xsubpp = cfg_lst('$Config{%s}/ExtUtils/xsubpp$Config{exe_ext}' % var)
rpm-build 95f51c
			if xsubpp and os.path.isfile(xsubpp[0]):
rpm-build 95f51c
				return xsubpp
rpm-build 95f51c
		return self.find_program('xsubpp')
rpm-build 95f51c
rpm-build 95f51c
	env.LINKFLAGS_PERLEXT = cfg_lst('$Config{lddlflags}')
rpm-build 95f51c
	env.INCLUDES_PERLEXT = cfg_lst('$Config{archlib}/CORE')
rpm-build 95f51c
	env.CFLAGS_PERLEXT = cfg_lst('$Config{ccflags} $Config{cccdlflags}')
rpm-build 95f51c
	env.EXTUTILS_TYPEMAP = cfg_lst('$Config{privlib}/ExtUtils/typemap')
rpm-build 95f51c
	env.XSUBPP = find_xsubpp()
rpm-build 95f51c
rpm-build 95f51c
	if not getattr(Options.options, 'perlarchdir', None):
rpm-build 95f51c
		env.ARCHDIR_PERL = cfg_str('$Config{sitearch}')
rpm-build 95f51c
	else:
rpm-build 95f51c
		env.ARCHDIR_PERL = getattr(Options.options, 'perlarchdir')
rpm-build 95f51c
rpm-build 95f51c
	env.perlext_PATTERN = '%s.' + cfg_str('$Config{dlext}')
rpm-build 95f51c
rpm-build 95f51c
def options(opt):
rpm-build 95f51c
	"""
rpm-build 95f51c
	Add the ``--with-perl-archdir`` and ``--with-perl-binary`` command-line options.
rpm-build 95f51c
	"""
rpm-build 95f51c
	opt.add_option('--with-perl-binary', type='string', dest='perlbinary', help = 'Specify alternate perl binary', default=None)
rpm-build 95f51c
	opt.add_option('--with-perl-archdir', type='string', dest='perlarchdir', help = 'Specify directory where to install arch specific files', default=None)
rpm-build 95f51c