# Copyright © 2019, 2020 Göran Weinholt
# SPDX-License-Identifier: AGPL-3.0-or-later

ROOT = ../..
export LOKO_SOURCE=$(ROOT)/.akku/lib

all: pc-repl

.akku/env:
	akku install

pc-repl: pc-repl.sps .akku/env $(ROOT)/loko
	.akku/env $(ROOT)/loko -feval --compile $< --output $@

run: pc-repl testdisk.img
	qemu-system-x86_64 -enable-kvm -kernel pc-repl -m 1024 -serial stdio -debugcon vc \
	  -k sv -hda testdisk.img \
	  -append 'LOKO_LIBRARY_PATH=/lib CONSOLE=com1'

testpart.img: .akku/lib
	dd if=/dev/zero of=$@.tmp bs=512 count=32768
	mformat -i $@.tmp
	cp -rL .akku/lib lib
	find lib -ipath '*:*' -delete
	mcopy -i $@.tmp -sb lib "::"
	rm -rf lib
	mv -f $@.tmp $@

testdisk.img: testpart.img
	dd if=testpart.img of=$@.tmp bs=512 seek=1
	echo "start=1, size=32768, type=6" | /sbin/sfdisk $@.tmp
	mv -f $@.tmp $@

clean:
	rm -f testpart.img testdisk.img
	rm -rf lib
	rm -f pc-repl

distclean:
	rm -rf .akku
