2023-02-27 18:42:58 +13:00
|
|
|
# Nuke built-in rules and variables.
|
|
|
|
override MAKEFLAGS += -rR
|
|
|
|
|
2023-03-25 14:47:38 +13:00
|
|
|
override IMAGE_NAME := barebones
|
|
|
|
|
2023-07-08 02:25:57 +12:00
|
|
|
# Convenience macro to reliably declare user overridable variables.
|
|
|
|
define DEFAULT_VAR =
|
|
|
|
ifeq ($(origin $1),default)
|
|
|
|
override $(1) := $(2)
|
|
|
|
endif
|
|
|
|
ifeq ($(origin $1),undefined)
|
|
|
|
override $(1) := $(2)
|
|
|
|
endif
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Compiler for building the 'limine' executable for the host.
|
|
|
|
override DEFAULT_HOST_CC := cc
|
|
|
|
$(eval $(call DEFAULT_VAR,HOST_CC,$(DEFAULT_HOST_CC)))
|
|
|
|
|
2022-03-26 17:54:00 +13:00
|
|
|
.PHONY: all
|
2023-03-25 14:47:38 +13:00
|
|
|
all: $(IMAGE_NAME).iso
|
2022-03-26 17:54:00 +13:00
|
|
|
|
|
|
|
.PHONY: all-hdd
|
2023-03-25 14:47:38 +13:00
|
|
|
all-hdd: $(IMAGE_NAME).hdd
|
2022-03-26 17:54:00 +13:00
|
|
|
|
|
|
|
.PHONY: run
|
2023-03-25 14:47:38 +13:00
|
|
|
run: $(IMAGE_NAME).iso
|
|
|
|
qemu-system-x86_64 -M q35 -m 2G -cdrom $(IMAGE_NAME).iso -boot d
|
2022-03-26 17:54:00 +13:00
|
|
|
|
|
|
|
.PHONY: run-uefi
|
2023-03-27 12:53:14 +13:00
|
|
|
run-uefi: ovmf $(IMAGE_NAME).iso
|
|
|
|
qemu-system-x86_64 -M q35 -m 2G -bios ovmf/OVMF.fd -cdrom $(IMAGE_NAME).iso -boot d
|
2022-03-26 17:54:00 +13:00
|
|
|
|
|
|
|
.PHONY: run-hdd
|
2023-03-25 14:47:38 +13:00
|
|
|
run-hdd: $(IMAGE_NAME).hdd
|
|
|
|
qemu-system-x86_64 -M q35 -m 2G -hda $(IMAGE_NAME).hdd
|
2022-03-26 17:54:00 +13:00
|
|
|
|
|
|
|
.PHONY: run-hdd-uefi
|
2023-03-27 12:53:14 +13:00
|
|
|
run-hdd-uefi: ovmf $(IMAGE_NAME).hdd
|
|
|
|
qemu-system-x86_64 -M q35 -m 2G -bios ovmf/OVMF.fd -hda $(IMAGE_NAME).hdd
|
2022-03-26 17:54:00 +13:00
|
|
|
|
2023-03-27 12:53:14 +13:00
|
|
|
ovmf:
|
|
|
|
mkdir -p ovmf
|
2023-07-08 01:14:24 +12:00
|
|
|
cd ovmf && curl -Lo OVMF.fd https://retrage.github.io/edk2-nightly/bin/RELEASEX64_OVMF.fd
|
2022-03-26 17:54:00 +13:00
|
|
|
|
|
|
|
limine:
|
2023-06-21 03:55:01 +12:00
|
|
|
git clone https://github.com/limine-bootloader/limine.git --branch=v5.x-branch-binary --depth=1
|
2023-07-08 02:25:57 +12:00
|
|
|
$(MAKE) -C limine CC="$(HOST_CC)"
|
2022-03-26 17:54:00 +13:00
|
|
|
|
|
|
|
.PHONY: kernel
|
|
|
|
kernel:
|
|
|
|
$(MAKE) -C kernel
|
|
|
|
|
2023-03-25 14:47:38 +13:00
|
|
|
$(IMAGE_NAME).iso: limine kernel
|
2022-03-26 17:54:00 +13:00
|
|
|
rm -rf iso_root
|
|
|
|
mkdir -p iso_root
|
2023-07-08 02:25:57 +12:00
|
|
|
cp -v kernel/kernel.elf \
|
2023-06-21 03:55:01 +12:00
|
|
|
limine.cfg limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/
|
2023-06-11 05:53:10 +12:00
|
|
|
mkdir -p iso_root/EFI/BOOT
|
2023-07-08 02:25:57 +12:00
|
|
|
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/
|
|
|
|
cp -v limine/BOOTIA32.EFI iso_root/EFI/BOOT/
|
2023-06-21 03:55:01 +12:00
|
|
|
xorriso -as mkisofs -b limine-bios-cd.bin \
|
2022-03-26 17:54:00 +13:00
|
|
|
-no-emul-boot -boot-load-size 4 -boot-info-table \
|
2023-06-21 03:55:01 +12:00
|
|
|
--efi-boot limine-uefi-cd.bin \
|
2022-03-26 17:54:00 +13:00
|
|
|
-efi-boot-part --efi-boot-image --protective-msdos-label \
|
2023-03-25 14:47:38 +13:00
|
|
|
iso_root -o $(IMAGE_NAME).iso
|
2023-06-21 03:55:01 +12:00
|
|
|
./limine/limine bios-install $(IMAGE_NAME).iso
|
2022-03-26 17:54:00 +13:00
|
|
|
rm -rf iso_root
|
|
|
|
|
2023-03-25 14:47:38 +13:00
|
|
|
$(IMAGE_NAME).hdd: limine kernel
|
|
|
|
rm -f $(IMAGE_NAME).hdd
|
|
|
|
dd if=/dev/zero bs=1M count=0 seek=64 of=$(IMAGE_NAME).hdd
|
|
|
|
parted -s $(IMAGE_NAME).hdd mklabel gpt
|
|
|
|
parted -s $(IMAGE_NAME).hdd mkpart ESP fat32 2048s 100%
|
|
|
|
parted -s $(IMAGE_NAME).hdd set 1 esp on
|
2023-06-21 03:55:01 +12:00
|
|
|
./limine/limine bios-install $(IMAGE_NAME).hdd
|
2023-03-25 14:47:38 +13:00
|
|
|
sudo losetup -Pf --show $(IMAGE_NAME).hdd >loopback_dev
|
2022-03-26 17:54:00 +13:00
|
|
|
sudo mkfs.fat -F 32 `cat loopback_dev`p1
|
|
|
|
mkdir -p img_mount
|
|
|
|
sudo mount `cat loopback_dev`p1 img_mount
|
|
|
|
sudo mkdir -p img_mount/EFI/BOOT
|
2023-06-21 03:55:01 +12:00
|
|
|
sudo cp -v kernel/kernel.elf limine.cfg limine/limine-bios.sys img_mount/
|
2023-07-08 02:25:57 +12:00
|
|
|
sudo cp -v limine/BOOTX64.EFI img_mount/EFI/BOOT/
|
|
|
|
sudo cp -v limine/BOOTIA32.EFI img_mount/EFI/BOOT/
|
2022-03-26 17:54:00 +13:00
|
|
|
sync
|
|
|
|
sudo umount img_mount
|
|
|
|
sudo losetup -d `cat loopback_dev`
|
|
|
|
rm -rf loopback_dev img_mount
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2023-03-25 14:47:38 +13:00
|
|
|
rm -rf iso_root $(IMAGE_NAME).iso $(IMAGE_NAME).hdd
|
2022-03-26 17:54:00 +13:00
|
|
|
$(MAKE) -C kernel clean
|
|
|
|
|
|
|
|
.PHONY: distclean
|
|
|
|
distclean: clean
|
2023-03-27 12:53:14 +13:00
|
|
|
rm -rf limine ovmf
|
2022-03-26 17:54:00 +13:00
|
|
|
$(MAKE) -C kernel distclean
|