fc_nag.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # harald at klimachs.de
  4. import re
  5. from waflib import Utils
  6. from waflib.Tools import fc,fc_config,fc_scan
  7. from waflib.Configure import conf
  8. from waflib.Tools.compiler_fc import fc_compiler
  9. fc_compiler['linux'].insert(0, 'fc_nag')
  10. @conf
  11. def find_nag(conf):
  12. """Find the NAG Fortran Compiler (will look in the environment variable 'FC')"""
  13. fc = conf.find_program(['nagfor'], var='FC')
  14. conf.get_nag_version(fc)
  15. conf.env.FC_NAME = 'NAG'
  16. conf.env.FC_MOD_CAPITALIZATION = 'lower'
  17. @conf
  18. def nag_flags(conf):
  19. v = conf.env
  20. v.FCFLAGS_DEBUG = ['-C=all']
  21. v.FCLNK_TGT_F = ['-o', '']
  22. v.FC_TGT_F = ['-c', '-o', '']
  23. @conf
  24. def nag_modifier_platform(conf):
  25. dest_os = conf.env['DEST_OS'] or Utils.unversioned_sys_platform()
  26. nag_modifier_func = getattr(conf, 'nag_modifier_' + dest_os, None)
  27. if nag_modifier_func:
  28. nag_modifier_func()
  29. @conf
  30. def get_nag_version(conf, fc):
  31. """Get the NAG compiler version"""
  32. version_re = re.compile(r"^NAG Fortran Compiler *Release *(?P<major>\d*)\.(?P<minor>\d*)", re.M).search
  33. cmd = fc + ['-V']
  34. out, err = fc_config.getoutput(conf,cmd,stdin=False)
  35. if out:
  36. match = version_re(out)
  37. if not match:
  38. match = version_re(err)
  39. else: match = version_re(err)
  40. if not match:
  41. conf.fatal('Could not determine the NAG version.')
  42. k = match.groupdict()
  43. conf.env['FC_VERSION'] = (k['major'], k['minor'])
  44. def configure(conf):
  45. conf.find_nag()
  46. conf.find_ar()
  47. conf.fc_flags()
  48. conf.fc_add_flags()
  49. conf.nag_flags()
  50. conf.nag_modifier_platform()