import sys
import os
from distutils.core import Distribution
from distutils.command.build import build

Import('env')

# make sure numpy headers are available
from numpy.distutils.misc_util import get_numpy_include_dirs
env.AppendUnique(CPPPATH=get_numpy_include_dirs())

# python extension module
module = env.SharedLibrary('srreal_ext', Glob('*.cpp'),
        SHLIBPREFIX='', SHLIBSUFFIX='.so')
Alias('module', module)

# install in a development mode
develop = Alias('develop', Install('#/diffpy/srreal', module))

test = env.Alias('test', develop,
        sys.executable + ' -m diffpy.srreal.tests.run')
AlwaysBuild(test)

# normal install - trick distutils into using this module.
bcmd = build(Distribution())
bcmd.finalize_options()
distmodfile = os.path.join(bcmd.build_platlib,
    'diffpy', 'srreal', os.path.basename(str(module[0])))
cmd_build_ext = sys.executable + ' setup.py build_ext'
cmd_install = sys.executable + ' setup.py install' + (
        'prefix' in env and (' --prefix=' + env['prefix']) or '')
install = env.Alias('install', module, [
    Mkdir(os.path.dirname(distmodfile)),
    Touch(distmodfile),
    cmd_build_ext,
    Copy(distmodfile, '$SOURCE'),
    cmd_install,
    ])
AlwaysBuild(install)

# default targets:
Default(module)

# vim: ft=python
