jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
4.5KB

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # andersg at 0x63.nu 2007
  4. # Thomas Nagy 2010 (ita)
  5. """
  6. Support for Perl extensions. A C/C++ compiler is required::
  7. def options(opt):
  8. opt.load('compiler_c perl')
  9. def configure(conf):
  10. conf.load('compiler_c perl')
  11. conf.check_perl_version((5,6,0))
  12. conf.check_perl_ext_devel()
  13. conf.check_perl_module('Cairo')
  14. conf.check_perl_module('Devel::PPPort 4.89')
  15. def build(bld):
  16. bld(
  17. features = 'c cshlib perlext',
  18. source = 'Mytest.xs',
  19. target = 'Mytest',
  20. install_path = '${ARCHDIR_PERL}/auto')
  21. bld.install_files('${ARCHDIR_PERL}', 'Mytest.pm')
  22. """
  23. import os
  24. from waflib import Task, Options, Utils
  25. from waflib.Configure import conf
  26. from waflib.TaskGen import extension, feature, before_method
  27. @before_method('apply_incpaths', 'apply_link', 'propagate_uselib_vars')
  28. @feature('perlext')
  29. def init_perlext(self):
  30. """
  31. Change the values of *cshlib_PATTERN* and *cxxshlib_PATTERN* to remove the
  32. *lib* prefix from library names.
  33. """
  34. self.uselib = self.to_list(getattr(self, 'uselib', []))
  35. if not 'PERLEXT' in self.uselib: self.uselib.append('PERLEXT')
  36. self.env['cshlib_PATTERN'] = self.env['cxxshlib_PATTERN'] = self.env['perlext_PATTERN']
  37. @extension('.xs')
  38. def xsubpp_file(self, node):
  39. """
  40. Create :py:class:`waflib.Tools.perl.xsubpp` tasks to process *.xs* files
  41. """
  42. outnode = node.change_ext('.c')
  43. self.create_task('xsubpp', node, outnode)
  44. self.source.append(outnode)
  45. class xsubpp(Task.Task):
  46. """
  47. Process *.xs* files
  48. """
  49. run_str = '${PERL} ${XSUBPP} -noprototypes -typemap ${EXTUTILS_TYPEMAP} ${SRC} > ${TGT}'
  50. color = 'BLUE'
  51. ext_out = ['.h']
  52. @conf
  53. def check_perl_version(self, minver=None):
  54. """
  55. Check if Perl is installed, and set the variable PERL.
  56. minver is supposed to be a tuple
  57. """
  58. res = True
  59. if minver:
  60. cver = '.'.join(map(str,minver))
  61. else:
  62. cver = ''
  63. self.start_msg('Checking for minimum perl version %s' % cver)
  64. perl = getattr(Options.options, 'perlbinary', None)
  65. if not perl:
  66. perl = self.find_program('perl', var='PERL')
  67. if not perl:
  68. self.end_msg("Perl not found", color="YELLOW")
  69. return False
  70. self.env['PERL'] = perl
  71. version = self.cmd_and_log(self.env.PERL + ["-e", 'printf \"%vd\", $^V'])
  72. if not version:
  73. res = False
  74. version = "Unknown"
  75. elif not minver is None:
  76. ver = tuple(map(int, version.split(".")))
  77. if ver < minver:
  78. res = False
  79. self.end_msg(version, color=res and "GREEN" or "YELLOW")
  80. return res
  81. @conf
  82. def check_perl_module(self, module):
  83. """
  84. Check if specified perlmodule is installed.
  85. The minimum version can be specified by specifying it after modulename
  86. like this::
  87. def configure(conf):
  88. conf.check_perl_module("Some::Module 2.92")
  89. """
  90. cmd = self.env.PERL + ['-e', 'use %s' % module]
  91. self.start_msg('perl module %s' % module)
  92. try:
  93. r = self.cmd_and_log(cmd)
  94. except Exception:
  95. self.end_msg(False)
  96. return None
  97. self.end_msg(r or True)
  98. return r
  99. @conf
  100. def check_perl_ext_devel(self):
  101. """
  102. Check for configuration needed to build perl extensions.
  103. Sets different xxx_PERLEXT variables in the environment.
  104. Also sets the ARCHDIR_PERL variable useful as installation path,
  105. which can be overridden by ``--with-perl-archdir`` option.
  106. """
  107. env = self.env
  108. perl = env.PERL
  109. if not perl:
  110. self.fatal('find perl first')
  111. def cmd_perl_config(s):
  112. return perl + ['-MConfig', '-e', 'print \"%s\"' % s]
  113. def cfg_str(cfg):
  114. return self.cmd_and_log(cmd_perl_config(cfg))
  115. def cfg_lst(cfg):
  116. return Utils.to_list(cfg_str(cfg))
  117. def find_xsubpp():
  118. for var in ('privlib', 'vendorlib'):
  119. xsubpp = cfg_lst('$Config{%s}/ExtUtils/xsubpp$Config{exe_ext}' % var)
  120. if xsubpp and os.path.isfile(xsubpp[0]):
  121. return xsubpp
  122. return self.find_program('xsubpp')
  123. env['LINKFLAGS_PERLEXT'] = cfg_lst('$Config{lddlflags}')
  124. env['INCLUDES_PERLEXT'] = cfg_lst('$Config{archlib}/CORE')
  125. env['CFLAGS_PERLEXT'] = cfg_lst('$Config{ccflags} $Config{cccdlflags}')
  126. env['EXTUTILS_TYPEMAP'] = cfg_lst('$Config{privlib}/ExtUtils/typemap')
  127. env['XSUBPP'] = find_xsubpp()
  128. if not getattr(Options.options, 'perlarchdir', None):
  129. env['ARCHDIR_PERL'] = cfg_str('$Config{sitearch}')
  130. else:
  131. env['ARCHDIR_PERL'] = getattr(Options.options, 'perlarchdir')
  132. env['perlext_PATTERN'] = '%s.' + cfg_str('$Config{dlext}')
  133. def options(opt):
  134. """
  135. Add the ``--with-perl-archdir`` and ``--with-perl-binary`` command-line options.
  136. """
  137. opt.add_option('--with-perl-binary', type='string', dest='perlbinary', help = 'Specify alternate perl binary', default=None)
  138. opt.add_option('--with-perl-archdir', type='string', dest='perlarchdir', help = 'Specify directory where to install arch specific files', default=None)