This repository has been archived by the owner on Jun 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwscript
251 lines (190 loc) · 7.08 KB
/
wscript
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
#!/usr/bin/env python
import os, shutil, subprocess, sys, tarfile, tempfile
from waflib import Build, Context, Scripting, Utils, Task, TaskGen
from waflib.Tools import ccroot
APPNAME = 'ExoCore'
VERSION = '1.0'
TOP = os.curdir
OUT = 'build'
Context.classes = [x for x in Context.classes if x.cmd != 'distcheck']
def options(opt):
opt.add_option('--mode', action = 'store', default = 'debug', help = 'the mode to compile in (debug/release)')
class kernel(ccroot.link_task):
"Link object files into a kernel binary"
run_str = '${LD} ${KERNLINKFLAGS} -o ${TGT} ${SRC}'
ext_out = ['.bin']
inst_to = None
def post_run(self):
Task.Task.post_run(self)
shutil.copy(self.outputs[0].abspath(), os.path.join(TOP, 'iso', 'boot'))
@TaskGen.feature('iso')
@TaskGen.after_method('kernel')
def iso(self):
kernel_output = self.link_task.outputs[0]
self.iso_task = self.create_task('iso',
src = kernel_output,
tgt = self.path.find_or_declare(kernel_output.change_ext('.iso').name))
class iso(Task.Task):
"Build a bootable ISO for GRUB 2"
run_str = '${MKRESCUE} -o ${TGT} ${SRC} ${ISOFLAGS} -- -report-about SORRY > /dev/null 2>&1'
ext_out = ['.iso']
inst_to = None
color = 'PINK'
@TaskGen.feature('syms')
@TaskGen.after_method('kernel')
def syms(self):
kernel_output = self.link_task.outputs[0]
self.syms_task = self.create_task('syms',
src = kernel_output,
tgt = self.path.find_or_declare(kernel_output.change_ext('.sym').name))
class syms(Task.Task):
"Build symbol list for a binary"
run_str = '${NM} -n ${SRC} | ${GREP} -v \'\( [aUw] \)\|\(__crc_\)\|\( \$[adt]\)\' | ${AWK} \'{print $1, $3}\' > ${TGT}'
ext_out = ['.sym']
inst_to = None
color = 'CYAN'
def configure(conf):
def add_options(flags, options):
for option in options:
if option not in conf.env[flags]:
conf.env.append_value(flags, option)
conf.load('ar')
conf.find_program('clang', var = 'CC', mandatory = True)
conf.load('gcc')
conf.check_cc(fragment = r'''int main()
{
#if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 1)
# error Only Clang versions above 3.1 are supported.
#endif
return 0;
}''',
features = 'c',
mandatory = True,
execute = False,
msg = 'Checking for clang 3.1+')
add_options('CFLAGS',
['-m64'])
add_options('CFLAGS',
['-std=gnu11',
'-fms-extensions',
'-fborland-extensions',
'-fblocks'])
add_options('CFLAGS',
['-Wall',
'-Wextra',
'-Werror',
'-Winit-self',
'-Wswitch-default',
'-Wswitch-enum',
'-Wundef',
'-Wshadow',
'-Wpointer-arith',
'-Wcast-qual',
'-Wwrite-strings',
'-Wconversion',
'-Wstrict-prototypes',
'-Wold-style-definition',
'-Wmissing-declarations',
'-Wmissing-format-attribute',
'-Wpadded',
'-Wredundant-decls',
'-Winline'])
add_options('CFLAGS',
['-nostdlib',
'-nostdinc',
'-ffreestanding'])
add_options('CFLAGS',
['-fwrapv',
'-fno-omit-frame-pointer',
'-mcmodel=large'])
conf.find_program('yasm', var = 'AS', mandatory = True)
conf.load('nasm')
add_options('ASFLAGS',
['-f',
'elf64'])
add_options('ASFLAGS',
['-w',
'-Worphan-labels',
'-Wunrecognized-char'])
conf.env.kernel_PATTERN = '%s.bin'
conf.find_program('ld', var = 'LD', mandatory = True)
add_options('KERNLINKFLAGS',
['-b',
'elf64-x86-64',
'-m',
'elf_x86_64'])
add_options('KERNLINKFLAGS',
['-z',
'max-page-size=0x1000'])
add_options('KERNLINKFLAGS',
['-T',
os.path.abspath(os.path.join('linker', 'x86_64.ld'))])
conf.find_program('nm', var = 'NM', mandatory = True)
conf.find_program('grep', var = 'GREP', mandatory = True)
conf.find_program('awk', var = 'AWK', mandatory = True)
conf.find_program(['grub-mkrescue', 'grub2-mkrescue'], var = 'MKRESCUE', mandatory = True)
add_options('ISOFLAGS',
[os.path.abspath('iso')])
if conf.options.mode == 'debug':
add_options('CFLAGS',
['-DEXOCORE_DEBUG'])
add_options('CFLAGS',
['-g',
'-ggdb'])
add_options('ASFLAGS',
['-DEXOCORE_DEBUG'])
add_options('ASFLAGS',
['-g',
'dwarf2'])
elif conf.options.mode == 'release':
add_options('CFLAGS',
['-O3'])
else:
conf.fatal('--mode must be either debug or release.')
def build(bld):
def search_paths(*k, **kw):
path = os.path.join(*k, **kw)
return [os.path.join(path, '*.c'), os.path.join(path, 'asm', '*.s')]
bld(features = 'asm c kernel syms iso',
includes = 'include',
source = bld.path.ant_glob(search_paths(os.path.join('src', 'exocore'))),
target = 'exocore')
def _run_shell(dir, ctx, args, wait = True):
cwd = os.getcwd()
os.chdir(dir)
proc = subprocess.Popen(args, shell = True)
if wait:
code = proc.wait()
if code != 0:
ctx.fatal(str(args) + ' exited with: ' + str(code))
os.chdir(cwd)
def docs(ctx):
'''builds the documentation'''
def build_docs(targets):
for x in targets:
_run_shell('docs', ctx, 'make ' + x)
build_docs(['html',
'dirhtml',
'singlehtml',
'text',
'man',
'changes',
'linkcheck'])
def dist(dst):
'''makes a tarball for redistributing the sources'''
with open('.gitignore', 'r') as f:
dst.excl = ' '.join(l.strip() for l in f if l.strip())
def qemu(ctx):
'''runs the kernel in QEMU with GDB server at localhost:1234'''
_run_shell(TOP, ctx, 'qemu-system-x86_64 -monitor stdio -S -s -cdrom {0}'.format(os.path.join(OUT, 'exocore.iso')))
class QEMUContext(Build.BuildContext):
cmd = 'qemu'
fun = 'qemu'
def bochs(ctx):
'''runs the kernel in Bochs with GDB server at localhost:1234'''
_run_shell(TOP, ctx, 'bochs -q')
class BochsContext(Build.BuildContext):
cmd = 'bochs'
fun = 'bochs'
def distcheck(ctx):
ctx.fatal('distcheck is not supported')