.PHONY: all clean

all: 84_stable 84_unstable graph_test sort_test hello_world

clean:
	rm -f runtime.o 84.c 84_stable 84_unstable
	rm -f hello_world{,.c}
	rm -f graph_test{,.c}
	rm -f sort_test{,.c}

CC := gcc
CFLAGS := -std=gnu11 -g

84_stable: 84_stable.c runtime.o
	$(CC) $(CFLAGS) -o $@ $^

84_unstable: 84.c runtime.o
	$(CC) $(CFLAGS) -o $@ $^

# The rule is conservative as some files in *.84 don't affect the compiler.
# TODO Be more precise.
84.c: *.84 84_stable
	./84_stable 84

# The rule is conservative as some files in *.84 don't affect the target.
# TODO Be more precise.
graph_test sort_test hello_world: *.84 84_stable runtime.o
	./84_stable $@
	$(CC) $(CFLAGS) -o $@ $@.c runtime.o

runtime.o: runtime.c runtime.h
	$(CC) $(CFLAGS) -c $<