CC := gcc

CPPFLAGS := -I../include
CFLAGS   := -Wall -Wextra -std=c11
LDFLAGS  := -L../lib
#LDLIBS   := -laws_tape -lebcdic_utils -lvdasd -lvpds -lvtape -lviebcopy
LDLIBS   := -ltsc_list -ltsc_tree -ltsc_hash \
	-lviebcopy -lvtape -lvpds -lvdasd -laws_tape -lmvs_utils -lmvs_datetime -lmvs_types -lebcdic_utils

LIBRARY := ../lib/libaws_tape.a

# Discover every C source file in this directory.
SOURCES := $(wildcard *.c)

# test_example.c becomes test_example.
TESTS := $(SOURCES:.c=)

# Dependency files generated by the compiler.
DEPS := $(SOURCES:.c=.d)

# "make" builds every discovered test.
all: $(TESTS)

# Build any individual test:
#     make test_aws_tape
#
# $< is the matching .c source file.
# $@ is the executable being created.
%: %.c $(LIBRARY)
	$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP $< \
		$(LDFLAGS) $(LDLIBS) -o $@

# Run every test executable.
check: all
	@set -e; \
	for test in $(TESTS); do \
		echo "Running ./$$test"; \
		./$$test; \
	done

# Remove generated executables and dependency files.
clean:
	rm -f $(TESTS) $(DEPS)

# Tests have no separately installed artifacts.
distclean: clean

-include $(DEPS)

.PHONY: all check clean distclean
