#!/bin/sh
this_dir=/home/amundson/work/srt/SoftRelTools  #THIS LINE CREATED BY ./install/runme.sh
#^^^^^^^^^^^^^^ above line must be on line 2 of this file
# software release tools definitions
# D. Wright, July 1995
# J. Amundson 9/98: addition
#   of removal of old directories from path before addition of new ones
# J. Amundson 9/98 TODO: make SRTstartup.sh consistent with SRTstartup.csh
# J. Amundson 11/98: also modify LD_LIBRARY_PATH

if [ -n "$BFARCH" ] && [ -n "$BFCURRENT" ] && [ -n "$BFDIST" ]; then
    old_vars=1
else
    old_vars=0
fi
if [ "$old_vars" = "1" ]; then
    old_arch=$BFARCH
    old_current=$BFCURRENT
    old_dist=$BFDIST
fi    

export BFDIST BFARCH BFCURRENT

if [ -z "$BFCURRENT" ]
then
    if [ -r $HOME/BFCURRENT ]
    then
        BFCURRENT=`cat $HOME/BFCURRENT`
    else
        BFCURRENT=current
    fi
fi
BFARCH=NONE

uname=`uname`
BFARCH=$uname`uname -r | cut -c1`
[ $uname = "AIX" ] && BFARCH=$uname`uname -v | cut -c1`
[ $uname = "HP-UX" ] && [ `uname -r | cut -c3` = 0 ] &&
    BFARCH=`uname``uname -r | cut -c4`
[ $uname = "HP-UX" ] && [ `uname -r | cut -c3` != 0 ] &&
    BFARCH=$uname`uname -r | cut -c3-4`
[ $uname = "OSF1" ] && BFARCH=$uname`uname -r | cut -c1-2`
[ $uname = "IRIX" -o $uname = "IRIX64" ] && BFARCH=IRIX`uname -r| cut -c1`
if [ -f $HOME/.SRTcompiler ]
then
#   Source the sh version of setcompiler when it's written...
#    . $BFDIST/releases/$BFCURRENT/SoftRelTools/setcompiler.sh
#   Meanwhile, just set BFARCH, and let user worry about path & debugger
    BFARCH=${BFARCH}-`cat $HOME/.SRTcompiler | cut -d'-' -f2`
fi

if [ -f $this_dir/config/SRTsite.sh ]; then
. $this_dir/config/SRTsite.sh;
else
#if it dosnt exist just set it to be backward compatible
 BFDIST=$BFROOT/dist;
fi

if [ -n "$SRT_HOME" ]; then
    if [ `echo $PATH | grep -c "SoftRelTools"` != 0 ]; then
	# remove possible old SRT_HOME from beginning of path 
	new_path=`echo $PATH | sed "s/^[^:]*SoftRelTools://"`
	# remove possible old SRT_HOME from middle of path 
	new_path=`echo $new_path | sed "s/:[^:]*SoftRelTools:/:/"`
	# remove possible old SRT_HOME from end of path 
	new_path=`echo $new_path | sed 's/:[^:]*SoftRelTools$//'`
	export PATH ; PATH="$new_path"
    fi
    export PATH; PATH="$SRT_HOME:$PATH"
fi

# if old path contains old settings, remove them
# n.b. If you change old_paths, you must also change new_paths or 
#      the removal of old paths will break.
new_paths="./bin/$BFARCH:$BFDIST/releases/$BFCURRENT/bin/$BFARCH"
if [ "$old_vars" = "1" ]; then
    old_paths="./bin/$old_arch:$old_dist/releases/$old_current/bin/$old_arch"
    new_path=`echo $PATH | sed "s~$old_paths:~~"`
    export PATH ; PATH="$new_path"
fi

# original setup
PATH="$new_paths:$PATH"

new_sharedlib_paths="./lib/$BFARCH:$BFDIST/releases/$BFCURRENT/lib/$BFARCH"
if [ "$old_vars" = "1" ]; then
    old_sharedlib_paths="./lib/$old_arch:$old_dist/releases/$old_current/lib/$old_arch"
    new_sharedlib_path=`echo $LD_LIBRARY_PATH | sed "s~$old_sharedlib_paths:~~"`
    export LD_LIBRARY_PATH; LD_LIBRARY_PATH="$new_sharedlib_path"
fi

# original setup
LD_LIBRARY_PATH="$new_sharedlib_paths:$LD_LIBRARY_PATH"

export MANPATH; MANPATH="`pwd`/man:$BFDIST/releases/$BFCURRENT/man:$MANPATH"

# The following alias should be called in the top directory of a distribution.

srt_top() {
    export SRT_TOP ; SRT_TOP=`pwd`
}

# The following alias allows users to do make in subdirectories.

lgmake() {
    gmake --no-print-directory -C $SRT_TOP SRT_CURDIR=`pwd` make_flags | xargs gmake
}    


