1#! /usr/bin/env python
2# encoding: utf-8
3# harald at klimachs.de
4
5import re
6from waflib.Tools import fc, fc_config, fc_scan
7from waflib.Configure import conf
8
9from waflib.Tools.compiler_fc import fc_compiler
10fc_compiler['linux'].append('fc_nec')
11
12@conf
13def find_sxfc(conf):
14	"""Find the NEC fortran compiler (will look in the environment variable 'FC')"""
15	fc = conf.find_program(['sxf90','sxf03'], var='FC')
16	conf.get_sxfc_version(fc)
17	conf.env.FC_NAME = 'NEC'
18	conf.env.FC_MOD_CAPITALIZATION = 'lower'
19
20@conf
21def sxfc_flags(conf):
22	v = conf.env
23	v['_FCMODOUTFLAGS']  = [] # enable module files and put them in the current directory
24	v['FCFLAGS_DEBUG'] = [] # more verbose compiler warnings
25	v['FCFLAGS_fcshlib']   = []
26	v['LINKFLAGS_fcshlib'] = []
27
28	v['FCSTLIB_MARKER'] = ''
29	v['FCSHLIB_MARKER'] = ''
30
31@conf
32def get_sxfc_version(conf, fc):
33	version_re = re.compile(r"FORTRAN90/SX\s*Version\s*(?P<major>\d*)\.(?P<minor>\d*)", re.I).search
34	cmd = fc + ['-V']
35	out,err = fc_config.getoutput(conf, cmd, stdin=False)
36	if out:
37		match = version_re(out)
38	else:
39		match = version_re(err)
40	if not match:
41		version_re=re.compile(r"NEC Fortran 2003 Compiler for\s*(?P<major>\S*)\s*\(c\)\s*(?P<minor>\d*)",re.I).search
42		if out:
43			match = version_re(out)
44		else:
45			match = version_re(err)
46		if not match:
47			conf.fatal('Could not determine the NEC Fortran compiler version.')
48	k = match.groupdict()
49	conf.env['FC_VERSION'] = (k['major'], k['minor'])
50
51def configure(conf):
52	conf.find_sxfc()
53	conf.find_program('sxar',var='AR')
54	conf.add_os_flags('ARFLAGS')
55	if not conf.env.ARFLAGS:
56		conf.env.ARFLAGS=['rcs']
57
58	conf.fc_flags()
59	conf.fc_add_flags()
60	conf.sxfc_flags()
61