# Default target is x86_64-unknown-none TARGET ?= "x86_64-unknown-none" # Limine BIOS file directory LIMINEDIR ?= "/usr/share/limine" # QEMU system is set accordingly and automatically qemu = "qemu-system-x86_64" # List of required BIOS files limine-files = limine-bios.sys limine-bios-cd.bin limine-bios-uefi-cd.bin BOOTX64.EFI BOOTIA32.EFI BOOTAA64.EFI BOOTLOONGARCH64.EFI BOOTRISCV64.EFI # Properly set QEMU command ifeq ($(TARGET),x86_64-unknown-none) qemu = "qemu-system-x86_64" else ifeq ($(TARGET),riscv64gc-unknown-none-elf) qemu = "qemu-system-riscv64" else ifeq ($(TARGET),aarch64-unknown-none) qemu = "qemu-system-aarch64" qemu += "-machine" qemu += "orangepi-pc" else ifeq ($(TARGET),loongarch64-unknown-none) qemu = "qemu-system-loongarch64" endif executables = rustup xorriso limine tree $(qemu) all: kernel iso run checkenv: $(info "Limine directory: $(LIMINEDIR)") $(foreach file,$(limine-files),\ $(if $(shell test -f $(LIMINEDIR)/$(file) | echo "it exists"),$(info "Found $(file)"),$(error "No $(file) in $(LIMINEDIR)"))) $(foreach exec,$(executables),\ $(if $(shell which $(exec)),$(info "Found $(exec)"),$(error "No $(exec) in PATH"))) # Prepare toolchain prepare: checkenv rustup install nightly rustup target add $(TARGET) # Run the ISO in an emulator. run: iso $(qemu) -drive file=build/gila.iso,format=raw,index=0,media=disk # Build the bootable kernel image. .PHONY: build/kernel kernel: prepare $(shell find src/kernel/ -type f -name *.rs) $(shell find src/kernel/ -type f -name linker.ld) cargo build --bin kernel --release -Zunstable-options --artifact-dir=build # Build a bootable ISO and install Limine. .PHONY: build/gila.iso iso: kernel limine.conf mkdir -p build/iso/boot/limine mkdir -p build/iso/EFI/BOOT # Copy Limine files cp ./limine.conf build/iso/ cp $(LIMINEDIR)/limine-bios.sys build/iso/boot/limine/ cp $(LIMINEDIR)/limine-bios-cd.bin build/iso/boot/limine/ cp $(LIMINEDIR)/limine-uefi-cd.bin build/iso/boot/limine/ cp $(LIMINEDIR)/BOOTX64.EFI build/iso/EFI/BOOT/ cp $(LIMINEDIR)/BOOTIA32.EFI build/iso/EFI/BOOT/ cp $(LIMINEDIR)/BOOTAA64.EFI build/iso/EFI/BOOT/ cp $(LIMINEDIR)/BOOTLOONGARCH64.EFI build/iso/EFI/BOOT cp $(LIMINEDIR)/BOOTRISCV64.EFI build/iso/EFI/BOOT # Copy kernel mv build/kernel build/iso/boot/ # Build filesystem tree mkdir -p build/iso/system/bin mkdir -p build/iso/system/tmp mkdir -p build/iso/system/cfg xorriso -as mkisofs -b boot/limine/limine-bios-cd.bin -no-emul-boot \ -boot-load-size 4 -boot-info-table --efi-boot \ boot/limine/limine-uefi-cd.bin -efi-boot-part --efi-boot-image \ --protective-msdos-label build/iso -o build/gila.iso limine bios-install build/gila.iso tree build/iso/ clean: rm -rf build cargo clean