set -e
set -v
-export AUTOMAKE='automake --foreign'
-aclocal
-libtoolize
-autoreconf -i
-pushd daemon
+
+mkdir -p daemon/m4
autoreconf -i
-popd
-./configure "$@"
+
+CONFIGUREDIR=.
+
+# Run configure in BUILDDIR if it's set
+if [ ! -z "$BUILDDIR" ]; then
+ mkdir -p $BUILDDIR
+ cd $BUILDDIR
+
+ CONFIGUREDIR=..
+fi
+
+# If no arguments were specified and configure has run before, use the previous
+# arguments
+if [ $# == 0 -a -x ./config.status ]; then
+ ./config.status --recheck
+else
+ $CONFIGUREDIR/configure "$@"
+fi