.SUFFIXES:





LANG0C=$(CURDIR)/../2-lang0c/lang0c.exe

all: lang0ll.exe

%.exe: %.s
	clang $^ -o $@

%.s: %.ll
	llc --relocation-model=pic $^

lang0ll0.c: lang0ll.lang0 $(LANG0C)
	cat $< | $(LANG0C) > $@

lang0ll0.o: lang0ll0.c
	gcc -c $<

lang0ll0.exe: lang0ll0.o
	gcc -o $@ $<

lang0ll1.ll: lang0ll.lang0 lang0ll0.exe
	cat $< | ./lang0ll0.exe > $@
# Cannot diff on the first iteration - platform change

lang0ll2.ll: lang0ll.lang0 lang0ll1.exe
	cat $< | ./lang0ll1.exe > $@
	-diff lang0ll1.ll lang0ll2.ll

lang0ll.ll: lang0ll.lang0 lang0ll2.exe
	cat $< | ./lang0ll2.exe > $@
	-diff lang0ll2.ll lang0ll.ll

foo.ll: foo.c
	clang -S -emit-llvm $^

clean:
	rm -f lang0ll*.py lang0ll*.ll lang0ll*.o lang0ll*.exe foo.ll foo.o foo.exe
