third_party:waf: update to upstream 2.0.4 release
[bbaumbach/samba-autobuild/.git] / third_party / waf / waflib / extras / fc_nag.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 # harald at klimachs.de
8
9 import re
10 from waflib import Utils
11 from waflib.Tools import fc,fc_config,fc_scan
12 from waflib.Configure import conf
13
14 from waflib.Tools.compiler_fc import fc_compiler
15 fc_compiler['linux'].insert(0, 'fc_nag')
16
17 @conf
18 def find_nag(conf):
19         """Find the NAG Fortran Compiler (will look in the environment variable 'FC')"""
20
21         fc = conf.find_program(['nagfor'], var='FC')
22         conf.get_nag_version(fc)
23         conf.env.FC_NAME = 'NAG'
24         conf.env.FC_MOD_CAPITALIZATION = 'lower'
25
26 @conf
27 def nag_flags(conf):
28         v = conf.env
29         v.FCFLAGS_DEBUG = ['-C=all']
30         v.FCLNK_TGT_F = ['-o', '']
31         v.FC_TGT_F = ['-c', '-o', '']
32
33 @conf
34 def nag_modifier_platform(conf):
35         dest_os = conf.env['DEST_OS'] or Utils.unversioned_sys_platform()
36         nag_modifier_func = getattr(conf, 'nag_modifier_' + dest_os, None)
37         if nag_modifier_func:
38                 nag_modifier_func()
39
40 @conf
41 def get_nag_version(conf, fc):
42         """Get the NAG compiler version"""
43
44         version_re = re.compile(r"^NAG Fortran Compiler *Release *(?P<major>\d*)\.(?P<minor>\d*)", re.M).search
45         cmd = fc + ['-V']
46
47         out, err = fc_config.getoutput(conf,cmd,stdin=False)
48         if out:
49                 match = version_re(out)
50                 if not match:
51                         match = version_re(err)
52         else: match = version_re(err)
53         if not match:
54                 conf.fatal('Could not determine the NAG version.')
55         k = match.groupdict()
56         conf.env['FC_VERSION'] = (k['major'], k['minor'])
57
58 def configure(conf):
59         conf.find_nag()
60         conf.find_ar()
61         conf.fc_flags()
62         conf.fc_add_flags()
63         conf.nag_flags()
64         conf.nag_modifier_platform()
65