SRCS=example.c abs.c idxmin.c search.c order3.c sum.c
OBJS=$(SRCS:.c=.o)
HDRS=$(SRCS:.c=.h)

BASE_OPTIONS=-O0 -g -fsanitize=address,undefined

tests-base.o: tests-base.c
	@echo "Compiling $@"
	@${CC} $< -c ${BASE_OPTIONS} -o $@

%.o: %.c %.h
	@echo "Compiling $@ with instrumentation"
	@${CC} $< -c -fprofile-arcs -ftest-coverage ${BASE_OPTIONS} -o $@

tests-base: tests-base.o ${OBJS}
	@echo "Linking   $@ with instrumentation"
	@${CC} $^ --coverage ${BASE_OPTIONS} -o $@

tests: tests-base
	@echo "Running tests ..."
	@./tests-base

coverage: clean-coverage tests
	@echo "Generating $@.html"
	@gcovr  --decisions --html-details $@.html

.PHONY: clean clean-coverage

clean-coverage:
	@rm -f *.html *.gcda

clean: clean-coverage
	@rm -f *.o *.gcno tests-base
