all:
	arm-none-eabi-gcc -ggdb -mcpu=Cortex-M4 -mthumb -r -Tlibpqscheme.ld -fPIC -nostartfiles -o libpqscheme_test.elf libpqscheme_test.c -Iruntime_mps2/out/an386/pack/include
	arm-none-eabi-gcc -ggdb -mcpu=Cortex-M4 -mthumb -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 \
    	-semihosting \
		-device loader,file=libpqscheme_test.elf,addr=0x20000000
#		-S -gdb tcp::1234
#	    -monitor unix:/tmp/qemu-monitor,server,nowait


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

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