#!/bin/sh

PACKAGE=subversion
VERSION=1.2.3
BASEDIR=/home/formtrap
SRCDIR=$BASEDIR/$PACKAGE-$VERSION
CONFIG_ARGS="--with-ssl \
  --with-egd \
  --with-zlib \
  --with-berkeley-db=/usr/local/BerkeleyDB.4.3 \
  --disable-mod-activation \
  --disable-nls \
  --without-apache \
  --without-apxs \
  --without-swig"

# use bash during configure phase
CONFIG_SHELL=/usr/local/bin/bash
export CONFIG_SHELL

# Add /usr/local/{lib,include} to relevant compiler paths
CFLAGS=-I/usr/local/include
LDFLAGS=-L/usr/local/lib
export CFLAGS LDFLAGS

# increase resource limits
for lim in c d f m n p s t u v ; do ulimit -$lim unlimited ; done

# clean out tmp
find /tmp/ -type f -name sh\* -exec rm -f {} \;

# check source is present
if [ ! -d "$SRCDIR" ] ; then
  echo "Source dir '$SRCDIR' not found"
  exit 1
fi

cd "$SRCDIR" || exit 1

# clean source dir
#if [ -f Makefile ] ; then
#  make distclean || exit 1
#fi
# really clean source dir
#find . -name config.cache -exec rm -f {} \;

# configure sources
echo "Running './configure' $CONFIG_ARGS"
CFLAGS=-I/usr/local/include \
LDFLAGS=-L/usr/local/lib \
./configure $CONFIG_ARGS || exit 1

# compile
echo "Running make"
make || exit 1
echo "$0 done."
