1# Variables
2ASM = nasm
3CC = gcc
4LD = ld
5QEMU = qemu-system-x86_64
6
7# Flags
8CFLAGS = -m32 -ffreestanding -fno-pie -fno-stack-protector -mno-sse -mno-mmx -mno-sse2 -c
9LDFLAGS = -m elf_i386 -T link.ld --oformat binary
10
11# Objects
12OBJS = entry.o kmain.o idt.o interrupts.o keyboard.o shell.o
13
14# Targets
15all: os-image.bin
16
17os-image.bin: boot.bin kernel.bin
18 cat $^ > $@
19 truncate -s 10k $@
20
21boot.bin: boot.asm
22 $(ASM) $< -f bin -o $@
23
24kernel.bin: $(OBJS)
25 $(LD) $(LDFLAGS) -o $@ $^
26
27entry.o: entry.asm
28 $(ASM) $< -f elf -o $@
29
30interrupts.o: interrupts.asm
31 $(ASM) $< -f elf -o $@
32
33%.o: %.c
34 $(CC) $(CFLAGS) $< -o $@
35
36run: os-image.bin
37 $(QEMU) -drive format=raw,file=$<
38
39clean:
40 rm -f *.bin *.o