-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·86 lines (69 loc) · 1.82 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
#!/bin/bash
#Config variables
PLATFORM="x86"
CCPLATFORM="i386"
BINLOC="$HOME/i386elfgcc/bin" #location of compiliation tools
CC="$BINLOC/$CCPLATFORM-elf-gcc"
LD="$BINLOC/$CCPLATFORM-elf-ld"
CCFLAGS="-std=gnu89 -pedantic -Wno-long-long -D ARCH=$PLATFORM -Wall -O3 -fstrength-reduce\
-fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -mno-red-zone\
-mgeneral-regs-only -I./include -I./libk/include -I./arch/$PLATFORM/include -c"
red=`tput setaf 1`
green=`tput setaf 2`
clr=`tput sgr0`
if [ "$1" = "clean" ]
then
rm Kernel.bin OS.iso iso/boot/Kernel.bin out.bochs &> /dev/null
echo "${green}Done cleaning!"
exit 0
fi
function asm
{
nasm $1.asm -f elf32 -o $1.o
linkfiles="$linkfiles $1.o"
}
function buildc
{
for file in $1/*.c
do
object=${file/".c"/}".o"
echo "$file -> $object"
$CC $file $CCFLAGS -o $object
linkfiles="$linkfiles $object"
done
}
echo "${green}Building kernel for platform $PLATFORM${clr}"
cd kernel/
#NASM commands
echo "boot.asm -> boot.o"
asm arch/$PLATFORM/boot
echo "pic.asm -> pic.o"
asm arch/$PLATFORM/pic
echo "idt_helper.asm -> idt_helper.o"
asm arch/$PLATFORM/idt_helper
echo "blink.asm -> blink.o"
asm arch/$PLATFORM/blink
#CC commands
echo -e "${green}\nCompiling base files${clr}"
buildc .
echo -e "${green}\nCompiling libk${clr}"
buildc libk
echo -e "${green}\nCompiling HAL${clr}"
buildc arch/$PLATFORM
echo -e "${green}\nLinking object files...${clr}"
$BINLOC/$CCPLATFORM-elf-ld -T arch/$PLATFORM/link.ld -o Kernel.bin $linkfiles -z max-page-size=4096 --nmagic
if [ $? -ne 0 ]
then
echo "${red}\n*** Build Failed! ***${clr}\n"
exit -1
fi
#Clean up
echo -e "${green}\nCleaning up...${clr}"
mv Kernel.bin ..
rm $linkfiles
#make iso
echo -e "${green}\nMaking iso...${clr}"
cd ..
cp -p Kernel.bin iso/boot/
grub-mkrescue -o OS.iso iso &> /dev/null
echo -e "${green}\n*** Done! ***${clr}\n"