CM=../cmeta
BL=..

all: prereq exit42 cons-test map-test1 map-test2 mem-test1 mem-test2 print-arith-test read-test read-write-test write-test

exit42: exit42.blc
	$(BL)/blc < $< | $(BL)/blc-asm | cat $(BL)/blcrt - | $(CM)/elfwrap > $@
	chmod +x $@

cons-test: cons-test.blc cons.blc write.blc
	cat cons.blc write.blc $< | $(BL)/blc | $(BL)/blc-asm | cat $(BL)/blcrt - | $(CM)/elfwrap > $@
	chmod +x $@

map-test1: map-test1.blc cons.blc map.blc write.blc y.blc
	cat cons.blc write.blc y.blc map.blc $< | $(BL)/blc | $(BL)/blc-asm | cat $(BL)/blcrt - | $(CM)/elfwrap > $@
	chmod +x $@

map-test2: map-test2.blc cons.blc map.blc write.blc y.blc
	cat cons.blc write.blc y.blc map.blc $< | $(BL)/blc | $(BL)/blc-asm | cat $(BL)/blcrt - | $(CM)/elfwrap > $@
	chmod +x $@

mem-test1: mem-test1.blc malloc.blc print.blc write.blc y.blc
	cat write.blc y.blc print.blc malloc.blc $< | $(BL)/blc | $(BL)/blc-asm | cat $(BL)/blcrt - | $(CM)/elfwrap > $@
	chmod +x $@

mem-test2: mem-test2.blc malloc.blc write.blc y.blc
	cat write.blc y.blc malloc.blc $< | $(BL)/blc | $(BL)/blc-asm | cat $(BL)/blcrt - | $(CM)/elfwrap > $@
	chmod +x $@

print-arith-test: print-arith-test.blc print.blc write.blc y.blc
	cat write.blc y.blc print.blc $< | $(BL)/blc | $(BL)/blc-asm | cat $(BL)/blcrt - | $(CM)/elfwrap > $@
	chmod +x $@

read-test: read-test.blc malloc.blc print.blc write.blc y.blc
	cat write.blc y.blc malloc.blc print.blc read.blc $< | $(BL)/blc | $(BL)/blc-asm | cat $(BL)/blcrt - | $(CM)/elfwrap > $@
	chmod +x $@

read-write-test: read-write-test.blc malloc.blc print.blc write.blc y.blc
	cat write.blc y.blc malloc.blc print.blc read.blc $< | $(BL)/blc | $(BL)/blc-asm | cat $(BL)/blcrt - | $(CM)/elfwrap > $@
	chmod +x $@

write-test: write-test.blc write.blc
	cat write.blc $< | $(BL)/blc | $(BL)/blc-asm | cat $(BL)/blcrt - | $(CM)/elfwrap > $@
	chmod +x $@

clean:
	$(RM) exit42 cons-test map-test1 map-test2 mem-test1 mem-test2 print-arith-test read-test read-write-test write-test

prereq:
	$(MAKE) -C $(CM) elfwrap
	$(MAKE) -C $(BL) all

.PHONY: all clean prereq
