# Prove It Works - companion Makefile
# Usage:
#   make test      build and run all tests against the correct code
#   make defects   build and run the same tests against the defective code
#   make clean     remove build output

CC      ?= gcc
CFLAGS  = -std=c99 -Wall -Wextra -Iinclude
BUILD   = build

SUITES  = traffic_light temperature_controller door_controller

.PHONY: all test defects clean

all: test

$(BUILD):
	mkdir -p $(BUILD)

$(BUILD)/test_%: tests/test_%.c src/%.c | $(BUILD)
	$(CC) $(CFLAGS) $^ -o $@

$(BUILD)/defect_%: tests/test_%.c defects/%_defect.c | $(BUILD)
	$(CC) $(CFLAGS) $^ -o $@

test: $(addprefix $(BUILD)/test_,$(SUITES))
	@for s in $(SUITES); do ./$(BUILD)/test_$$s; done

defects: $(addprefix $(BUILD)/defect_,$(SUITES))
	-@for s in $(SUITES); do ./$(BUILD)/defect_$$s; done

clean:
	rm -rf $(BUILD)
