-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·112 lines (91 loc) · 2.38 KB
/
run.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
#!/bin/sh
# ======================= Architecture ====================
# Remember to add your cross compiler on your ~/.bashrc or ~/.profile
# export PATH="$HOME/opt/cross/bin:$PATH"
DEFAULT_TARGET=i686-elf
# ======================= Arguments =======================
ARG1=$1 # build, clean, run, host, target
ARG2=$2 # i686-elf, x86_64-elf, etc.
# ======================= Fast Returns ====================
if [ "$1" = "host" ]; then
echo "$DEFAULT_TARGET"
exit 0
elif [ "$1" = "target" ]; then
ARG2="$2"
if echo "$ARG2" | grep -Eq 'i[[:digit:]]86-'; then
echo i386
exit 0
else
echo "$ARG2" | grep -Eo '^[[:alnum:]_]*'
exit 0
fi
fi
# ======================= Projects ========================
SYSTEM_HEADER_PROJECTS="libc kernel"
PROJECTS="libc kernel"
# ======================= Environment =====================
export MAKE="${MAKE:-make}"
export HOST="${HOST:-$(./run.sh host)}"
export AR="${HOST}-ar"
export AS="${HOST}-as"
export CC="${HOST}-gcc"
export PREFIX=/usr
export EXEC_PREFIX=$PREFIX
export BOOTDIR=/boot
export LIBDIR=$EXEC_PREFIX/lib
export INCLUDEDIR=$PREFIX/include
export CFLAGS='-O2 -g'
export CPPFLAGS=''
export SYSROOT="$HOME/sysroot"
export CC="i686-elf-gcc --sysroot=$SYSROOT -Wall -Wextra -Werror -Wpedantic"
# ======================= Build ===========================
if echo "$HOST" | grep -Eq -- '-elf($|-)'; then
export CC="$CC -isystem=$INCLUDEDIR"
fi
# ======================= Functions =======================
headers() {
set -e
mkdir -p "$SYSROOT"
for PROJECT in $SYSTEM_HEADER_PROJECTS; do
(cd "$PROJECT" && DESTDIR="$SYSROOT" "$MAKE" install-headers)
done
}
build() {
set -e
for PROJECT in $PROJECTS; do
(cd "$PROJECT" && DESTDIR="$SYSROOT" "$MAKE" install)
done
}
clean() {
set -e
for PROJECT in $PROJECTS; do
(cd "$PROJECT" && "$MAKE" clean)
done
rm -rf "sysroot isodir myos.iso $HOME/sysroot"
}
run() {
qemu-system-i386 -kernel "$HOME/sysroot/boot/myos.kernel"
}
# ======================= Main =============================
case "$ARG1" in
build)
headers
build
;;
clean)
clean
;;
run)
run
;;
*)
echo "Usage: ./run.sh [build|clean|run]"
echo "Without arguments, will clean, build, and run."
clean
headers
build
run
clean # clean again (optional)
;;
esac
# ======================= End ==============================