#==============================================================================
#   Copyright (c) 2001-2011 Joel de Guzman
#
#   Distributed under the Boost Software License, Version 1.0. (See accompanying
#   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#==============================================================================
project spirit-qi-compiler_tutorial
    : requirements
        <c++-template-depth>300
    :
    ;

import modules ;

exe calc1_exe : calc1.cpp ;
exe calc2_exe : calc2.cpp ;
exe calc3_exe : calc3.cpp ;
exe calc4_exe : calc4.cpp /boost/foreach//boost_foreach ;
exe calc5_exe : calc5.cpp /boost/foreach//boost_foreach ;
exe calc6_exe : calc6.cpp /boost/foreach//boost_foreach ;

exe calc7_exe :
    calc7/vm.cpp
    calc7/compiler.cpp
    calc7/expression.cpp
    calc7/statement.cpp
    calc7/main.cpp
    /boost/foreach//boost_foreach
;

exe calc8_exe :
    calc8/vm.cpp
    calc8/compiler.cpp
    calc8/expression.cpp
    calc8/statement.cpp
    calc8/main.cpp
    /boost/foreach//boost_foreach
;

exe mini_c_exe :
    mini_c/vm.cpp
    mini_c/compiler.cpp
    mini_c/expression.cpp
    mini_c/statement.cpp
    mini_c/function.cpp
    mini_c/main.cpp
    /boost/foreach//boost_foreach
;

exe conjure1_exe :
    conjure1/vm.cpp
    conjure1/compiler.cpp
    conjure1/expression.cpp
    conjure1/statement.cpp
    conjure1/function.cpp
    conjure1/main.cpp
    /boost/foreach//boost_foreach
;

exe conjure2_exe :
    conjure2/compiler.cpp
    conjure2/expression.cpp
    conjure2/function.cpp
    conjure2/lexer.cpp
    conjure2/main.cpp
    conjure2/statement.cpp
    conjure2/vm.cpp
    /boost/foreach//boost_foreach
;

#==============================================================================
# conjure3 and above require LLVM. Make sure you provide the
# LLVM_PATH in your bjam invocation. E.g.:
#
#     bjam -sLLVM_PATH=C:/dev/llvm conjure3
#
#==============================================================================

if [ modules.peek : LLVM_PATH ]
{
    LLVM_PATH =  [ modules.peek : LLVM_PATH ] ;
}

if $(LLVM_PATH)
{
    path-constant LLVM_LIB_DEBUG_PATH : $(LLVM_PATH)/lib/Debug ;
    path-constant LLVM_LIB_RELEASE_PATH : $(LLVM_PATH)/lib/Release ;

    llvm_linker_flags =
         "advapi32.lib"
         "shell32.lib"
        ;

    llvm_debug_libs = [ glob $(LLVM_LIB_DEBUG_PATH)/LLVM*.lib ] ;
    llvm_release_libs = [ glob $(LLVM_LIB_RELEASE_PATH)/LLVM*.lib ] ;

    rule build_exe_1 ( target-name : sources + : requirements * )
    {
        local llvm_lib ;
        if <variant>debug in $(requirements)
        {
            llvm_lib = $(llvm_debug_libs) ;
        }
        else
        {
            llvm_lib = $(llvm_release_libs) ;
        }

        exe $(target-name)
        :   $(sources)
            $(llvm_lib)
        :   $(requirements)
            <toolset>msvc
            <include>$(LLVM_PATH)/include
            <linkflags>$(llvm_linker_flags)
        ;
    }

    rule build_exe ( target-name : sources + )
    {
        build_exe_1 $(target-name) : $(sources) : <variant>debug ;
        build_exe_1 $(target-name) : $(sources) : <variant>release ;
    }

    build_exe conjure3_exe :
        conjure3/compiler.cpp
        conjure3/expression.cpp
        conjure3/function.cpp
        conjure3/lexer.cpp
        conjure3/main.cpp
        conjure3/statement.cpp
        conjure3/vm.cpp
    ;
}



