-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·170 lines (155 loc) · 3.63 KB
/
build.sh
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
#!/usr/bin/env bash
# If this is not your path, kindly change it
export CROSS_CC="${CROSS_CC:-$HOME/opt/cross/bin/i686-elf-gcc}"
export ARCH="${ARCH:-x86/x32}"
export QEMU_SYSTEM="${QEMU_SYSTEM:-i386}"
export EMULATOR="${EMULATOR:-qemu}"
# Colors
if command -v tput &> /dev/null; then
ncolors=$(tput colors)
if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
bold="$(tput bold)"
underline="$(tput smul)"
standout="$(tput smso)"
normal="$(tput sgr0)"
black="$(tput setaf 0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
white="$(tput setaf 7)"
fi
fi
# Utils
build() {
if ! cargo build; then
return 1
fi
KERNEL="target/target/debug/satan"
GRUB_CFG="src/arch/$ARCH/grub"
if [ "$KERNEL" -nt "bin/os.iso" ] || [ "$GRUB_CFG" -nt "bin/os.iso" ]; then
echo "${green}Building the system...${normal}"
rm -rf bin/iso bin/os.iso
mkdir -p bin/iso/boot
cp -r "$GRUB_CFG" bin/iso/boot
cp "$KERNEL" bin/iso/boot/kernel.bin
grub-mkrescue -o bin/os.iso bin/iso
echo "${green}Done!${normal}"
fi
}
run() {
if [ $EMULATOR = "bochs" ]; then
bochs -q
else
qemu-system-$QEMU_SYSTEM -d guest_errors -no-reboot -cdrom bin/os.iso
fi
}
debug() {
if [ $EMULATOR = "bochs" ]; then
bochs -q
else
qemu-system-$QEMU_SYSTEM -d guest_errors -no-reboot -cdrom bin/os.iso -s -S &
rust-gdb target/target/debug/satan -x gdbinit
fi
}
clean() {
rm -rf bin target
}
print() {
echo "ARCH: $ARCH"
echo "CROSS_CC: $CROSS_CC"
echo "QEMU System: $QEMU_SYSTEM"
}
help() {
cat <<-EOF
SATAN Build system
Usage: ./build.sh [--arch x86] [--toolchain i686-elf] [--quemu-system x86_64] [command]
When ran without command, REPL mode will be entered
Commands:
build - build kernel and OS
run - build and run the OS
debug - build and run the OS, drop into gdb
print - print current parameters
clean - remove all build artifacts
help - show this message
quit/exit/q - exit REPL
EOF
}
command() {
case $1 in
build) build;;
run) build && run;;
debug) build && debug;;
print) print;;
clean) clean;;
help) help;;
quit|exit|q) exit 0;;
*) echo -e "Unknown command $1.\nUse help to see the available options";;
esac
}
repl() {
cat <<-"EOF"
.oooooo..o .o. ooooooooooooo .o. ooooo ooo
d8P' `Y8 .888. 8' 888 `8 .888. `888b. `8'
Y88bo. .8"888. 888 .8"888. 8 `88b. 8
`"Y8888o. .8' `888. 888 .8' `888. 8 `88b. 8
`"Y88b .88ooo8888. 888 .88ooo8888. 8 `88b.8
oo .d8P .8' `888. 888 .8' `888. 8 `888
8""88888P' o88o o8888o o888o o88o o8888o o8o `8
Type help for list of availble commands
EOF
while true; do
if command -v zsh &> /dev/null; then
REPLY=$(zsh -c 'export REPLY="" && vared -p "> " REPLY && echo $REPLY')
else
read -e -r -p "> "
fi
if [[ $REPLY == \:* ]]; then
bash -c "${REPLY#\:}"
else
command $REPLY
fi
done
}
# Main
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
--arch)
export ARCH="$2"
shift
shift
;;
--cross-cc)
export CROSS_CC="$2"
shift
shift
;;
--qemu-system)
export QEMU_SYSTEM="$2"
shift
shift
;;
-h|--help)
help
exit 0
;;
-*|--*)
echo "Unknown option $1"
echo "Use help to see the available options"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}"
if [ $# -gt 0 ]; then
command "$@"
else
repl
fi