gfortran.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # DC 2008
  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_gfortran(conf):
  11. """Find the gfortran program (will look in the environment variable 'FC')"""
  12. fc = conf.find_program(['gfortran','g77'], var='FC')
  13. # (fallback to g77 for systems, where no gfortran is available)
  14. conf.get_gfortran_version(fc)
  15. conf.env.FC_NAME = 'GFORTRAN'
  16. @conf
  17. def gfortran_flags(conf):
  18. v = conf.env
  19. v.FCFLAGS_fcshlib = ['-fPIC']
  20. v.FORTRANMODFLAG = ['-J', ''] # template for module path
  21. v.FCFLAGS_DEBUG = ['-Werror'] # why not
  22. @conf
  23. def gfortran_modifier_win32(conf):
  24. fc_config.fortran_modifier_win32(conf)
  25. @conf
  26. def gfortran_modifier_cygwin(conf):
  27. fc_config.fortran_modifier_cygwin(conf)
  28. @conf
  29. def gfortran_modifier_darwin(conf):
  30. fc_config.fortran_modifier_darwin(conf)
  31. @conf
  32. def gfortran_modifier_platform(conf):
  33. dest_os = conf.env.DEST_OS or Utils.unversioned_sys_platform()
  34. gfortran_modifier_func = getattr(conf, 'gfortran_modifier_' + dest_os, None)
  35. if gfortran_modifier_func:
  36. gfortran_modifier_func()
  37. @conf
  38. def get_gfortran_version(conf, fc):
  39. """Get the compiler version"""
  40. # ensure this is actually gfortran, not an imposter.
  41. version_re = re.compile(r"GNU\s*Fortran", re.I).search
  42. cmd = fc + ['--version']
  43. out, err = fc_config.getoutput(conf, cmd, stdin=False)
  44. if out:
  45. match = version_re(out)
  46. else:
  47. match = version_re(err)
  48. if not match:
  49. conf.fatal('Could not determine the compiler type')
  50. # --- now get more detailed info -- see c_config.get_cc_version
  51. cmd = fc + ['-dM', '-E', '-']
  52. out, err = fc_config.getoutput(conf, cmd, stdin=True)
  53. if out.find('__GNUC__') < 0:
  54. conf.fatal('Could not determine the compiler type')
  55. k = {}
  56. out = out.splitlines()
  57. import shlex
  58. for line in out:
  59. lst = shlex.split(line)
  60. if len(lst)>2:
  61. key = lst[1]
  62. val = lst[2]
  63. k[key] = val
  64. def isD(var):
  65. return var in k
  66. def isT(var):
  67. return var in k and k[var] != '0'
  68. conf.env.FC_VERSION = (k['__GNUC__'], k['__GNUC_MINOR__'], k['__GNUC_PATCHLEVEL__'])
  69. def configure(conf):
  70. conf.find_gfortran()
  71. conf.find_ar()
  72. conf.fc_flags()
  73. conf.fc_add_flags()
  74. conf.gfortran_flags()
  75. conf.gfortran_modifier_platform()
  76. conf.check_gfortran_o_space()