TMPDIR?=/tmp

POSTGIS_PGSQL_VERSION=@POSTGIS_PGSQL_VERSION@
POSTGIS_GEOS_VERSION=@POSTGIS_GEOS_VERSION@
POSTGIS_PROJ_VERSION=@POSTGIS_PROJ_VERSION@
HAVE_LIBXML2=@HAVE_LIBXML2@
MINGWBUILD=@MINGWBUILD@

# MingW hack: rather than use PGSQL_BINDIR directly, we change
# to the directory and then use "pwd" to return the path. This
# ensures that the returned path is in MSYS format, otherwise
# colons in drive letters will break PATH.
PGSQL_BINDIR=$(shell pushd "@PGSQL_BINDIR@" > /dev/null && pwd && popd > /dev/null)

# Where we put our regression installation 
ifeq ($(MINGWBUILD),1)
	srcdir=$(shell bash -c "pwd -W")
else
	srcdir=$(shell pwd)
endif
REGRESS_INSTALLDIR=$(srcdir)/00-regress-install

# 
# Put path from pg_config into front of search path
#
PATH := $(PGSQL_BINDIR):$(PATH)
export PATH


TESTS = \
	loader/Point \
	loader/PointM \
	loader/PointZ \
	loader/MultiPoint \
	loader/MultiPointM \
	loader/MultiPointZ \
	loader/Arc \
	loader/ArcM \
	loader/ArcZ \
	loader/Polygon \
	loader/PolygonM \
	loader/PolygonZ \
	regress \
	regress_index \
	regress_management \
	regress_index_nulls \
	lwgeom_regress \
	regress_lrs \
	removepoint \
	setpoint \
	simplify \
	snaptogrid \
	summary \
	affine \
	wkt \
	measures \
	long_xact \
	ctors \
	sql-mm-serialize \
	sql-mm-circularstring \
	sql-mm-compoundcurve \
	sql-mm-curvepoly \
	sql-mm-general \
	sql-mm-multicurve \
	sql-mm-multisurface \
	geojson \
	gml \
	svg \
	kml \
	in_gml \
	in_kml \
	polygonize \
	regress_ogc \
	regress_ogc_cover \
	regress_ogc_prep \
	regress_bdpoly \
	regress_proj \
	dumppoints \
	wmsservers \
	tickets

# Styled buffer only if GEOS >= 3.2
ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 32),1)
	TESTS += regress_buffer_params
endif

# Hausdorff only if GEOS >= 3.2
ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 32),1)
	TESTS += hausdorff
endif


all: test 

test check:
	$(MAKE) -C ../postgis REGRESS=1 DESTDIR=$(REGRESS_INSTALLDIR) install
	$(MAKE) -C ../loader REGRESS=1 DESTDIR=$(REGRESS_INSTALLDIR) install
	sed 's,$$libdir,$(REGRESS_INSTALLDIR)/lib,g' ../postgis/postgis.sql > postgis.sql
	@USE_VERSION=$(POSTGIS_PGSQL_VERSION) ./run_test $(TESTS)

cleanup:
	@sleep 1
	@dropdb postgis_reg > /dev/null

clean:
	rm -rf $(REGRESS_INSTALLDIR)
	rm -f postgis.sql 
