third_party:waf: update to upstream 2.0.4 release
[samba.git] / third_party / waf / waflib / extras / fc_xlf.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,Errors
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['aix'].insert(0, 'fc_xlf')
16
17 @conf
18 def find_xlf(conf):
19         """Find the xlf program (will look in the environment variable 'FC')"""
20
21         fc = conf.find_program(['xlf2003_r', 'xlf2003', 'xlf95_r', 'xlf95', 'xlf90_r', 'xlf90', 'xlf_r', 'xlf'], var='FC')
22         conf.get_xlf_version(fc)
23         conf.env.FC_NAME='XLF'
24
25 @conf
26 def xlf_flags(conf):
27         v = conf.env
28         v['FCDEFINES_ST'] = '-WF,-D%s'
29         v['FCFLAGS_fcshlib'] = ['-qpic=small']
30         v['FCFLAGS_DEBUG'] = ['-qhalt=w']
31         v['LINKFLAGS_fcshlib'] = ['-Wl,-shared']
32
33 @conf
34 def xlf_modifier_platform(conf):
35         dest_os = conf.env['DEST_OS'] or Utils.unversioned_sys_platform()
36         xlf_modifier_func = getattr(conf, 'xlf_modifier_' + dest_os, None)
37         if xlf_modifier_func:
38                 xlf_modifier_func()
39
40 @conf
41 def get_xlf_version(conf, fc):
42         """Get the compiler version"""
43
44         cmd = fc + ['-qversion']
45         try:
46                 out, err = conf.cmd_and_log(cmd, output=0)
47         except Errors.WafError:
48                 conf.fatal('Could not find xlf %r' % cmd)
49
50         for v in (r"IBM XL Fortran.* V(?P<major>\d*)\.(?P<minor>\d*)",):
51                 version_re = re.compile(v, re.I).search
52                 match = version_re(out or err)
53                 if match:
54                         k = match.groupdict()
55                         conf.env['FC_VERSION'] = (k['major'], k['minor'])
56                         break
57         else:
58                 conf.fatal('Could not determine the XLF version.')
59
60 def configure(conf):
61         conf.find_xlf()
62         conf.find_ar()
63         conf.fc_flags()
64         conf.fc_add_flags()
65         conf.xlf_flags()
66         conf.xlf_modifier_platform()
67