# This is a bash snippet that will set up some variables that should be
# set when Eccet will be run.

#
# Strip existing references to /cv from PATH.
#
PATH=$(echo ":$PATH" | sed -e "s#:/cv/[a-z0-9./-]*bin##g" -e "s/^://")

#
# Probe what CPU we have.
#

grep -q "sse2" /proc/cpuinfo && HAVE_SSE=1
grep -q "3dnow" /proc/cpuinfo && HAVE_3DNOW=1

#
# Probe if Libc 2.3 is available. Note that the optimized versions all
# require Libc 2.3, as gcc 3.3 requires it.
#

ls -l /lib/libc-2.3* 2>/dev/null >/dev/null && HAVE_LIBC23=1

BASEPATH=

#
# Dummy loop - just used to break out when we have a result.
#
while true; do

	#
	# If we have 3DNOW, this is a Athlon machine
	#
	if [ "$HAVE_3DNOW" == "1" -a "$HAVE_LIBC23" == "1" ] ; then
		if [ -f /cv/athlon/bin/voxren ] ; then
			BASEPATH=/cv/athlon
			break
		elif [ -f /cvlocal/athlon/bin/voxren ] ; then
			BASEPATH=/cvlocal/athlon
			break
		fi
	fi

	#
	# If we have SSE2, this is a Xeon/Pentium4 Class machine
	#
	if [ "$HAVE_SSE" == "1" -a "$HAVE_LIBC23" == "1" ] ; then
		if [ -f /cv/xeon/bin/voxren ] ; then
			BASEPATH=/cv/xeon
			break
		elif [ -f /cvlocal/xeon/bin/voxren ] ; then
			BASEPATH=/cvlocal/xeon
			break
		fi
	fi

	#
	# If we at least have libc 2.3, use that.
	#
	if [ "$HAVE_LIBC23" == "1" ] ; then
		if [ -f /cv/libc23/bin/voxren ] ; then
			BASEPATH=/cv/libc23
			break
		elif [ -f /cvlocal/libc23/bin/voxren ] ; then
			BASEPATH=/cvlocal/libc23
			break
		fi
	fi

	#
	# Nothing available. Try the "noopt" version.
	#
	if [ -f /cv/noopt/bin/voxren ] ; then
		BASEPATH=/cv/noopt
		break
	elif [ -f /cvlocal/noopt/bin/voxren ] ; then
		BASEPATH=/cvlocal/noopt
		break
	fi

	#
	# Bail out
	#
	break
done

if [ "$BASEPATH" != "" ] ; then
	PATH="$BASEPATH/bin:$PATH"
fi

#
# If we at least have something in /cv/bin, put that in the path as well.
#

if [ -f /cv/bin/voxren ] ; then
	PATH=$PATH:/cv/bin
elif [ -f /cvlocal/bin/voxren ] ; then
	PATH=$PATH:/cvlocal/bin
fi

#
# We are using LibGGI. LibGGI usually reduces the cursor to a small dot.
# However in ECCET this isn't a really useful feature, so we turn it off.
# Please note, that this interferes with Libggi auto target detection,
# So override if you use LibGGI for other purposes as well.
#
GGI_DISPLAY="X:-keepcursor"
export GGI_DISPLAY

#
# Set the man path to include eccet specific manpages.
#

if [ "$MANPATH" != "" ] ; then
	MANPATH="$MANPATH:$BASEPATH/share/man"
else
	MANPATH="/usr/share/man:/usr/X11R6/man:/usr/man:/usr/local/man:$BASEPATH/share/man"
	export MANPATH
fi
