g95.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # KWS 2010
  4. # Thomas Nagy 2016-2018 (ita)
  5. import re
  6. from waflib import Utils
  7. from waflib.Tools import fc, fc_config, fc_scan, ar
  8. from waflib.Configure import conf
  9. @conf
  10. def find_g95(conf):
  11. fc = conf.find_program('g95', var='FC')
  12. conf.get_g95_version(fc)
  13. conf.env.FC_NAME = 'G95'
  14. @conf
  15. def g95_flags(conf):
  16. v = conf.env
  17. v.FCFLAGS_fcshlib = ['-fPIC']
  18. v.FORTRANMODFLAG = ['-fmod=', ''] # template for module path
  19. v.FCFLAGS_DEBUG = ['-Werror'] # why not
  20. @conf
  21. def g95_modifier_win32(conf):
  22. fc_config.fortran_modifier_win32(conf)
  23. @conf
  24. def g95_modifier_cygwin(conf):
  25. fc_config.fortran_modifier_cygwin(conf)
  26. @conf
  27. def g95_modifier_darwin(conf):
  28. fc_config.fortran_modifier_darwin(conf)
  29. @conf
  30. def g95_modifier_platform(conf):
  31. dest_os = conf.env.DEST_OS or Utils.unversioned_sys_platform()
  32. g95_modifier_func = getattr(conf, 'g95_modifier_' + dest_os, None)
  33. if g95_modifier_func:
  34. g95_modifier_func()
  35. @conf
  36. def get_g95_version(conf, fc):
  37. """get the compiler version"""
  38. version_re = re.compile(r"g95\s*(?P<major>\d*)\.(?P<minor>\d*)").search
  39. cmd = fc + ['--version']
  40. out, err = fc_config.getoutput(conf, cmd, stdin=False)
  41. if out:
  42. match = version_re(out)
  43. else:
  44. match = version_re(err)
  45. if not match:
  46. conf.fatal('cannot determine g95 version')
  47. k = match.groupdict()
  48. conf.env.FC_VERSION = (k['major'], k['minor'])
  49. def configure(conf):
  50. conf.find_g95()
  51. conf.find_ar()
  52. conf.fc_flags()
  53. conf.fc_add_flags()
  54. conf.g95_flags()
  55. conf.g95_modifier_platform()