# Compiler
CC = gcc

# Compiler flags
CFLAGS = -Wall -I/usr/include/CUnit

# Linker flags
LDFLAGS = -L/usr/lib -lcunit -lm -L. -lStructCunit

# Find all .c files except those with "Test" in their names
SRC_FILES = $(shell find . -name "*.c" ! -name "*Test.c")

# Find all Test .c files
TEST_FILES = $(shell find . -name "*Test.c")

# Set the output file name
OUTPUT = test_output

.PHONY: all
all: $(OUTPUT)

$(OUTPUT): $(SRC_FILES) $(TEST_FILES)
	$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)

.PHONY: run
run: $(OUTPUT)
	./$<

.PHONY: valgrind
valgrind: $(OUTPUT)
	valgrind --leak-check=full --track-origins=yes ./$(OUTPUT) -s

.PHONY: clean
clean:
	rm -f $(OUTPUT)
