#!/bin/bash -e

function autoStrap
{
	aclocal
	libtoolize --force
	autoheader
	automake --add-missing
	autoconf
}

function autoClean
{
# run distclean if available
	make distclean 2>/dev/null || true

# Delete these files if they are created automatically
	for f in NEWS README AUTHORS ChangeLog missing install-sh mkinstalldirs config.guess config.sub depcomp INSTALL COPYING ltmain.sh; do
		if [ ! -s "${f}" ] || [ -L "${f}" ]; then  # file does not exists or has size 0 or is a symlink
			rm -f -v ${f};
		fi;
	done
# Always delete these files
	rm -f -v *~ configure config.h.in config.h stamp-h.in stamp-h1 config.cache config.log config.status aclocal.m4 libtool
	rm -r -f -v autom4te.cache
}

if [ "${1}" == "clean" ]; then
	autoClean ;
elif [ "${1}" == "all" ]; then
	autoClean ;
	autoStrap ;
elif [ "${1}" == "" ]; then
	autoStrap ;
else
	echo "Usage: $0 [clean|all]: No arg=strap only, \"clean\"=clean only, \"all\"=clean+strap." >&2
	exit 1
fi
