# -*- coding: iso-8859-1 -*-
# -*- mode: python -*-
import os

if hasattr(os,'uname'):
    system = os.uname()[0]
else:
    system = 'Windows'

# source files and libraries
src_files = ['mtm.c', 'tfr.c']
hdr_files = ['tfr.h']
libs = ['m']

# install location
AddOption('--prefix',
          dest='prefix',
          type='string',
          nargs=1,
          action='store',
          metavar='DIR',
          help='installation prefix')

if not GetOption('prefix')==None:
    install_prefix = GetOption('prefix')
else:
    install_prefix = '/usr/local/'

Help("""
Type: 'scons' to build the library
      'scons install' to install library and headers under %s
      'scons matlab' to compile mex file
      'scons test' to compile the test program
      (use --prefix  to change library installation location)
""" % install_prefix)

# build options
env = Environment(ENV = os.environ,
                  LIBS = ['fftw3','lapack'],
                  CCFLAGS = ['-O2', '-std=c99'],
                  tools=['default','mex','doxygen'])

# system-specific settings
if system=='Darwin':
    # fftw is probably installed with macports; if elsewhere
    # then adjust these paths
    env.Append(CPPPATH = ['/opt/local/include'],
               LIBPATH = ['/opt/local/lib'])
elif system=='Linux':
    # add additional items as needed, for example if lapack requires atlas:
    #env.Prepend(LIBS = ['atlas','cblas','f77blas','lapack'])
    pass


sharedobjs = env.SharedObject(src_files)
slib = env.StaticLibrary('libtfr', source = src_files)
dylib = env.SharedLibrary('libtfr', sharedobjs)
test_prog = env.Program('test_tfr', ['test_tfr.c', slib])

env.Default(env.Alias('lib', [slib, dylib]))
env.Alias('test',test_prog)
env.Alias('install', env.Install(os.path.join(install_prefix, 'include'), hdr_files))
env.Alias('install', env.Install(os.path.join(install_prefix,'lib'), [slib, dylib]))

# matlab mex-file
if hasattr(env,'MEX'):
    mex = env.MEX('tfrspec', ['tfrspec.c', sharedobjs])
    env.Alias("mex",mex)

if hasattr(env,'Doxygen'):
    dox = env.Doxygen('doxy.cfg')
    env.Alias("docs",dox)
