# -*- coding: utf-8 -*-
#----------------------------------------------------------------------------#
# SConstruct
# Lars Yencken <lars.yencken@gmail.com>
# vim: ts=4 sw=4 sts=4 et tw=78:
# Thu Nov 30 15:23:25 2006
#
#----------------------------------------------------------------------------#

""" Build instructions for the research codebase.
"""

#----------------------------------------------------------------------------#

import os
from os import path
import sys
from distutils import sysconfig
import py_compile
import re

#----------------------------------------------------------------------------#

# Default include path for python, version inspecific.
pythonVersion = sysconfig.get_config_var('VERSION')

#----------------------------------------------------------------------------#

def checkLibraries(env):
    """ Check whether the correct libraries exist, and thus whether building
        is possible.
    """
    # Detect OS X python installation, and attempt to correct for it.
    if os.uname()[0] == 'Darwin':
        env.Replace(SHLINKFLAGS='$LINKFLAGS -bundle -flat_namespace -undefined suppress')
        env.Replace(SHLIBSUFFIX='.so')

    # Detect the presence of necessary dependencies.
    conf = Configure(env)

    if not conf.CheckLibWithHeader('m', 'math.h', 'c'):
        print "Can't find standard math libraries."
        Exit(1)

    env = conf.Finish()

    return env

#----------------------------------------------------------------------------#
# CONFIGURATION
#----------------------------------------------------------------------------#

# Set up the compilation environment.
pythonVersion = sysconfig.get_config_var('VERSION')
env = Environment(
        CPPPATH=sysconfig.get_python_inc(),
        LIBPATH=sysconfig.get_config_var('LIBPL'),
        SHLIBPREFIX='',
        LIBS=['python%s' % pythonVersion],
    )

environmentVars = (
        'CPATH',
        'LD_LIBRARY_PATH',
    )

envDict = env['ENV']
for var in environmentVars:
    if var in os.environ:
        envDict[var] = os.environ[var]

# Choose between debugging or optimized mode.
if ARGUMENTS.get('debug'):
    print 'Using debug targets'
    env.Replace(DEBUG=True, CXXFLAGS='-O0 -g -Wall ', CCFLAGS='-O0 -g -Wall ')
else:
    print 'Using optimised targets'
    env.Replace(DEBUG=False, CXXFLAGS='-O3 -DNDEBUG -Wall ',
            CCFLAGS='-O3 -DNDEBUG -Wall ')

# Add pyrex builder
pyxbuild = Builder(action='pyrexc -o $TARGET $SOURCE')
env.Append(BUILDERS={'Pyrex': pyxbuild})

# Configure the environment.
env = checkLibraries(env)

#----------------------------------------------------------------------------#

SConscript('src/SConscript', exports='env')

#----------------------------------------------------------------------------#

c5c4c48d59562d65acac6d5b60ae7462d3045a5c
# -*- coding: utf-8 -*-
#----------------------------------------------------------------------------#
# SConstruct
# Lars Yencken <lars.yencken@gmail.com>
# vim: ts=4 sw=4 sts=4 et tw=78:
# Thu Nov 30 15:23:25 2006
#
#----------------------------------------------------------------------------#

""" Build instructions for the research codebase.
"""

#----------------------------------------------------------------------------#

import os
from os import path
import sys
from distutils import sysconfig
import py_compile
import re

#----------------------------------------------------------------------------#

# Default include path for python, version inspecific.
pythonVersion = sysconfig.get_config_var('VERSION')

#----------------------------------------------------------------------------#

def checkLibraries(env):
    """ Check whether the correct libraries exist, and thus whether building
        is possible.
    """
    # Detect OS X python installation, and attempt to correct for it.
    if os.uname()[0] == 'Darwin':
        env.Replace(SHLINKFLAGS='$LINKFLAGS -bundle -flat_namespace -undefined suppress')
        env.Replace(SHLIBSUFFIX='.so')

    # Detect the presence of necessary dependencies.
    conf = Configure(env)

    if not conf.CheckLibWithHeader('m', 'math.h', 'c'):
        print "Can't find standard math libraries."
        Exit(1)

    env = conf.Finish()

    return env

#----------------------------------------------------------------------------#
# CONFIGURATION
#----------------------------------------------------------------------------#

# Set up the compilation environment.
pythonVersion = sysconfig.get_config_var('VERSION')
env = Environment(
        CPPPATH=sysconfig.get_python_inc(),
        LIBPATH=sysconfig.get_config_var('LIBPL'),
        SHLIBPREFIX='',
        LIBS=['python%s' % pythonVersion],
    )

environmentVars = (
        'CPATH',
        'LD_LIBRARY_PATH',
    )

envDict = env['ENV']
for var in environmentVars:
    if var in os.environ:
        envDict[var] = os.environ[var]

# Choose between debugging or optimized mode.
if ARGUMENTS.get('debug'):
    print 'Using debug targets'
    env.Replace(DEBUG=True, CXXFLAGS='-O0 -g -Wall ', CCFLAGS='-O0 -g -Wall ')
else:
    print 'Using optimised targets'
    env.Replace(DEBUG=False, CXXFLAGS='-O3 -DNDEBUG -Wall ',
            CCFLAGS='-O3 -DNDEBUG -Wall ')

# Add pyrex builder
pyxbuild = Builder(action='pyrexc -o $TARGET $SOURCE')
env.Append(BUILDERS={'Pyrex': pyxbuild})

# Configure the environment.
env = checkLibraries(env)

#----------------------------------------------------------------------------#

SConscript('src/SConscript', exports='env')

#----------------------------------------------------------------------------#
