# Set up source trees.
# $Id: find-src,v 1.4 2003/01/20 22:03:19 mrustad Exp $

for pkg in "$@" ; do
    export GLOBIGNORE='*.tar.*'
    dir=`ls -1d ${pkg}-* 2>/dev/null | tail -1`
    unset GLOBIGNORE
    if [ ! -f "${dir}/Makefile.in" ]; then
	tar=`ls -1d ${tars}/${pkg}-*.tar.*z* 2>/dev/null | tail -1`
	case "${tar}" in
	*.tar.gz)
		echo "${0}: unpacking ${pkg} from tar file ${tar}."
		tar --gzip -xf ${tar}
		;;
	*.tar.bz2)
		echo "${0}: unpacking ${pkg} from tar file ${tar}."
		tar --use-compress-program=bzip2 -xf ${tar}
		;;
	*)
		echo "${0}: Unable to find a ${pkg} source tree or tar file."
		echo "You need to install a ${pkg} release in this directory."
		exit 1
		;;
	esac

	export GLOBIGNORE='*.tar.*'
	dir=`ls -1d ${pkg}-* | tail -1`
	unset GLOBIGNORE
	if [ -x patch-${pkg} ]; then
		echo "${0}: Patching ${pkg}."
		(cd ${dir}; tool_build=${tool_build} ../patch-${pkg} || \
			exit 1) || exit 1
		echo "${0}: ${pkg} patch complete."
	fi
	if [ -f "${pkg}-`uname`-custom" ]; then
		source "${pkg}-`uname`-custom"
	fi
    fi

    eval ${pkg}=${dir}
    echo "${0}: Using ${pkg} release ${dir}."
done
