# Needs only clang and lld: `make` builds inputmon.efi, and `make run`
# tries it in QEMU with OVMF.

# Windows's target gives a PE/COFF image and the Microsoft calling
# convention, which is what UEFI uses; -ffreestanding and -nostdlib keep
# out the Windows C library.
CC = clang
CFLAGS = --target=x86_64-unknown-windows -ffreestanding -std=c11 -O2 -Wall -Wextra
LDFLAGS = -nostdlib -fuse-ld=lld -Wl,-entry:efi_main -Wl,-subsystem:efi_application

OVMF = /usr/share/ovmf/OVMF.fd

inputmon.efi: inputmon.c efi.h proof9x16.h
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ inputmon.c

# OVMF boots esp/EFI/BOOT/BOOTX64.EFI from the directory QEMU presents as a
# FAT disk.  4 MiB of video memory limits OVMF's modes to 1360x768.
run: inputmon.efi
	mkdir -p esp/EFI/BOOT
	cp inputmon.efi esp/EFI/BOOT/BOOTX64.EFI
	qemu-system-x86_64 -machine accel=kvm:tcg -bios $(OVMF) -nic none \
		-drive format=raw,file=fat:rw:esp -device VGA,vgamem_mb=4 \
		-device qemu-xhci -device usb-kbd -device usb-mouse

clean:
	rm -rf inputmon.efi esp

.PHONY: run clean
