#!/bin/sh

# bootstrap the build when checking out from CVS

# dodgy hack to use gmake if we're on bsd systems
if [ -x /usr/local/bin/gmake ]; then
	MAKE=/usr/local/bin/gmake
else
	MAKE=make
fi

if [ "$1" = "clean" ]; then
	# clean up junk
	
	if [ -f Makefile ]; then 
		$MAKE distclean
	fi
	find . -name Makefile.in -print0 | xargs -r0 rm -f
	rm -f aclocal.m4 install-sh missing mkinstalldirs \
	      stamp-* tags configure config.* \
		  compile depcomp ltmain.sh
	rm -rf autom4te.cache libltdl
	find . -name '*~' -print0 | xargs -r0 rm -f
	find . -name '*.rej' -print0 | xargs -r0 rm -f
	find . -name '*.orig' -print0 | xargs -r0 rm -f

else

    VERSION=`automake --version |head -1| sed 's/automake (GNU automake) //'`
    MAJOR=`echo $VERSION | cut -f1 -d.`
    MINOR=`echo $VERSION | cut -f2 -d.`
    if test "$MAJOR" -ge "1" -a "$MINOR" -ge "6"; then
	aclocal
	autoheader
	libtoolize --copy --ltdl --automake
	automake --foreign --add-missing --copy
	autoconf
    else
	echo "Need automake version 1.6 or higher"
    fi
fi
