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