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'].append('fc_solstudio')
12
13@conf
14def find_solstudio(conf):
15	"""Find the Solaris Studio compiler (will look in the environment variable 'FC')"""
16
17	fc = conf.find_program(['sunf95', 'f95', 'sunf90', 'f90'], var='FC')
18	conf.get_solstudio_version(fc)
19	conf.env.FC_NAME = 'SOL'
20
21@conf
22def solstudio_flags(conf):
23	v = conf.env
24	v['FCFLAGS_fcshlib'] = ['-Kpic']
25	v['FCFLAGS_DEBUG'] = ['-w3']
26	v['LINKFLAGS_fcshlib'] = ['-G']
27	v['FCSTLIB_MARKER'] = '-Bstatic'
28	v['FCSHLIB_MARKER'] = '-Bdynamic'
29	v['SONAME_ST']      = '-h %s'
30
31@conf
32def solstudio_modifier_platform(conf):
33	dest_os = conf.env['DEST_OS'] or Utils.unversioned_sys_platform()
34	solstudio_modifier_func = getattr(conf, 'solstudio_modifier_' + dest_os, None)
35	if solstudio_modifier_func:
36		solstudio_modifier_func()
37
38@conf
39def get_solstudio_version(conf, fc):
40	"""Get the compiler version"""
41
42	version_re = re.compile(r"Sun Fortran 95 *(?P<major>\d*)\.(?P<minor>\d*)", re.I).search
43	cmd = fc + ['-V']
44
45	out, err = fc_config.getoutput(conf,cmd,stdin=False)
46	if out:
47		match = version_re(out)
48	else:
49		match = version_re(err)
50	if not match:
51		conf.fatal('Could not determine the Sun Studio Fortran version.')
52	k = match.groupdict()
53	conf.env['FC_VERSION'] = (k['major'], k['minor'])
54
55def configure(conf):
56	conf.find_solstudio()
57	conf.find_ar()
58	conf.fc_flags()
59	conf.fc_add_flags()
60	conf.solstudio_flags()
61	conf.solstudio_modifier_platform()
62
63