#!/bin/sh -x

export WORKSPACE=`pwd`

# Add PostgreSQL libraries to path
POSTGRESQL_HOME=${HOME}/opt/pgsql/8.2
export LD_LIBRARY_PATH=${POSTGRESQL_HOME}/lib
export PATH=/usr/local/bin:/bin:/usr/bin:${POSTGRESQL_HOME}/bin
export PGPORT=8213

# Add GEOS support
GEOS_HOME=${HOME}/opt/geos/3.1.0
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${GEOS_HOME}/lib

# Add Proj support
PROJ_HOME=${HOME}/opt/proj/4.6.1
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PROJ_HOME}/lib


# Checkout source code
svn -q co http://svn.osgeo.org/postgis/branches/1.4 src


# Build project
cd src
./autogen.sh
./configure \
   --prefix=${WORKSPACE}/build/ \
   --with-pgconfig=${POSTGRESQL_HOME}/bin/pg_config \
   --with-geosconfig=${GEOS_HOME}/bin/geos-config \
   --with-projdir=${PROJ_HOME}
make
make install
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${WORKSPACE}/build/lib


# Regression Test
cd regress
make 


# Cleanup
cd ${WORKSPACE}/src
make uninstall


