6 Commits

Author SHA1 Message Date
b02a4b5284 Fix build-iso prerequisites 2026-03-15 18:05:24 +01:00
32f3889565 Move PHONY tags and fix clean
Move the PHONY tags to make them clearer to read.
Fix the clean rule so it deletes the build directory.
2026-03-15 18:01:35 +01:00
803ac0879b 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.
2026-03-15 17:56:26 +01:00
9fc55f98d8 Use variables for build and pepperk and rename build target.
Instead of hardcoding the names set them using a variable.
Also rename the target build to the name of the file it builds which is
in the ELFFILE variable.
2026-03-15 16:58:04 +01:00
11bd628821 Extract CC and LD to variables.
This allows to change the name of the compiler or linker when calling
make.
2026-03-15 16:57:29 +01:00
80d8b49560 Merge pull request 'spinlock' (#14) from spinlock into main
Reviewed-on: #14
2026-03-15 09:55:45 +01:00

View File

@@ -1,31 +1,41 @@
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
BUILDDIR := build
ELFFILE := pepperk
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 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
CC_PROBLEMATIC_FLAGS=-Wno-unused-parameter -Wno-unused-variable CC_PROBLEMATIC_FLAGS=-Wno-unused-parameter -Wno-unused-variable
.PHONY: build build-iso debug debug2 run clean LD := x86_64-elf-ld
build: $(ELFFILE): $(BUILDDIR) $(OBJFILES)
mkdir -p build nasm -f elf64 src/idt/idt.S -o $(BUILDDIR)/idt_stub.o
rm -f *.o build/*.o $(LD) -o $(ELFFILE) -T linker.ld $(OBJFILES) $(BUILDDIR)/idt_stub.o
x86_64-elf-gcc -g -c -Isrc $(SOURCES) $(CC_PROBLEMATIC_FLAGS) $(CC_FLAGS) # Get the symbols for debugging
mv *.o build/ nm -n $(ELFFILE) | awk '$$2 ~ /[TtDdBbRr]/ {print $$1, $$3}' > symbols.map
nasm -f elf64 src/idt/idt.S -o build/idt_stub.o
x86_64-elf-ld -o pepperk -T linker.ld build/*.o
nm -n pepperk | awk '$$2 ~ /[TtDdBbRr]/ {print $$1, $$3}' > symbols.map
python3 symbols.py python3 symbols.py
nasm -f elf64 symbols.S -o build/symbols.o nasm -f elf64 symbols.S -o $(BUILDDIR)/symbols.o
x86_64-elf-ld -o pepperk -T linker.ld build/*.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: limine/limine:
rm -rf limine rm -rf limine
git clone https://github.com/limine-bootloader/limine.git --branch=v9.x-binary --depth=1 git clone https://github.com/limine-bootloader/limine.git --branch=v9.x-binary --depth=1
$(MAKE) -C limine $(MAKE) -C limine
build-iso: limine/limine build build-iso: limine/limine $(ELFFILE)
rm -rf iso_root rm -rf iso_root
mkdir -p iso_root/boot mkdir -p iso_root/boot
cp -v pepperk iso_root/boot cp -v $(ELFFILE) iso_root/boot
mkdir -p iso_root/boot/limine mkdir -p iso_root/boot/limine
cp -v limine.conf iso_root/boot/limine cp -v limine.conf iso_root/boot/limine
mkdir -p iso_root/EFI/BOOT mkdir -p iso_root/EFI/BOOT
@@ -39,16 +49,20 @@ build-iso: limine/limine build
iso_root -o pepper.iso iso_root -o pepper.iso
./limine/limine bios-install pepper.iso ./limine/limine bios-install pepper.iso
.PHONY: debug
debug: debug:
/usr/bin/qemu-system-x86_64 -drive file=pepper.iso -s -S -d int -D qemu.log -no-reboot -no-shutdown & /usr/bin/qemu-system-x86_64 -drive file=pepper.iso -s -S -d int -D qemu.log -no-reboot -no-shutdown &
gdb pepperk --command=debug.gdb gdb $(ELFFILE) --command=debug.gdb
.PHONY: debug2
debug2: debug2:
/usr/bin/qemu-system-x86_64 -drive file=pepper.iso -s -S -d int -no-reboot -no-shutdown & /usr/bin/qemu-system-x86_64 -drive file=pepper.iso -s -S -d int -no-reboot -no-shutdown &
pwndbg pepperk --command=debug.gdb pwndbg $(ELFFILE) --command=debug.gdb
.PHONY: run
run: build-iso run: build-iso
/usr/bin/qemu-system-x86_64 -cdrom pepper.iso -serial stdio /usr/bin/qemu-system-x86_64 -cdrom pepper.iso -serial stdio
.PHONY: clean
clean: clean:
rm -rf *.o symbols.map symbols.S pepperk iso_root pepper.iso limine build/*.o rm -rf $(BUILDDIR) symbols.map symbols.S $(ELFFILE) iso_root pepper.iso limine