hazel/Makefile
2024-07-03 11:23:21 -04:00

46 lines
1019 B
Makefile

CC = i686-elf-gcc
AS = nasm
BUILDDIR := build
INCLUDEDIR := include
KSRC := $(wildcard kernel/*.asm kernel/*.c)
KOBJ := $(addprefix $(BUILDDIR)/, \
$(notdir \
$(patsubst %.asm,%.o, $(patsubst %.c,%.o, $(KSRC)))))
KIMG := kernel.bin
LSRC := $(wildcard lib/*.c)
LOBJ := $(addprefix $(BUILDDIR)/, \
$(notdir \
$(patsubst %.c,%.o, $(LSRC))))
ISO := Hazel.iso
CFLAGS := -ffreestanding -Wall -Wextra -Werror -I $(INCLUDEDIR) -I lib
LDFLAGS := -ffreestanding -nostdlib -lgcc -T kernel/kernel.ld
QEMUFLAGS := -cdrom $(BUILDDIR)/$(ISO) \
-d int
-m 512M \
-serial stdio
$(BUILDDIR)/$(KIMG): $(KOBJ) $(LOBJ)
$(CC) $^ -o $@ $(LDFLAGS)
$(BUILDDIR)/%.o: */%.asm
$(AS) -felf32 $^ -o $@
$(BUILDDIR)/%.o: */%.c
$(CC) $(CFLAGS) -c $^ -o $@
kernel: $(BUILDDIR)/$(KIMG)
$(BUILDDIR)/$(ISO): kernel
rm -f $(BUILDDIR)/$(ISO)
cp $(BUILDDIR)/$(KIMG) boot/$(KIMG)
grub-mkrescue -o $(BUILDDIR)/$(ISO) .
iso: $(BUILDDIR)/$(ISO)
qemu: iso
qemu-system-i386 $(QEMUFLAGS)
clean:
rm -f build/* boot/*.bin