import os
import Options

srcdir='.'
blddir='../build'

# Check whether envinronment variable has been set by Makefile
if 'RAPTOR_PREFIX' in os.environ:
    RAPTOR_PREFIX = os.environ['RAPTOR_PREFIX']
else:
    RAPTOR_PREFIX = '/usr/local'

def set_options(ctx):
    ctx.add_option('--clang',
            action='store_true',
            default='',
            dest='use_clang',
            help='Uses the clang compiler')
    ctx.add_option('--analyze',
            action='store_true',
            default='',
            dest='analyze',
            help='Runs the clang static analyzer (implies --clang)')
    ctx.tool_options('compiler_cxx')

def configure(ctx):
    print "libraptor2 prefix: " + RAPTOR_PREFIX
    if Options.options.analyze:
        ctx.env.ANALYZE = Options.options.analyze
        Options.options.use_clang = 1

    if Options.options.use_clang:
        os.environ['CXX'] = '/usr/bin/clang'

    ctx.check_tool('compiler_cxx')
    ctx.check_tool('node_addon')

def build(ctx):
    obj = ctx.new_task_gen('cxx', 'shlib', 'node_addon')

    # Analyze
    if ctx.env.ANALYZE:
        obj.cxxflags = ['-g', '-Wall', '--analyze']
    else:
        obj.cxxflags = ['-g', '-Wall']

    obj.find_sources_in_dirs('.')

    obj.target   = 'bindings'
    obj.includes = RAPTOR_PREFIX + '/include/raptor2'
    obj.lib      = 'raptor2'
    obj.libpath  = RAPTOR_PREFIX + '/lib'

