-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
67 lines (47 loc) · 1.55 KB
/
Makefile
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
QEMU = qemu-system-i386
QEMUopts = -usb -drive file=andromedos.img,media=disk,format=raw
define QEMUdebug =
-S -s \
-chardev file,path=seabios.log,id=seabios \
-device isa-debugcon,iobase=0x402,chardev=seabios \
$(QEMUopts)
endef
CC=i686-elf-gcc
CFLAGS=-std=gnu11 -m32 -g -ffreestanding -nostdlib -lgcc -Wall -Wextra
LD=i686-elf-ld
KOBJS=entry.o main.o log.o memory.o terminal.o general.o shell.o
KDEPS=$(addprefix kernel/, $(KOBJS))
export PATH := deps/bin:$(PATH)
# Directives
build: andromedos.img
echo "Build Complete!"
run: build
$(QEMU) $(QEMUopts)
debug: build kernel/debug.elf
setsid $(QEMU) $(QEMUdebug) & true
gdb -x gdbinit
clean:
find . -type f -regextype posix-extended \
-regex ".*\.(img|log|o|gz)$$" -delete
# Bootloader
boot/boot.img: boot/boot1.img boot/boot2.img
cat boot/boot1.img boot/boot2.img >boot/boot.img
boot/boot1.img: boot/boot1.nasm
nasm -f bin -o boot/boot1.img boot/boot1.nasm
boot/boot2.img: boot/boot2.nasm
nasm -f bin -o boot/boot2.img boot/boot2.nasm
# Kernel
%.o: %.s
$(CC) -c -o $@ $< $(CFLAGS)
%.o: %.c kernel/*.h
$(CC) -c -o $@ $< $(CFLAGS)
kernel/kernel.img: kernel/link.ld $(KDEPS)
$(LD) -T kernel/link.ld -o kernel/kernel.img $(KDEPS)
# There's probably a better way to do this that takes into account the linker
# file, but this is good enough for now.
kernel/debug.elf: $(KDEPS)
$(LD) -r -o kernel/debug.elf $(KDEPS)
# Final Processing
andromedos.img: boot/boot.img kernel/kernel.img scripts/postprocess.py
cat boot/boot.img kernel/kernel.img >andromedos.img
python3 scripts/postprocess.py andromedos.img