#!/bin/bash -e

# If you want to track the status of the project in Subversion, run this script
# instead of relying on "svn update". The script makes sure you end up with a
# working copy of the source tree that is customized to the version of GNU
# "autotools" that are installed on your machine.
#
# Alternatively, you can always remove the entire tree and check out a fresh
# copy from Subversion.

[ -x "$(type -path svn)" ] || {
  echo "You must have the 'svn' binary to use this script." >&2
  exit 1
}
[ -x "$(type -path libtoolize)" ] || {
  echo "You must install 'libtool', if you want to track SVN." >&2
  echo "Alternatively, delete all files and check out a clean copy"           \
       "from SVN." >&2
  exit 1
}
[ -x "$(type -path autoreconf)" -a -x "$(type -path aclocal)" ] || {
  echo "You must install the GNU 'autotools', if you want to track SVN." >&2
  echo "Alternatively, delete all files and check out a clean copy"           \
       "from SVN" >&2
  exit 1
}

rm -rf aclocal.m4 configure config.guess config.h config.h.in config.sub      \
       ltmain.sh m4 Makefile.in

svn update
[ -z "$(svn st|grep '^C')" ] || {
  echo "Some files could not be synchronized with the SVN repository." >&2
  echo "You have to manually resolve the merge conflicts and rerun this "     \
       "script" >&2
  exit 1
}

aclocal
libtoolize --force --copy
autoreconf
./configure