# Last Change: Fri Oct 10 03:00 PM 2008 J
# vim:syntax=python
from os.path import join as pjoin

from numscons import GetNumpyEnvironment, CheckF77Clib, CheckF77Mangling

env = GetNumpyEnvironment(ARGUMENTS)
env.Tool('f2py')

config = env.NumpyConfigure(custom_tests = {'CheckF77Clib' : CheckF77Clib, 'CheckF77Mangling': CheckF77Mangling})
if not config.CheckF77Clib():
    raise Exception("Could not check F77 runtime, needed for interpolate")
config.CheckF77Mangling()
config.Finish()

# Build fitpack
src = [pjoin("fitpack", s) for s in ["bispev.f", "bispeu.f", "clocur.f",
"cocosp.f", "concon.f", "concur.f", "cualde.f", "curev.f", "curfit.f",
"dblint.f", "evapol.f", "fourco.f", "fpader.f", "fpadno.f", "fpadpo.f",
"fpback.f", "fpbacp.f", "fpbfout.f", "fpbisp.f", "fpbspl.f", "fpchec.f",
"fpched.f", "fpchep.f", "fpclos.f", "fpcoco.f", "fpcons.f", "fpcosp.f",
"fpcsin.f", "fpcurf.f", "fpcuro.f", "fpcyt1.f", "fpcyt2.f", "fpdeno.f",
"fpdisc.f", "fpfrno.f", "fpgivs.f", "fpgrdi.f", "fpgrpa.f", "fpgrre.f",
"fpgrsp.f", "fpinst.f", "fpintb.f", "fpknot.f", "fpopdi.f", "fpopsp.f",
"fporde.f", "fppara.f", "fppasu.f", "fpperi.f", "fppocu.f", "fppogr.f",
"fppola.f", "fprank.f", "fprati.f", "fpregr.f", "fprota.f", "fprppo.f",
"fprpsp.f", "fpseno.f", "fpspgr.f", "fpsphe.f", "fpsuev.f", "fpsurf.f",
"fpsysy.f", "fptrnp.f", "fptrpe.f", "insert.f", "parcur.f", "parder.f",
"parsur.f", "percur.f", "pogrid.f", "polar.f", "profil.f", "regrid.f",
"spalde.f", "spgrid.f", "sphere.f", "splder.f", "splev.f", "splint.f",
"sproot.f", "surev.f", "surfit.f"]]
fitpack = env.DistutilsStaticExtLibrary('fitpack', source = src)

env.PrependUnique(LIBPATH = ['.'])

# Build _fitpack
env.NumpyPythonExtension('_fitpack', source = 'src/_fitpackmodule.c', 
		LIBS="fitpack")

# Build dfitpack
env.NumpyPythonExtension('dfitpack', source = 'src/fitpack.pyf',
		LIBS="fitpack")

# Build _interpolate
env.NumpyPythonExtension('_interpolate', source = 'src/_interpolate.cpp',
                         CXXFILESUFFIX = ".cpp")

# Build interpnd
env.NumpyPythonExtension('interpnd', source = 'interpnd.c')
