-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.py
executable file
·102 lines (73 loc) · 1.76 KB
/
build.py
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
#!/usr/bin/env python
import os
import sys
files = ['src/main.py']
asm_files = ['src/boot.asm']
c_files = ['build/main.c']
output_files = ['build/main.c.o', 'build/boot.asm.o']
gcc_flags = [
'-O2',
'-Wall',
'-I.',
'-std=gnu11 ',
'-ffreestanding ',
'-fno-stack-protector ',
'-fno-pic ',
'-mabi=sysv ',
'-mno-80387 ',
'-mno-mmx ',
'-mno-3dnow ',
'-mno-sse ',
'-mno-sse2 ',
'-mno-red-zone ',
'-mcmodel=kernel ',
]
ld_flags = [
'-Tsrc/linker.ld ',
'-nostdlib ',
'-zmax-page-size=0x1000 ',
'-static'
]
def build_py():
for i in files:
output = i.replace('src', 'build')
output = output.replace('.py', '.c')
d = "build"
if not os.path.exists(d):
os.makedirs(d)
os.system('thirdparty/snek/snek.py ' + i + ' ' + output)
def build_c():
for output in c_files:
command = "gcc "
for i in gcc_flags:
command += i + " "
command += f" {output} -c -o {output + '.o'}"
print(f"Compiling {output}")
os.system(command)
def build_asm():
for output in asm_files:
command = "nasm -felf64"
command += f" {output} -o build/{os.path.basename(output + '.o')}"
print(command)
print(f"Assembling {output}")
os.system(command)
def link():
command = "ld "
for i in ld_flags:
command += i + " "
command += f"{' '.join([o for o in output_files])} -o kernel.elf"
print(command)
print(f"Linking kernel.elf")
os.system(command)
def run():
os.system("./scripts/make_image.py")
os.system(f"qemu-system-x86_64 -M q35 -m 2G -cdrom pyOS.iso")
if len(sys.argv) == 2:
if sys.argv[1] == "clean":
os.system("rm -rf build kernel.elf pyOS.iso")
sys.exit(0)
build_py()
build_c()
build_asm()
link()
run()