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