79 lines
2.2 KiB
Makefile
79 lines
2.2 KiB
Makefile
|
|
# 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
|
|
|
|
# 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 $(qemu)
|
|
|
|
all: gila 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: build/gila.iso
|
|
|
|
$(qemu) -drive file=build/gila.iso,format=raw,index=0,media=disk
|
|
|
|
# Build the bootable kernel image.
|
|
.PHONY: build/iso/gila
|
|
gila: prepare $(shell find src -type f -name *.rs) $(shell find src -type f -name linker.ld)
|
|
|
|
mkdir -p build/iso/
|
|
cargo build --release -Z unstable-options --target=$(TARGET) --artifact-dir build/iso/
|
|
|
|
# Build a bootable ISO and install Limine.
|
|
.PHONY: build/gila.iso
|
|
iso: build/iso/gila limine.conf
|
|
|
|
mkdir -p build/iso/limine
|
|
mkdir -p build/iso/EFI/BOOT
|
|
|
|
cp ./limine.conf build/iso/
|
|
cp $(LIMINEDIR)/limine-bios.sys build/iso/limine/
|
|
cp $(LIMINEDIR)/limine-bios-cd.bin build/iso/limine/
|
|
cp $(LIMINEDIR)/limine-uefi-cd.bin build/iso/limine/
|
|
|
|
tree build/iso/
|
|
|
|
xorriso -as mkisofs -b limine/limine-bios-cd.bin -no-emul-boot \
|
|
-boot-load-size 4 -boot-info-table --efi-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
|
|
|
|
clean:
|
|
rm -rf build
|
|
cargo clean
|