rk/Makefile
2024-05-20 05:59:07 -04:00

50 lines
1.0 KiB
Makefile

CC = i686-elf-gcc
INCLUDE = -I./
CFLAGS = -Wall -Wextra -Werror -ffreestanding $(INCLUDE)
LDFLAGS = -T kernel.ld -ffreestanding -O3 -nostdlib -lgcc -mpreferred-stack-boundary=4
BUILDDIR = build
KERNELSRC := $(shell find . -name '*.c' -o -name '*.asm')
KERNELOBJ := $(addprefix $(BUILDDIR)/, \
$(notdir \
$(patsubst %.c,%.o,\
$(patsubst %.asm,%.o,$(KERNELSRC)))))
LIBSRC := $(shell find ./lib -name '*.c')
LIBOBJ := $(addprefix $(BUILDDIR)/, \
$(notdir \
$(patsubst %.c,%.o,$(LIBSRC))))
KERNELIMG := $(BUILDDIR)/kernel.bin
QEMUFLAGS = -d int -s \
-kernel $(KERNELIMG)
.PHONY: all kernel qemu clean docs
all: qemu
qemu: kernel
kernel: $(KERNELIMG)
$(KERNELIMG): $(KERNELOBJ) $(LIBOBJ)
$(CC) $^ -o $@ $(LDFLAGS)
$(BUILDDIR)/%.o: %.c
$(CC) $(CFLAGS) -c $^ -o $@
$(BUILDDIR)/%.o: %.asm
nasm -felf32 $^ -o $@
qemu: kernel
qemu-system-i386 $(QEMUFLAGS)
iso: kernel
cp $(BUILDDIR)/kernel.bin iso/boot/kernel.bin
grub-mkrescue -o $(BUILDDIR)/andewOS.iso iso/
clean:
rm -rf build/*.o build/*.bin iso/boot/*.bin
docs:
doxygen