all:
	arm-none-eabi-gcc -r -Tlibpqscheme.ld -fPIC -nostartfiles -o libpqscheme_test.elf libpqscheme_test.c -Iruntime_mps2/out/an386/pack/include
	arm-none-eabi-gcc -mcpu=Cortex-M4 -Truntime_mps2/out/an386/pack/lib/mps2.ld -nostartfiles -o runner.elf runner.c -Lruntime_mps2/out/an386/pack/lib -lmps2-an386_runtime -Iruntime_mps2/out/an386/pack/include
	arm-none-eabi-ar rcs runner runner.elf

	arm-none-eabi-objcopy -O binary libpqscheme_test.elf libpqscheme_test.bin

run:
	qemu-system-arm \
    	-M mps2-an386 \
    	-cpu cortex-m4 \
    	-nographic \
    	-kernel runner.elf \
    	-initrd libpqscheme_test.elf \
    	-semihosting

clean:
	rm -rf *.o *.a *.elf

proper: clean
	cd runtime_mps2 && cmake --build --preset an386 --target clean