SRC_TESTS_HERE = $(ROOT)src/tests

SRC_TESTS_SRCS = $(sort $(wildcard $(SRC_TESTS_HERE)/*.c))

SRC_TESTS_TDB_TESTS = $(patsubst %.c,%.tdb,$(SRC_TESTS_SRCS))

SRC_TESTS_BDB_DONTRUN = bug627 test_abort1
SRC_TESTS_BDB_TESTS = $(patsubst %.c,%.bdb,$(filter-out $(patsubst %,%.c,$(SRC_TESTS_BDB_DONTRUN)),$(SRC_TEST_SRCS)))

SRC_TESTS_TDB_TESTS_THAT_SHOULD_FAIL = test_groupcommit_count

SRC_TESTS_ALL_TESTS = $(SRC_TESTS_TDB_TESTS) $(SRC_TESTS_BDB_TESTS)

SRC_TESTS_RUN_TDB_TESTS = $(patsubst %.tdb,%.tdbrun,$(SRC_TESTS_TDB_TESTS))
SRC_TESTS_RUN_BDB_TESTS = $(patsubst %.bdb,%.bdbrun,$(SRC_TESTS_BDB_TESTS))
SRC_TESTS_RUN_ALL_TESTS = $(SRC_TESTS_RUN_TDB_TESTS) $(SRC_TESTS_RUN_BDB_TESTS)

SRC_TESTS_TDB_LOADLIBES = -L$(ROOT)lib -ltokudb -Wl,-rpath,.. -lpthread
SRC_TESTS_TDB_CPPFLAGS  = -I$(ROOT)include

foo:
	echo $(SRC_TESTS_RUN_ALL_TESTS)

src/tests.checkdir: $(SRC_TESTS_RUN_ALL_TESTS)
src/tests.builddir: $(SRC_TESTS_ALL_TESTS)

$(SRC_TESTS_ALL_TESTS): $(SRC_TESTS_HERE)/test.h

%.bdbrun: %.bdb
	$(MAYBEATSIGN) $(UNSETTOKUENV) ./$< $(VERBVERBOSE)
%.tdbrun: %.tdb
	$(MAYBEATSIGN) $(SETTOKUENV) $(VGRIND) ./$< $(VERBVERBOSE) $(MAYBEINVERTERR)
%.bdb: %.c
	$(UNSETTOKUENV) cc  -DENVDIR=\"$<.bdbdir\" $(BDB_CPPFLAGS) -DUSE_BDB -DIS_TDB=0 $(CFLAGS) $< $(BDB_LDFLAGS) -ldb -o $@
%.tdb: %.c $(ROOT)lib/libtokudb.$(LIBEXT)
	$(SETTOKUENV) cc  -DENVDIR=\"$<.tdbdir\" -DUSE_TDB -DIS_TDB=1 $(CFLAGS) $(CPPFLAGS) $(SRC_TESTS_TDB_CPPFLAGS) $(SRC_TESTS_TDB_LOADLIBES) $< -o $@
%.tdbt: %.c
	$(SETTOKUENV) cc  -DENVDIR=\"$<.tdbdir\" -DUSE_TDB -DIS_TDB=1 $(CFLAGS) $(CPPFLAGS) $(SRC_TESTS_TDB_CPPFLAGS) $(TDB_TRACELOADLIBES) $< -o $@

$(SRC_TESTS_HERE)/test_logmax.tdb: CPPFLAGS += -D_BSD_SOURCE
$(SRC_TESTS_HERE)/test_thread_insert.tdb: CPPFLAGS += -D_GNU_SOURCE
$(SRC_TESTS_HERE)/test_thread_stack.tdb: CPPFLAGS += -D_GNU_SOURCE
