from os.path import join as pjoin

from numscons import GetNumpyEnvironment
from numscons import CheckF77BLAS, CheckF77Clib, NumpyCheckLibAndHeader
from numscons import write_info

env = GetNumpyEnvironment(ARGUMENTS)

#=======================
# Starting Configuration
#=======================
config = env.NumpyConfigure(custom_tests = 
    {'CheckBLAS' : CheckF77BLAS,
     'CheckF77Clib' : CheckF77Clib,
     'NumpyCheckLibAndHeader' : NumpyCheckLibAndHeader})

#-----------------
# Checking Lapack
#-----------------
st = config.CheckBLAS()
if not st:
    raise RuntimeError("no blas found, necessary for umfpack module")

has_umfpack = config.NumpyCheckLibAndHeader(
    'umfpack', None, 'umfpack.h', section = 'umfpack', autoadd = 1)
config.Finish()
write_info(env)

if has_umfpack:
    env.Append(SWIGFLAGS = '-python')
    env.Append(SWIGFLAGS = '$_CPPINCFLAGS')
    env.NumpyPythonExtension('__umfpack', source = 'umfpack.i') 
