CC = gcc
CFLAGS ?= -std=c2x -Wall -Wextra -pedantic -pthread
LDFLAGS ?= 

# Some tests need -lm explicitly
MATH_TESTS = test_7_3_complex test_7_6_fenv test_7_10_math test_7_29_tgmath

all: $(patsubst %.c,%,$(wildcard *.c))

%: %.c
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(if $(findstring $@,$(MATH_TESTS)),-lm,)

test: all
	@fails=0; \
	for t in $(patsubst %.c,%,$(wildcard *.c)); do \
		echo "Running $$t..."; \
		./$$t || { echo "$$t FAILED"; fails+=1; }; \
	done; \
	exit $$fails

clean:
	rm -f $(patsubst %.c,%,$(wildcard *.c)) *.o
