95 lines
2.8 KiB
Python
95 lines
2.8 KiB
Python
from sysconfig import get_config_var
|
|
import os
|
|
|
|
# Define the command line options
|
|
AddOption('--dbg',
|
|
dest='dbg',
|
|
action='store_true',
|
|
help='add debugging symbols')
|
|
|
|
AddOption('--verbose',
|
|
dest='verbose',
|
|
action='store_true',
|
|
help='add debugging symbols')
|
|
|
|
AddOption('--compiler',
|
|
dest='compiler',
|
|
default='gfortran',
|
|
choices=['gfortran', 'ifort'],
|
|
help='The Fortran compiler to use')
|
|
|
|
def CheckPKGConfig(context, version):
|
|
context.Message( 'Checking for pkg-config... ' )
|
|
ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
|
|
context.Result( ret )
|
|
return ret
|
|
|
|
def CheckPKG(context, name):
|
|
context.Message( 'Checking for %s... ' % name )
|
|
ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
|
|
context.Result( ret )
|
|
return ret
|
|
|
|
def filtered_glob(env, pattern, omit=[],
|
|
ondisk=True, source=False, strings=False):
|
|
return list(filter(
|
|
lambda f: os.path.basename(f.path) not in omit,
|
|
env.Glob(pattern)))
|
|
|
|
|
|
|
|
# define the default build environment
|
|
std = Environment(tools=['default', 'fortran'], F2PY_OPTS=[], FORTRANCOMSTR = "building $TARGET ...", LIBS=[])
|
|
std.AddMethod(filtered_glob, "FilteredGlob");
|
|
|
|
# define environments
|
|
gfortran_env = std.Clone(tools=['gfortran'])
|
|
gfortran_env.Replace(FORTRANFLAGS=['-fPIC', '-O2', '-ffast-math', '-fno-automatic'])
|
|
|
|
ifort_env = std.Clone(tools=['ifort'])
|
|
|
|
# parse options
|
|
if GetOption('compiler') == 'gfortran':
|
|
env = gfortran_env
|
|
elif GetOption('compiler') == 'ifort':
|
|
env = ifort_env
|
|
|
|
if GetOption('dbg'):
|
|
gfortran_env.Append(FORTRANFLAGS = ['-g', '-Wall', '-Wextra', '-Warray-temporaries',
|
|
'-Wconversion', '-fbacktrace', '-ffree-line-length-0',
|
|
'-fcheck=all', '-ffpe-trap=zero,overflow,underflow',
|
|
'-finit-real=nan'],
|
|
F2PY_OPTS = ['--debug-capi', '--debug'])
|
|
|
|
if GetOption('verbose'):
|
|
env.Replace(FORTRANCOMSTR = "")
|
|
|
|
|
|
conf = Configure(env, custom_tests = { 'CheckPKG' : CheckPKG})
|
|
suffix = get_config_var('EXT_SUFFIX')
|
|
|
|
# Create a builder for f2py
|
|
def create_f2py_cmd(source, target, env, for_signature):
|
|
objects = source[1:]
|
|
cmd = "f2py3 "
|
|
cmd += " ".join([o.get_path() for o in objects if str(o).endswith('o')])
|
|
cmd += f" $F2PY_OPTS -m {str(target[0]).replace(suffix,'').replace('/', '.')} -c {source[0]}"
|
|
return cmd
|
|
|
|
def modify_targets(target, source, env):
|
|
target[0] = str(target[0]) + suffix
|
|
#print(target[0])
|
|
return target, source
|
|
|
|
bld = Builder(generator=create_f2py_cmd, emitter = modify_targets)
|
|
env['BUILDERS']['F2PY'] = bld
|
|
|
|
|
|
|
|
# exports
|
|
Export('env', 'conf')
|
|
|
|
|
|
SConscript(['src/msspec/spec/fortran/SConstruct',
|
|
'src/msspec/phagen/fortran/SConstruct'])
|