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