1#! /bin/sh
2
3##  Kernel-mode libcaca compilation script -- Sam Hocevar <sam@hocevar.net>
4
5set -x
6set -e
7
8MYCFLAGS="-fno-builtin -O0 -I. -I.. -I../caca/ -Wall -D__KERNEL__ -fno-stack-protector -m32"
9
10./configure --enable-kernel --disable-doc --host i386
11
12# Compile cacademo, leave it as an object
13cd caca && make && cd ..
14cd examples && make dithering.o && cd ..
15
16cd kernel
17
18# Bootsector
19nasm -f bin -o bootsect.bin boot/bootsect.asm
20# Interruption handlers
21nasm -f elf -o int.o boot/int.asm
22
23##### Boot (x86)
24# Stage2, loads GDT, PIC, IDT, interrupts, then calls kmain()
25gcc $MYCFLAGS boot/stage2.c -c
26# GDT installation, called by stage2
27gcc $MYCFLAGS boot/gdt.c -c
28# PIC installation, called by stage2
29gcc $MYCFLAGS boot/pic.c -c
30# IDT installation, called by stage2
31gcc $MYCFLAGS boot/idt.c -c
32# Interruptions installation, called by stage2
33gcc $MYCFLAGS boot/interruptions.c -c
34
35##### Drivers
36# Floppy driver
37gcc $MYCFLAGS drivers/floppy.c -c
38# Processor driver
39gcc $MYCFLAGS drivers/processor.c -c
40# Keyboard handler
41gcc $MYCFLAGS drivers/keyboard.c -c
42# Memory driver
43gcc $MYCFLAGS drivers/memory.c -c
44# Programmable Interval Timer driver
45gcc $MYCFLAGS drivers/timer.c -c
46
47# Minimalistic libc
48gcc $MYCFLAGS klibc.c -c
49
50# Kernel by itself, contains cmain() which calls main()
51gcc $MYCFLAGS kernel.c -c
52
53# Link everything but bootsector, kernel.o MUST be at the very end
54ld --oformat binary -Ttext 1000 stage2.o gdt.o pic.o int.o idt.o interruptions.o keyboard.o memory.o timer.o floppy.o processor.o klibc.o kernel.o ../caca/.libs/libcaca.a -Map kernel.map    -o kern.bin
55
56ls -ail kern.bin
57cd ..
58
59# Copy bootsector at the very beginning of the floppy (first sector/512 bytes of the image), then kernel right after
60cat kernel/bootsect.bin  kernel/kern.bin /dev/zero | dd of=cacademo.img bs=512 count=2500
61
62