# The input timeout per input: the real timeout.c on the host, its thread
# run one pass at a time over a fake mc_interface (main.c). Built single
# motor and dual motor.
#
# `make old` runs the same against timeout.c as it was before (44e9e6e7, one
# switch for every input), where the tests marked [new] fail: the proof
# that they test the change. It needs git and is not part of `run`.

CC = gcc
CFLAGS = -O1 -g -Wall -Wextra -Wundef -Wno-unused-parameter -std=gnu99 \
         -I. -I../.. -DNO_STM32 -DCAN_ENABLE=1
SAN = -fsanitize=address,undefined -fno-sanitize-recover=all
DEPS = main.c $(wildcard *.h) ../../timeout.c ../../timeout.h ../../chconf.h ../../datatypes.h
OLD_REV = 44e9e6e7

.PHONY: all run old clean

all: test_single test_dual

test_single: $(DEPS)
	$(CC) $(CFLAGS) $(SAN) -DTIMEOUT_C='"../../timeout.c"' main.c -o $@

test_dual: $(DEPS)
	$(CC) $(CFLAGS) $(SAN) -DHW_HAS_DUAL_MOTORS -DTIMEOUT_C='"../../timeout.c"' main.c -o $@

run: all
	./test_single && ./test_dual

old:
	mkdir -p old
	git -C ../.. show $(OLD_REV):timeout.c > old/timeout.c
	git -C ../.. show $(OLD_REV):timeout.h > old/timeout.h
	git -C ../.. show $(OLD_REV):chconf.h > old/chconf.h
	$(CC) $(CFLAGS) -Iold -DOLD_TIMEOUT -DTIMEOUT_C='"old/timeout.c"' main.c -o old/test_single
	$(CC) $(CFLAGS) -Iold -DOLD_TIMEOUT -DHW_HAS_DUAL_MOTORS -DTIMEOUT_C='"old/timeout.c"' main.c -o old/test_dual
	-./old/test_single
	-./old/test_dual

clean:
	rm -rf test_single test_dual old
