.PHONY: all clean

all: 84_stable 84_unstable graph_test sort_test hello_world factorial

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

CC := gcc
CFLAGS := -std=gnu11 -g -Wall -Wno-unused-label

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 factorial: *.84 84_stable runtime.o
	./84_stable $@
	$(CC) $(CFLAGS) -o $@ $@.c runtime.o

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