#!/usr/bin/env python
# encoding: utf8

import Options, re

def build(bld):
    all_libs = []
    boost_lib_re = re.compile('LIB_BOOST_')
    boost_inc_re = re.compile('CPPPATH_BOOST')

    includes = ['.']

    for k,v in bld.env.get_merged_dict().iteritems():
        if boost_lib_re.search(k):
            # Each of these is a 1 element list
            all_libs.append(v[0])
        elif boost_inc_re.search(k):
            # This is just a string
            includes.append(v)

    all_libs.extend([
            'LLVMArchive',
            'LLVMBitReader',
            'LLVMCore',
            'LLVMInstrumentation',
            'LLVMLinker',
            'LLVMScalarOpts',
            'LLVMSupport',
            'LLVMSystem',
            'LLVMTarget',
            'LLVMTransformUtils',
            'LLVMipa',
            'LLVMipo',
            'LLVMAnalysis'
            ])

    scheme_dep_header = bld.new_task_gen(
        features = 'subst',
        source = 'SchemeDepPaths.hpp.in')
    scheme_dep_header.env.table.update({
            'SCHEME': Options.options.schemelibdir,
            'DEPS':   Options.options.dependencylibdir
            })

    bld.add_group('subst-headers-sigdump')

    obj = bld.new_task_gen(
        target = 'sigdump',
        features = 'cc cxx cprogram',
        source = [
            'AliasHelper.cpp',
            'AllocatorAnalysis.cpp',
            'ArgumentHelpers.cpp',
            'ArrayAnalysis.cpp',
            'Driver.cpp',
            'EscapeAnalysis.cpp',
            'FinalizerAnalysis.cpp',
            'InterproceduralDefUse.cpp',
            'OutputParameterAnalysis.cpp',
            'Results.cpp',
            'Scheme.cpp',
            'SharedLibraryManipulation.cpp',
            'StructArrayMemberAnalysis.cpp',
            'TransitiveDefUse.cpp',
            'Utility.cpp',
            'ValueCounter.cpp',
            'b64/cencode.c',
            'b64/cdecode.c'
            ],
        includes = includes,
        cxxflags = ['-Wall', '-Wshadow', '-fexceptions', '-O3'],
        lib = all_libs,
        uselib = ['GUILE'],
        install_path = '${PREFIX}/bin')
