all: setup asm rust link image clean

mkrun: all run

setup:
  mkdir temp

asm:
	nasm -f elf64 src/asm/multiboot_header.asm -o temp/multiboot_header.asm.o
	nasm -f elf64 src/asm/long_mode_init.asm -o temp/long_mode_init.asm.o
	nasm -f elf64 src/asm/boot.asm -o temp/boot.asm.o

rust:
	cargo build

link:
	ld -n -o temp/kernel.bin --gc-sections -T link-cfg/linker.ld temp/multiboot_header.asm.o temp/long_mode_init.asm.o temp/boot.asm.o target/x86_64-rustboot/debug/librustboot.a

image:
	mkdir isofiles
	mkdir isofiles/boot
	mkdir isofiles/boot/grub
	cp temp/kernel.bin isofiles/boot/kernel.bin
	cp link-cfg/grub.cfg isofiles/boot/grub/grub.cfg
	grub-mkrescue -o build/os.iso isofiles 2> /dev/null

clean:
	rm -rf temp
	rm -rf isofiles

scrub: clean
  cargo clean
  cargo update --verbose

run:
	qemu-system-x86_64 -cdrom build/os.iso
