diff --git a/src/msspec/spec/fortran/SConstruct b/src/msspec/spec/fortran/SConstruct index 5791198..53ba2c0 100644 --- a/src/msspec/spec/fortran/SConstruct +++ b/src/msspec/spec/fortran/SConstruct @@ -1,7 +1,6 @@ from sysconfig import get_config_var import os -SetOption('silent', True) # Define the command line options AddOption('--dbg', dest='dbg', @@ -13,29 +12,57 @@ AddOption('--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 + + + # define environments -COMP_OPTS = ['-O2', '-ffast-math', '-fno-automatic'] -#std = Environment(tools=['default', 'gfortran'], FORTRAN='gfortran', -std = Environment(FORTRAN='gfortran', - FORTRANFLAGS=['-fPIC', '-O2', '-ffast-math', '-fno-automatic'], - F2PY_OPTS=[], - FORTRANCOMSTR = "building $TARGET ...") +std = Environment(tools=['default', 'fortran'], F2PY_OPTS=[], FORTRANCOMSTR = "building $TARGET ...") -dbg = std.Clone() -dbg.Append(FORTRANFLAGS = ['-g', '-Wall', '-Wextra', '-Warray-temporaries', '-Wconversion', '-fbacktrace', - '-ffree-line-length-0', '-fcheck=all', '-ffpe-trap=zero,overflow,underflow', - '-finit-real=nan']) -dbg.Append(F2PY_OPTS = ['--debug-capi', '--debug']) +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 -env = std if GetOption('dbg'): - env = 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'): - SetOption('silent', False) - #env.Replace(FORTRANCOMSTR = "") + env.Replace(FORTRANCOMSTR = "") +# Configuration: +conf = Configure(env, custom_tests = { 'CheckPKG' : CheckPKG}) + +if conf.CheckPKG('lapack'): + env.ParseConfig("pkg-config lapack --libs") + +conf.Finish() suffix = get_config_var('EXT_SUFFIX') @@ -52,6 +79,11 @@ sources = { 'eig_mi_src' : Glob('eig/mi/*.f'), 'eig_pw_src' : Glob('eig/pw/*.f')} +if 'lapack' in env['LIBS']: + env.Append(F2PY_OPTS = "-llapack") + for k,files in sources.items(): + sources[k] = [_ for _ in files if str(_).find('lapack') == -1] + objects = {} for k, v in sources.items(): objects[k.replace('_src', '_obj')] = env.Object(v) @@ -69,8 +101,11 @@ modules = {} for k, v in shared_objects.items(): cmd = "f2py3 -I. " + " ".join([str(_) for _ in objects if str(_).endswith('.o')]) + f"$F2PY_OPTS -c -m {k} $SOURCE" - cmd += " 1>/dev/null" - modules[k + suffix] = env.Command(k + suffix, v, Action(cmd, 'Building Python module $TARGET')) + cmd += "2>/dev/null 1>/dev/null" + modules[k + suffix] = env.Command(k + suffix, v, Action(cmd, '$FORTRANCOMSTR')) Requires(modules[k + suffix], objects.values()) +#for k,v in env.items(): +# print(k,v) +#exit()