#!/bin/sh
#
# Title:  gEDA Wrapper Script
# Author: Charles Dominguez (cfdoming)
# Description:
#     Configures and runs geda on Athena.
#
# Change Log:
#   2005-07-05  cfdoming  Initial version.


binary='gmk_sym'
versionDir=`athdir -p /mit/geda -t versions`
runver='current'
athlib='/usr/athena/lib'


# Check script parameters
case "$1" in
--runver)
	# User is specifying the version to run.
	case "$2" in
	*[!a-z0-9A-Z._-]*|.|..)
		;;
	*)
		runver="$2"
		;;
	esac
	shift
	shift
	;;
--listver)
	# User only wants a list of availible versions
	curr=`ls -l $versionDir | sed -n -e '/current -> / s/.* current -> //p'`
	echo "The current version of $binary for $ATHENA_SYS is:"
	echo "	${curr}"
	echo ''
	
	echo "The versions availible for $ATHENA_SYS are:"
	for dir in "$versionDir"/[!.]*; do
		ver=`echo $dir | sed  -e 's#.*/##' -e '/current/d' `
		[ ${ver} ] && echo "	${ver}"
	done
	exit 0
esac

# Check that binaries exist for the version specified
if [ ! -d "$versionDir/$runver" ]; then
	echo "$binary.sh: The specified version of $binary could not be found."
	echo "To see a list of the availible versions, run the command:"
	echo "$binary --listver"
	exit 2
fi

if [ -z "$LD_LIBRARY_PATH" ]; then
	LD_LIBRARY_PATH=$athlib:$versionDir/$runver/lib
	export LD_LIBRARY_PATH
else
	LD_LIBRARY_PATH=$athlib:$versionDir/$runver/lib:$LD_LIBRARY_PATH
	export LD_LIBRARY_PATH
fi


PATH=$versionDir/$runver/bin:$PATH
export PATH

exec $versionDir/$runver/bin/$binary "$@"



