# The list of test is stored in a separate file, so that it can be shared with
# the Windows makefile, win.mak.
include tests

# The included file defined variable TESTBINS, which is a list of program
# names in format src/<testname>-test. Extract the base test names from it.
TESTNAMES = $(patsubst src/%-test,%, $(TESTBINS))
TESTSQLS = $(patsubst %,sql/%.sql, $(TESTNAMES))

# Set by autoconf
LDFLAGS = -Wl,-z,relro  -L/usr/lib -L/usr/lib
CFLAGS = -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables
PG_CONFIG = /usr/bin/pg_config

REGRESS = sampletables $(TESTNAMES)

all: $(TESTBINS) $(TESTSQLS)

installcheck: all

override CFLAGS += -Wno-pointer-sign

src/common.o: src/common.c

# For each test file, compile the .c file, and create a .sql file that
# when executed from psql, just runs the binary.
src/%-test sql/%.sql: src/%-test.c src/common.o
	$(CC) $(CFLAGS) $(LDFLAGS) src/$*-test.c src/common.o -o src/$*-test -lodbc
	echo "\! \"./src/$*-test\"" > sql/$*.sql

EXTRA_CLEAN = $(TESTBINS) $(TESTSQLS) src/common.o

REGRESS_OPTS = --launcher=./launcher

PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
