all: ../src/disk0.c
	
mep: mep.c
	gcc -g -ggdb -o mep mep.c -lwolfssl

../src/disk0.c: mep FORCE
	dd if=/dev/zero of=disk0.img bs=1K count=128
	sudo mkfs.vfat disk0.img
	sudo mkdir -p tmpfs
	sudo mount -o loop disk0.img tmpfs
	sudo mkdir -p tmpfs/mep
	sudo cp mep.c mep tmpfs/mep
	sudo cp Makefile.flash tmpfs/mep/Makefile
	sudo cp ../README.md tmpfs
	sudo umount tmpfs
	xxd -i disk0.img | sed -e "s/unsigned/const unsigned/g" \
	   | sed -e "s/char/char __attribute__((section(\".disk0\")))/g" > ../src/disk0.c 
	

clean:
	rm -f mep fatfs ../fatfs.ld
	sudo umount tmpfs || true
	sudo rm -rf tmpfs

FORCE: 

