aboutsummaryrefslogtreecommitdiff
path: root/scons-tools/llvm.py
blob: 8fecb40a159b247556e4526e1fd66c5bbab7e4a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from SCons.Scanner.Prog import scan
from SCons.Builder import Builder
import os

def exists(env):
    return True

def add_libraries(target, source, env):
    unique = []
    lib_nodes = set()
    for x in scan(None, env, tuple(map(env.Dir, env['LIBPATH']))):
        if x in lib_nodes:
            continue
        lib_nodes.add(x)
        unique.append(x)
    return (target, source + unique)

def generate(env):
    env.SetDefault(
        CLANG='clang',
        CLANGXX='clang++',
        LLVM_DIS='llvm-dis',
        LLVM_OPT='opt',
        LLVM_LINK='llvm-link')
    
    env['BUILDERS']['LLVMDis'] = Builder(
        action=os.path.join('${LLVM_ROOT}', '$LLVM_DIS') + ' -o $TARGET $SOURCE')

    env['BUILDERS']['LLVMOpt'] = Builder(
        action=os.path.join('${LLVM_ROOT}', '$LLVM_OPT') + ' $LLVM_OPT_FLAGS $LLVM_OPT_PASSES -o $TARGET $SOURCE')

    env['BUILDERS']['LLVMLink'] = Builder(
        action=os.path.join('${LLVM_ROOT}', '$LLVM_LINK') + ' -o $TARGET $SOURCES',
        emitter=add_libraries)