##########################################################################
# setup-mwuser
# -*- ksh -*-
# This file is to be "sourced" by sh/ksh users of Visual MainWin to set up 
# the necessary environment variables for Visual MainWin and for nmake 
# makefiles.
#
# setupmw-user is used internally by setupmainwin and setmwruntime. Do not
# use it directly.
###########################################################################

# define all the function to be used in the current shell before any other
# setting.
mwsetonce()
{
	eval $1=\"\${$1:-$2}\"
	export $1
}

expand_lib_path()
{
    eval $lib_path_name=\${$lib_path_name}:$1
	export $lib_path_name 
}

push_lib_path()
{
    eval $lib_path_name=$1:\${$lib_path_name}
	export $lib_path_name
}

mwprefix ()
{
  eval $1=\"${2}:\${$1}\"
}
 
mwpostfix ()
{
  eval $1=\"\${$1}:$2\"
}


if [ "${MWHOME}" != "${MWSETUP_GUARD:-not_set}" ]; then

#
# set the printarch variable if you want the message
#
if [ ! -z "${PRINTARCH:-}" ];then
    echo "Defining environment for Visual MainWin..."
fi

case `uname` in
SunOS) case `uname -r` in
	5*) MWOS=sunos5
	case `uname -m` in
		sun4*) MWARCH=sparc;;
		*)     echo "Machine under sunos must be sparc Solaris" 1>&2
		esac;;
	esac;;

HP-UX)	case `uname -r` in
		[AB].10*) MWOS=ux10
			case `uname -m` in 
			9000/[78]*) MWARCH=hp700;;
			*) echo "HP-UX machine must be 9000/700 series" 1>&2
			esac;;
                [AB].11*) MWOS=ux11
                        case `uname -m` in
                        9000/[78]*) MWARCH=hp700;;
                       	ia64) MWARCH=ia64;;
			*) echo "HP-UX machine must be 9000/700 series" 1>&2
                        esac;;
		*) echo "Unknown HP-UX version" 1>&2 
	esac;;

AIX)	case `uname -v` in
	4|5) MWOS=aix4
	   MWARCH=rs6000;;
	*) echo "Unknown version of AIX" 1>&2;;
	esac;;

IRIX*)
	# Silicon Graphics
	case `uname -r` in
	6.*)
	  MWOS=irix6
	  MWARCH=mips;;
	*) echo "Versions of IRIX other than 6.x are not supported";;
	esac;;
OSF1)
	case `uname -r` in
        V4.*|V5.*)
	  MWOS=osf1v4
	  MWARCH=alpha;;
	*) echo "Versions of Compaq Tru64 UNIX other than 4.x/5.x are not supported";;
	esac;;
	
Linux)
	MWOS=linux
	MWARCH=i86;;
*) echo "Unknown architecture and operating system." 1>&2

esac

MWARCH_OS="${MWARCH}_${MWOS}"

if [ ! -z "${PRINTARCH:-}" ];then
    echo "Architecture for Visual MainWin is ${MWARCH_OS}"
fi




export MWARCH_OS
export MWARCH
export MWOS
export lib_path_name


lib_path_name=LD_LIBRARY_PATH
#
# shared library path variables
#
case ${MWOS} in
sunos5)
	LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}
	OPENWINHOME=${OPENWINHOME:-/usr/openwin}
	export OPENWINHOME
	export LD_LIBRARY_PATH;;
linux)
	LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}
	export LD_LIBRARY_PATH;;
ux10 | ux11)
	lib_path_name=SHLIB_PATH
	SHLIB_PATH=${SHLIB_PATH:-}
	export SHLIB_PATH;;
aix4)
	lib_path_name=LIBPATH
	LIBPATH=${LIBPATH:-}
	export LIBPATH
	# For critical section (pthread_mutex) performance.
	SPINLOOPTIME=1000
	AIXTHREAD_MNRATIO=1:1
	export SPINLOOPTIME
	export AIXTHREAD_MNRATIO
	;;
esac

#
# Set path to include the MFW executables
#
PATH="${MWHOME}/bin":"$MWHOME/bin-${MWARCH_OS}":"${PATH}"
export PATH

if [ -d "${MWHOME}"/../stingray ] ; then
  MWSTINGRAY_HOME=`dirname "$MWHOME"`/stingray
  export MWSTINGRAY_HOME
fi

#
# Set ODBC home path
#
if [ -d "${MWHOME}"/../odbc/. ] ; then
  MWODBC_HOME=`dirname "$MWHOME"`/odbc
  ODBCINI="$MWODBC_HOME/$MWOS/odbc.ini"
  export MWODBC_HOME ODBCINI
fi

fi

# setup HOME to point to the home directory if it is not already set.
if [ "${HOME:-not_set}" = "not_set" ]; then
 HOME="`gethome`"
 export HOME
fi

# setup user directory
if [ "${MWUSER_DIRECTORY:-not_set}" = "not_set" ]; then
 MWUSER_DIRECTORY="${HOME}/.mw"
 export MWUSER_DIRECTORY
fi

# when in clearcase, set up MWCHROOT accordingly.
if [ ${CLEARCASE_ROOT:-"not_set"} != "not_set" ]; then
 MWCHROOT=${CLEARCASE_ROOT}
 export MWCHROOT
fi

#
# Set WinHelp search path
#
WINHELPPATH="${WINHELPPATH:-.:${MWUSER_DIRECTORY}/helpfile:${MWHOME}/helpfile}"
export WINHELPPATH
