import os
Import('env', 'get_pyext_environment')

# Get a modified build environment suitable for building Python extensions:
e = get_pyext_environment(env, 'mdt')
e.MergeFlags(e['MODELLER'])
e.MergeFlags(e['GLIB'])

# Check for NumPy support:
if not e.GetOption('clean') and not e.GetOption('help') \
   and not e['wine'] and not e['wine64']:
    print "Checking for numpy...",
    try:
        import numpy
        path = os.path.join(numpy.__path__[0], 'core', 'include')
        if os.path.exists(path):
            e.Append(CPPDEFINES=[('MDT_WITH_NUMPY', 1)])
            print "found in " + path
            e.Append(CPPPATH=[path])
        else:
            print "module found, but no headers"
    except ImportError:
        print "not found"

e.Append(LIBPATH=['../src'])
e.Append(LIBS=['mdt'])
e.Append(CPPPATH=['../src'])
e.Append(SWIGPATH=['../src'])

# Build the Python extension from SWIG interface file:
pyso = e.LoadableModule('_mdt', 'mdt.i',
                        SWIGFLAGS='-python -noproxy ' + \
                                  '-nodefaultctor -nodefaultdtor')

# Subdirectories containing pure Python files:
Export('e')
pyext = SConscript('mdt/SConscript')

# Install the Python extension:
libinst = e.Install(e['destdir'] + e['pyextdir'], pyso)
e.Alias('install', libinst)

Return('pyso', 'pyext')
