#!/bin/sh

set -e

if TEMPDIR="`cat test-temp-dir 2>/dev/null`" \
		&& [ -f "$TEMPDIR/build/Makefile" ]; then
	(cd "$TEMPDIR/build" && make all install)
	exit
fi

TEMPDIR="`mktemp -d /tmp/mmh-test-XXXXXXXX`"
echo "$TEMPDIR" >test-temp-dir

cd ..
srcdir="$PWD"
if [ ! -f configure ]; then
	./autogen.sh
fi
if [ -f Makefile ]; then
	make -s clean
fi

mkdir "$TEMPDIR/build"
cd "$TEMPDIR/build"
"$srcdir/configure" -q --prefix="$TEMPDIR" --enable-debug
make -s all install
