-
Notifications
You must be signed in to change notification settings - Fork 11
/
SConstruct
265 lines (245 loc) · 6.09 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# __ __ _
# \ \/ / _ _ __(_)___
# \ / | | | '__| / __|
# / \ |_| | | | \__ \
# /_/\_\__, |_| |_|___/
# |___/
#
# Compiles the kernel source code located in the kernel folder.
# Designed by Keeton Feavel & Micah Switzer
# Copyright the Xyris Contributors (c) 2019
import os
import subprocess
def get_git_commit():
"""Returns the current git version as a string."""
return subprocess.check_output(
['git', 'describe', '--abbrev=8', '--dirty', '--always', '--tags']
).decode().rstrip()
# Clear any default targets set by SCons
Default(None)
env = Environment(
tools=[
'default',
'colors',
'glob',
'ext2'
],
toolpath=[
'Scones',
],
ENV={
'PATH': os.environ['PATH'],
},
BUILD_DIR='#Build/$ARCH/$MODE',
INSTALL_DIR='#Distribution/$ARCH/$MODE',
LIBPATH='$INSTALL_DIR',
REPO_URL='https://xyr.is/source',
GIT_COMMIT=get_git_commit(),
VERSION_ID=(0, 5, 0),
VERSION_NAME='Tengu',
# *******************
# * Toolchain Flags *
# *******************
# C only warnings
CWARNINGS=[
'-Wnested-externs',
'-Wstrict-prototypes',
'-Wmissing-prototypes',
],
# C/C++ warnings
CCWARNINGS=[
'-Wall',
'-Werror',
'-Wextra',
'-Wundef',
'-Winline',
'-Wshadow',
'-Wformat=2',
'-Wcast-align',
'-Wno-long-long',
'-Wpointer-arith',
'-Wwrite-strings',
'-Wredundant-decls',
'-Wdouble-promotion',
'-Wno-unused-function',
'-Wmissing-declarations',
],
# C only flags
CFLAGS=[
'${CWARNINGS}'
],
# C/C++ flags
CCFLAGS=[
'-nodefaultlibs',
'-ffreestanding',
'-fstack-protector',
'-fno-omit-frame-pointer',
'${CCWARNINGS}'
],
# C++ only flags
CXXFLAGS=[
'-std=c++20',
'-fno-rtti',
'-fno-exceptions',
'-fno-use-cxa-atexit',
],
LINKFLAGS=[
'-nostdlib',
'-lgcc',
],
CPPDEFINES={
'REPO_URL': '\\"$REPO_URL\\"',
'COMMIT': '\\"$GIT_COMMIT\\"',
'VER_MAJOR': '\\"${VERSION_ID[0]}\\"',
'VER_MINOR': '\\"${VERSION_ID[1]}\\"',
'VER_PATCH': '\\"${VERSION_ID[2]}\\"',
'VER_NAME': '\\"$VERSION_NAME\\"',
},
CPPPATH=[
'#Kernel',
'#Thirdparty',
'#Libraries',
],
)
limine_deploy = env.SConscript(
"Limine.scons",
variant_dir="$BUILD_DIR/limine",
duplicate=False,
)
env["LIMINE_INSTALL"] = limine_deploy
# ************************
# * Kernel Build Targets *
# ************************
kernel_environments = [
# i686 ELF (debug)
env.Clone(
tools=[
'nasm',
'i686_elf',
'mode_debug',
],
),
# i686 ELF (release)
env.Clone(
tools=[
'nasm',
'i686_elf',
'mode_release',
],
),
]
# Allow docs to be built without the kernel or a compiler
# This is necessary for allowing CI to build and publish docs
if 'docs' not in COMMAND_LINE_TARGETS:
# Build a list of all build targets associated with the kernel
# Includes all dependencies, kernels, bootable images, etc.
kernel_targets_all = []
kernel_targets_debug = []
kernel_targets_release = []
for target_env in kernel_environments:
liballoc = target_env.SConscript(
'Libraries/liballoc/SConscript',
variant_dir='$BUILD_DIR/liballoc',
duplicate=0,
exports={
'env': target_env
},
)
Default(liballoc)
target_env.Install('$INSTALL_DIR', liballoc)
kernel = target_env.SConscript(
'Kernel/SConscript',
variant_dir='$BUILD_DIR/kernel',
duplicate=0,
exports={
'env': target_env
},
)
Default(kernel)
target_env.Install('$INSTALL_DIR', kernel)
image = target_env.Ext2Image(
'$INSTALL_DIR/xyris.img',
[
'#Kernel/Arch/$ARCH/Bootloader/limine.cfg',
'#Thirdparty/limine/limine.sys',
kernel
]
)
env.Depends(image, limine_deploy)
Default(image)
kernel_targets_all.extend([liballoc, kernel, image])
# Add targets to kernel_targets_[MODE] list
target_list_name = 'kernel_targets_' + target_env['MODE'].lower()
targets_list = globals()[target_list_name]
targets_list.extend([liballoc, kernel, image])
# Mode specific kernel targets
env.Alias('kernel-debug', kernel_targets_debug)
env.Alias('kernel-release', kernel_targets_release)
# ************************
# * Kernel Documentation *
# ************************
env = Environment(
tools=[
'doxygen'
],
toolpath=[
'Scones'
],
ENV={
'PATH': os.environ['PATH']
},
)
docs = env.Doxygen(
'#Documentation/Build',
'#Documentation/Doxyfile',
)
env.Alias('docs', docs)
env.Clean('docs', '#Documentation/Build')
# ***************************
# * Unit Test Build Targets *
# ***************************
env = Environment(
tools=[
'default',
'colors',
'glob'
],
toolpath=[
'Scones',
],
BUILD_DIR='#Build/Tests',
INSTALL_DIR='#Distribution/Tests',
LIBPATH='$INSTALL_DIR',
CXXFLAGS=[
'-fprofile-arcs',
'-ftest-coverage',
],
CPPPATH=[
'#Tests',
'#Kernel',
'#Thirdparty',
],
LINKFLAGS=[
'--coverage',
'-lstdc++',
'-lgcov',
'-lgcc',
'-lm',
],
)
catch2_header_url = 'https://github.com/catchorg/Catch2/releases/download/v2.13.8/catch.hpp'
catch2_header = env.Command(
'#Thirdparty/catch2/catch.hpp',
None,
'wget -qP ${{TARGET.dir}} {}'.format(catch2_header_url)
)
tests = env.SConscript(
'Tests/SConscript',
variant_dir='$BUILD_DIR/tests',
duplicate=0,
exports={
'env': env
}
)
tests_intall = env.Install('$INSTALL_DIR', tests)
env.Alias('tests', [catch2_header, tests, tests_intall])