pgicc.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Antoine Dechaume 2011
  4. """
  5. Detect the PGI C compiler
  6. """
  7. import sys, re
  8. from waflib import Errors
  9. from waflib.Configure import conf
  10. from waflib.Tools.compiler_c import c_compiler
  11. c_compiler['linux'].append('pgicc')
  12. @conf
  13. def find_pgi_compiler(conf, var, name):
  14. """
  15. Find the program name, and execute it to ensure it really is itself.
  16. """
  17. if sys.platform == 'cygwin':
  18. conf.fatal('The PGI compiler does not work on Cygwin')
  19. v = conf.env
  20. cc = None
  21. if v[var]:
  22. cc = v[var]
  23. elif var in conf.environ:
  24. cc = conf.environ[var]
  25. if not cc:
  26. cc = conf.find_program(name, var=var)
  27. if not cc:
  28. conf.fatal('PGI Compiler (%s) was not found' % name)
  29. v[var + '_VERSION'] = conf.get_pgi_version(cc)
  30. v[var] = cc
  31. v[var + '_NAME'] = 'pgi'
  32. @conf
  33. def get_pgi_version(conf, cc):
  34. """Find the version of a pgi compiler."""
  35. version_re = re.compile(r"The Portland Group", re.I).search
  36. cmd = cc + ['-V', '-E'] # Issue 1078, prevent wrappers from linking
  37. try:
  38. out, err = conf.cmd_and_log(cmd, output=0)
  39. except Errors.WafError:
  40. conf.fatal('Could not find pgi compiler %r' % cmd)
  41. if out:
  42. match = version_re(out)
  43. else:
  44. match = version_re(err)
  45. if not match:
  46. conf.fatal('Could not verify PGI signature')
  47. cmd = cc + ['-help=variable']
  48. try:
  49. out, err = conf.cmd_and_log(cmd, output=0)
  50. except Errors.WafError:
  51. conf.fatal('Could not find pgi compiler %r' % cmd)
  52. version = re.findall('^COMPVER\s*=(.*)', out, re.M)
  53. if len(version) != 1:
  54. conf.fatal('Could not determine the compiler version')
  55. return version[0]
  56. def configure(conf):
  57. conf.find_pgi_compiler('CC', 'pgcc')
  58. conf.find_ar()
  59. conf.gcc_common_flags()
  60. conf.cc_load_tools()
  61. conf.cc_add_flags()
  62. conf.link_add_flags()