TMPDIR?=/tmp

POSTGIS_PGSQL_VERSION=842
POSTGIS_GEOS_VERSION=31
POSTGIS_PROJ_VERSION=46
PGSQL_BINDIR=$(shell pushd "c:/POSTGR~3/bin" && pwd && popd)

srcdir=$(shell pwd)

# 
# 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_index_nulls \
	lwgeom_regress \
	regress_lrs \
	removepoint \
	setpoint \
	simplify \
	snaptogrid \
	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 \
	regress_ogc \
	regress_bdpoly \
	regress_proj

# Covers/CoveredBy only if GEOS >= 3.0
ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 30),1)
	TESTS += regress_ogc_cover 
endif

# PreparedGeometry only if GEOS >= 3.1
ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 31),1)
	TESTS += regress_ogc_prep
endif

# 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: ../postgis/postgis.sql ../loader/pgsql2shp ../loader/shp2pgsql 
	sed 's,$$libdir/postgis,$(srcdir)/../postgis/libpostgis,g' ../postgis/postgis.sql > postgis.sql
	@USE_VERSION=$(POSTGIS_PGSQL_VERSION) ./run_test $(TESTS)


../postgis/postgis.sql:
	$(MAKE) -C ../postgis

../loader/pgsql2shp ../loader/shp2pgsql:
	$(MAKE) -C ../loader

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

clean:
	rm -f postgis.sql 
