# Last Change: Thu Jun 12 07:00 PM 2008 J
# vim:syntax=python

import os
from os.path import join as pjoin, splitext

from numscons import GetNumpyEnvironment
from numscons import CheckF77BLAS, CheckF77Clib

from numscons import write_info

env = GetNumpyEnvironment(ARGUMENTS)
#if os.name == 'nt':
#    # NT needs the pythonlib to run any code importing Python.h, including
#    # simple code using only typedef and so on, so we need it for configuration
#    # checks
#    env.AppendUnique(LIBPATH = [get_pythonlib_dir()])

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

if not config.CheckBLAS():
    raise RuntimeError("Could not check F/C runtime library for %s/%s, " \
                       "contact the maintainer" % (env['CC'], env['F77']))

#--------------
# Checking Blas
#--------------
st = config.CheckBLAS()
if not st:
    has_blas = 0
else:
    has_blas = 1

config.Finish()
write_info(env)

#==========
#  Build
#==========

# odr lib
libodr_src = [pjoin('odrpack', i) for i in ['d_odr.f', 'd_mprec.f', 'dlunoc.f']]
if has_blas:
    libodr_src.append(pjoin('odrpack', 'd_lpk.f'))
else:
    libodr_src.append(pjoin('odrpack', 'd_lpkbls.f'))

env.DistutilsStaticExtLibrary('odrpack', source = libodr_src)

env.PrependUnique(LIBS = 'odrpack')
env.PrependUnique(LIBPATH = '.')

# odr pyextension
env.NumpyPythonExtension('__odrpack', '__odrpack.c')
