From 803ac0879b32c66473f4f9b7317581d62bff0f66 Mon Sep 17 00:00:00 2001 From: furtest Date: Sun, 15 Mar 2026 17:56:26 +0100 Subject: [PATCH] Auto find source files check for changes Previously the build process removed everything and did all the build again on each make invocation. This fixes this behaviour with two changes. First dynamically find the list of files to build using find instead of a manually written list. Then use implicit rules to only build files that need to be built again instead of recompiling everything. --- Makefile | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 8fb5756..e113160 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ BUILDDIR := build ELFFILE := pepperk -SOURCES = src/sched/spinlock.c src/debug/misc.c src/io/term/flanterm_backends/fb.c src/io/term/flanterm.c src/debug/panic.c src/debug/stacktrace.c src/boot/boot.c src/sched/scheduler.c src/sched/process.c src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c +SRC := src +SOURCES := $(shell find src -name '*.c') +OBJFILES := $(patsubst $(SRC)/%.c, $(BUILDDIR)/%.o, $(SOURCES)) CC := x86_64-elf-gcc CC_FLAGS=-Wall -Wextra -std=gnu99 -nostdlib -ffreestanding -fno-stack-protector -fno-omit-frame-pointer -fno-stack-check -fno-PIC -ffunction-sections -fdata-sections -mcmodel=kernel @@ -11,17 +13,20 @@ LD := x86_64-elf-ld .PHONY: build build-iso debug debug2 run clean -$(ELFFILE): - mkdir -p $(BUILDDIR) - rm -f *.o $(BUILDDIR)/*.o - $(CC) -g -c -Isrc $(SOURCES) $(CC_PROBLEMATIC_FLAGS) $(CC_FLAGS) - mv *.o $(BUILDDIR)/ +$(ELFFILE): $(BUILDDIR) $(OBJFILES) nasm -f elf64 src/idt/idt.S -o $(BUILDDIR)/idt_stub.o - $(LD) -o $(ELFFILE) -T linker.ld $(BUILDDIR)/*.o + $(LD) -o $(ELFFILE) -T linker.ld $(OBJFILES) $(BUILDDIR)/idt_stub.o nm -n $(ELFFILE) | awk '$$2 ~ /[TtDdBbRr]/ {print $$1, $$3}' > symbols.map python3 symbols.py nasm -f elf64 symbols.S -o $(BUILDDIR)/symbols.o - $(LD) -o $(ELFFILE) -T linker.ld $(BUILDDIR)/*.o + $(LD) -o $(ELFFILE) -T linker.ld $(OBJFILES) $(BUILDDIR)/idt_stub.o + +$(BUILDDIR): + @mkdir -p $(BUILDDIR) + +$(BUILDDIR)/%.o: $(SRC)/%.c + mkdir -p $(dir $@) + $(CC) -g -c -Isrc $< $(CC_PROBLEMATIC_FLAGS) $(CC_FLAGS) -o $@ limine/limine: rm -rf limine