-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
53 lines (39 loc) · 1.17 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
QEMU = qemu-system-x86_64
CC = i386-elf-gcc
CFLAGS = -ffreestanding -O2 -Wall -pedantic -Wextra -fno-pic
LD = i386-elf-ld
AS = nasm
DEPS = $(patsubst %.c,${OBJDIR}/%.o,kernel.c io/io.c io/vga.c std/math.c std/vec.c)
OBJDIR = obj
IMGDIR = img
# TODO: do something about make_directories
# it is kind of convoluted
all: make_directories bootdisk.raw
run: all
${QEMU} \
-enable-kvm \
-m 2048 \
-drive format=raw,file=./img/bootdisk.raw
# The disk is padded to 1.44MB (floppy size)
bootdisk.raw: ${OBJDIR}/stage1.bin ${OBJDIR}/stage2.bin ${OBJDIR}/kernel.bin
cat $^ > ${IMGDIR}/bootdisk.raw
dd if=/dev/null of=${IMGDIR}/bootdisk.raw bs=1 count=1 seek=1474560
# Assembly (bootloader) files
${OBJDIR}/%.bin: src/boot/%.s
${AS} $< -f bin -i "src/boot/include" -o $@
# Kernel files
${OBJDIR}/kernel.bin: ${OBJDIR}/kernel_entry.o ${DEPS}
${LD} -o $@ -T linker.ld $^ --oformat binary
${OBJDIR}/%.o: src/kernel/%.c
${CC} -c $< -o $@ ${CFLAGS}
${OBJDIR}/kernel_entry.o: src/kernel/entry.s
${AS} $< -f elf -o $@
.PHONY: clean make_directories
clean:
rm -rf img
rm -rf obj
make_directories: ${OBJDIR} ${IMGDIR}
${OBJDIR}:
mkdir -p ${OBJDIR}/{io,std}
${IMGDIR}:
mkdir -p ${IMGDIR}