fc_pgfortran.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # harald at klimachs.de
  4. import re
  5. from waflib.Tools import fc, fc_config, fc_scan
  6. from waflib.Configure import conf
  7. from waflib.Tools.compiler_fc import fc_compiler
  8. fc_compiler['linux'].append('fc_pgfortran')
  9. @conf
  10. def find_pgfortran(conf):
  11. """Find the PGI fortran compiler (will look in the environment variable 'FC')"""
  12. fc = conf.find_program(['pgfortran', 'pgf95', 'pgf90'], var='FC')
  13. conf.get_pgfortran_version(fc)
  14. conf.env.FC_NAME = 'PGFC'
  15. @conf
  16. def pgfortran_flags(conf):
  17. v = conf.env
  18. v['FCFLAGS_fcshlib'] = ['-shared']
  19. v['FCFLAGS_DEBUG'] = ['-Minform=inform', '-Mstandard'] # why not
  20. v['FCSTLIB_MARKER'] = '-Bstatic'
  21. v['FCSHLIB_MARKER'] = '-Bdynamic'
  22. v['SONAME_ST'] = '-soname %s'
  23. @conf
  24. def get_pgfortran_version(conf,fc):
  25. version_re = re.compile(r"The Portland Group", re.I).search
  26. cmd = fc + ['-V']
  27. out,err = fc_config.getoutput(conf, cmd, stdin=False)
  28. if out:
  29. match = version_re(out)
  30. else:
  31. match = version_re(err)
  32. if not match:
  33. conf.fatal('Could not verify PGI signature')
  34. cmd = fc + ['-help=variable']
  35. out,err = fc_config.getoutput(conf, cmd, stdin=False)
  36. if out.find('COMPVER')<0:
  37. conf.fatal('Could not determine the compiler type')
  38. k = {}
  39. prevk = ''
  40. out = out.splitlines()
  41. for line in out:
  42. lst = line.partition('=')
  43. if lst[1] == '=':
  44. key = lst[0].rstrip()
  45. if key == '':
  46. key = prevk
  47. val = lst[2].rstrip()
  48. k[key] = val
  49. else:
  50. prevk = line.partition(' ')[0]
  51. def isD(var):
  52. return var in k
  53. def isT(var):
  54. return var in k and k[var]!='0'
  55. conf.env['FC_VERSION'] = (k['COMPVER'].split('.'))
  56. def configure(conf):
  57. conf.find_pgfortran()
  58. conf.find_ar()
  59. conf.fc_flags()
  60. conf.fc_add_flags()
  61. conf.pgfortran_flags()