compiler_fc.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. import re
  4. from waflib import Utils, Logs
  5. from waflib.Tools import fc
  6. fc_compiler = {
  7. 'win32' : ['gfortran','ifort'],
  8. 'darwin' : ['gfortran', 'g95', 'ifort'],
  9. 'linux' : ['gfortran', 'g95', 'ifort'],
  10. 'java' : ['gfortran', 'g95', 'ifort'],
  11. 'default': ['gfortran'],
  12. 'aix' : ['gfortran']
  13. }
  14. """
  15. Dict mapping the platform names to lists of names of Fortran compilers to try, in order of preference::
  16. from waflib.Tools.compiler_c import c_compiler
  17. c_compiler['linux'] = ['gfortran', 'g95', 'ifort']
  18. """
  19. def default_compilers():
  20. build_platform = Utils.unversioned_sys_platform()
  21. possible_compiler_list = fc_compiler.get(build_platform, fc_compiler['default'])
  22. return ' '.join(possible_compiler_list)
  23. def configure(conf):
  24. """
  25. Detects a suitable Fortran compiler
  26. :raises: :py:class:`waflib.Errors.ConfigurationError` when no suitable compiler is found
  27. """
  28. try:
  29. test_for_compiler = conf.options.check_fortran_compiler or default_compilers()
  30. except AttributeError:
  31. conf.fatal("Add options(opt): opt.load('compiler_fc')")
  32. for compiler in re.split('[ ,]+', test_for_compiler):
  33. conf.env.stash()
  34. conf.start_msg('Checking for %r (Fortran compiler)' % compiler)
  35. try:
  36. conf.load(compiler)
  37. except conf.errors.ConfigurationError as e:
  38. conf.env.revert()
  39. conf.end_msg(False)
  40. Logs.debug('compiler_fortran: %r', e)
  41. else:
  42. if conf.env.FC:
  43. conf.end_msg(conf.env.get_flat('FC'))
  44. conf.env.COMPILER_FORTRAN = compiler
  45. conf.env.commit()
  46. break
  47. conf.env.revert()
  48. conf.end_msg(False)
  49. else:
  50. conf.fatal('could not configure a Fortran compiler!')
  51. def options(opt):
  52. """
  53. This is how to provide compiler preferences on the command-line::
  54. $ waf configure --check-fortran-compiler=ifort
  55. """
  56. test_for_compiler = default_compilers()
  57. opt.load_special_tools('fc_*.py')
  58. fortran_compiler_opts = opt.add_option_group('Configuration options')
  59. fortran_compiler_opts.add_option('--check-fortran-compiler', default=None,
  60. help='list of Fortran compiler to try [%s]' % test_for_compiler,
  61. dest="check_fortran_compiler")
  62. for x in test_for_compiler.split():
  63. opt.load('%s' % x)