.SUFFIXES:

PYVERSION=3.12
PYPREFIX=/usr
INCLUDES=
CYTHON=cython3
LANG0PY=$(CURDIR)/../1-lang0py/lang0py.exe

all: lang0c.exe

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

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

lang0c0.py: lang0c.lang0 $(LANG0PY)
	cat $< | $(LANG0PY) > $@.tmp
	mv $@.tmp $@

lang0c0.c: lang0c0.py
	$(CYTHON) -3 --embed $<

lang0c0.o: lang0c0.c
	gcc -c $< -I$(PYPREFIX)/include/python$(PYVERSION)

lang0c0.exe: lang0c0.o
	gcc -o $@ $< -lpython$(PYVERSION)

lang0c1.c: lang0c.lang0 lang0c0.exe
	cat $< | ./lang0c0.exe > $@.tmp
	mv $@.tmp $@
# Cannot diff on the first iteration - platform change

lang0c2.c: lang0c.lang0 lang0c1.exe
	cat $< | ./lang0c1.exe > $@.tmp
	mv $@.tmp $@
	-diff lang0c1.c lang0c2.c

lang0c.c: lang0c.lang0 lang0c2.exe
	cat $< | ./lang0c2.exe > $@.tmp
	mv $@.tmp $@
	-diff lang0c2.c lang0c.c

clean:
	rm -f lang0c*.py lang0c*.c lang0c*.o lang0c*.exe
