-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
170 lines (145 loc) · 3.76 KB
/
SConstruct
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#imports
import sys, os, fnmatch, shutil
# Needed for colored output.
class color:
escape = '\033['
endEscape = 'm'
black = '\033[30m'
blue = '\033[34m'
green = '\033[32m'
cyan = '\033[36m'
red = '\033[31m'
purple = '\033[35m'
white = '\033[37m'
endc = '\033[0m'
AddOption(
'--no-color',
dest='nocolor',
action='store_true',
default=False,
help='Disable colored build.'
)
# Environment initialization
env = 0;
if GetOption('nocolor'):
env = Environment(
CCCOMSTR='[CC] $SOURCES',
SHCXXCOMSTR='[CXX] $SOURCES',
CXXCOMSTR='[CXX] $SOURCES',
SHCCCOMSTR='[CC] $SOURCES',
SHLINKCOMSTR='[LD] $TARGET',
LINKCOMSTR='[LD] $TARGET'
)
else:
env = Environment(
CCCOMSTR= color.cyan + '[' + color.green + 'CC' + color.cyan +']' + color.endc + ' ' + '$SOURCES',
SHCXXCOMSTR= color.cyan + '[' + color.green + 'CXX' + color.cyan +']' + color.endc + ' ' + '$SOURCES',
CXXCOMSTR= color.cyan + '[' + color.green + 'CXX' + color.cyan +']' + color.endc + ' ' + '$SOURCES',
SHCCCOMSTR= color.cyan + '[' + color.green + 'CC' + color.cyan +']' + color.endc + ' ' + '$SOURCES',
SHLINKCOMSTR= color.cyan + '[' + color.cyan + 'LD' + color.cyan +']' + color.endc + ' ' + '$TARGET',
LINKCOMSTR= color.cyan + '[' + color.cyan + 'LD' + color.cyan +']' + color.endc + ' ' + '$TARGET',
)
HeaderDirectory = "include"
SourceDirectory = "src"
SourceExtensions = ["c", "cpp"]
DefaultVariant = "generic"
BuildPrefix = os.path.join("build", ".objects")
# Compile flags.
Flags = '-std=c99 -pipe'
# Options
AddOption(
'--lto',
dest='lto',
action='store_true',
default=False,
help='Link time optimization.'
)
AddOption(
'--debugging',
dest='debug',
action='store_true',
default=False,
help='Compile a debug release'
)
AddOption('--strict',
dest='strict',
action='store_true',
default=False,
help='Stop compiling whenever the compiler issues a warning.'
)
AddOption(
'--fast',
dest='fast',
action='store_true',
default=False,
help='Compile a fast executable'
)
AddOption(
'--small',
dest='small',
action='store_true',
default=False,
help='Compile a small executable'
)
AddOption(
'--tool-prefix',
dest='tool-prefix',
type='string',
nargs=1,
action='store',
metavar='TOOL',
help='tool prefix'
)
AddOption(
'--mingw32',
dest='mingw32',
action='store_true',
default=False,
help='Cross compile for windows'
)
Variant = DefaultVariant
if(GetOption('mingw32')):
env.Append(CCFLAGS='-mwindows')
Libraries = ['mingw32']
Variant = 'windows'
Executable = 'out.exe'
else:
Libraries = []
Executable = 'out'
Variant = 'linux'
BuildPrefix = os.path.join(BuildPrefix, Variant)
#source directories
env.VariantDir(BuildPrefix, SourceDirectory, duplicate=0)
Sources = []
for Extension in SourceExtensions:
for Root, Directories, Files in os.walk(SourceDirectory):
for Files in fnmatch.filter(Files, '*.' + Extension):
Sources.append((os.path.join(Root, Files)).replace(SourceDirectory, BuildPrefix, 1))
Executable = os.path.join('build', os.path.join(Variant, Executable))
# Include directories
Headers = [HeaderDirectory]
#env setup
env.Append(CCFLAGS=Flags)
env.Append(CPPPATH=Headers)
if(GetOption('tool-prefix')):
env['CC']=GetOption('tool-prefix')+'-'+env['CC']
env['CXX']=GetOption('tool-prefix')+'-'+env['CXX']
#option reading
if(GetOption('debug')):
env.Append(CCFLAGS='-ggdb -Wall -Wextra')
if(GetOption('strict')):
env.Append(CCFLAGS='-Werror')
if(GetOption('small')):
env.Append(CCFLAGS='-Os')
if(GetOption('fast')):
env.Append(CCFLAGS='-O3')
if(GetOption('lto')):
env.Append(CCFLAGS='-flto')
env.Append(LINKFLAGS='-flto')
if(not GetOption('debug')):
env.Append(CCFLAGS='-DNDEBUG')
Install = env.Program(Executable, Sources, LIBS=Libraries)
#install
env.Install('/usr/bin', Install)
#aliases
env.Alias('install',['/usr/bin'])