CC  = clang --target=aarch64-none-elf
RUST = $(shell rustc --print sysroot)
# rust-lld needs libLLVM.dylib from the toolchain's lib dir
LD  = DYLD_LIBRARY_PATH=$(RUST)/lib $(RUST)/lib/rustlib/aarch64-apple-darwin/bin/rust-lld -flavor gnu
CFLAGS = -ffreestanding -nostdlib -mgeneral-regs-only -O2 -Wall

kernel.elf: boot.o kernel.o linker.ld
	$(LD) -T linker.ld -o $@ boot.o kernel.o

%.o: %.S
	$(CC) $(CFLAGS) -c $< -o $@

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

# Ctrl-A then X quits QEMU
run: kernel.elf
	qemu-system-aarch64 -M virt -cpu cortex-a72 -nographic -kernel kernel.elf

clean:
	rm -f *.o kernel.elf

.PHONY: run clean
