summaryrefslogtreecommitdiffstats
path: root/SConstruct
blob: 1924c8df4f1f6773d24ffa60277a12cf320860da (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#
# Copyright (C) 2011 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

COMMON_CFLAGS = ['-Wall', '-Werror', '-D__HOST__']
COMMON_CXXFLAGS = ['-Wall', '-Werror', '-fno-exceptions', '-D__HOST__']

configs = {
    'debug': {
        'CFLAGS': COMMON_CFLAGS + ['-g'],
        'CXXFLAGS': COMMON_CXXFLAGS + ['-g']
    },

    'release': {
        'CFLAGS': COMMON_CFLAGS + ['-O2'],
        'CXXFLAGS': COMMON_CXXFLAGS + ['-O2']
    },
}

toolsets = {
    'gcc': {
        'CC': 'gcc',
        'CXX': 'g++',
    },

    'mips-gcc': {
        'CC': 'mips-linux-gnu-gcc',
        'CXX': 'mips-linux-gnu-g++',
    },

    'clang': {
        'CC': 'clang',
        'CXX': 'clang++',
    },
}

toolset_configs = {
    'gcc': { 'CFLAGS': [], 'CXXFLAGS': [], 'LDFLAGS': [] },
    'clang': { 'CFLAGS': [], 'CXXFLAGS': [], 'LDFLAGS': [] },
    'mips-gcc': { 'CFLAGS': ['-EL', '-mips32r2'],
                  'CXXFLAGS': ['-EL', '-mips32r2'],
                  'LDFLAGS': ['-EL', '-mips32r2'] }
}

mode = ARGUMENTS.get('mode', 'release')
toolset = ARGUMENTS.get('toolset', 'gcc')

if not mode in configs:
    print 'ERROR: Unknown building mode:', mode
    Exit(1)

if not toolset in toolsets:
    print 'ERROR: Unknown toolset:', toolset
    Exit(1)

build_config = configs[mode]
build_toolset = toolsets[toolset]
build_toolset_config = toolset_configs[toolset]

print '===> BUILDING IN', mode.upper(), 'MODE ...'

import os

cflags = build_config['CFLAGS'] + build_toolset_config['CFLAGS']
cxxflags = build_config['CXXFLAGS'] + build_toolset_config['CXXFLAGS']
linkflags = build_toolset_config['LDFLAGS']

env = Environment(CC=build_toolset['CC'],
                  CXX=build_toolset['CXX'],
                  CFLAGS=cflags,
                  CXXFLAGS=cxxflags,
                  LINKFLAGS=linkflags,
                  CPPPATH=['.', 'include'],
                  ENV={'PATH': os.environ['PATH']})

env.ParseConfig('llvm-config --cxxflags --ldflags --libs support')

env.Program('rsloader',
            source=['lib/ELFHeader.cpp',
                    'lib/ELFSectionHeader.cpp',
                    'lib/ELFSymbol.cpp',
                    'lib/ELFTypes.cpp',
                    'lib/MemChunk.cpp',
                    'lib/StubLayout.cpp',
                    'lib/GOT.cpp',
                    'utils/helper.cpp',
                    'utils/raw_ostream.cpp',
                    'utils/rsl_assert.cpp',
                    'main.cpp'])