#! /bin/sh

do_cmd()
{
	echo "executing $@"
	"$@" || {
		echo "$1 failed" >&2
		exit 1
	}
}

case "$1" in
clean)
	clean_only=true;;
"")
	clean_only=false;;
*)
	echo "Usage: reconfig [ clean ]"
	exit 1
esac

cd "`dirname "$0"`"
echo "removing old files"
find . \( -name Makefile -o -name Makefile.in \) -exec rm -f {} \;
find . -depth -type d -name .deps -exec rm -rf {} \;
find . -type f -name core -exec rm {} \;
find . -type f -name "*~" -exec rm {} \;
rm -f configure config.status config.cache config.guess config.sub config.log config.h config.h.in
rm -f depcomp stamp-h stamp-h.in stamp-h1 missing aclocal.m4 install-sh mkinstalldirs
rm -rf autom4te.cache 
find . -type f -name "*.o" -exec rm {} \;
rm -f src/shell-fm
rm -f shell-fm-*.tar.gz shell-fm-*.tar.bz2

$clean_only && exit

do_cmd aclocal -I m4
do_cmd autoheader
do_cmd automake --add-missing --copy
do_cmd autoconf



# vim: noet ts=8 sw=8
