#!/bin/sh

if [ "$MWHOME" = "" ] ; then
   echo "You must set the MWHOME enviroment variable to use the MainWin Runtime Environment"
   exit
fi

. "$MWHOME"/setup-mwuser

case ${MWARCH_OS} in
     sparc_sunos5)
			PATH=$PATH:/usr/openwin/bin
			LD_LIBRARY_PATH=`echo "${LD_LIBRARY_PATH:-}:/usr/openwin/lib" | sed 's/^::*//'`
            MWCONFIG_NAME=sunos5;;
     hp700_ux10)
			PATH=$PATH:/usr/contrib/bin/X11
            MWCONFIG_NAME=ux10;;
     hp700_ux11)
			PATH=$PATH:/usr/contrib/bin/X11
            MWCONFIG_NAME=ux11;;
     ia64_ux11)
		PATH=$PATH:/usr/contrib/bin/X11
		MWCONFIG_NAME=ia64_ux11;;
    #i86_sysvr4_2)
            #MWCONFIG_NAME=ux11;;
     alpha_osf1v4)
			PATH=$PATH:/usr/bin/X11
            MWCONFIG_NAME=osf1v4;;
     rs6000_aix4)
			PATH=$PATH:/usr/bin/X11
            MWCONFIG_NAME=aix4;;
     mips_irix6)
			PATH=$PATH:/usr/bin/X11
            MWCLIPBOARD_WITHOUT_TIMER=1
	        export MWCLIPBOARD_WITHOUT_TIMER
            MWCONFIG_NAME=irix6;;
	i86_linux)
		PATH=$PATH:/usr/bin/X11
		MWCONFIG_NAME=linux;;
     *) echo "`basename $0`: Unknown Architecture, cannot set environment"
       exit;;
esac

export X11_LIB_DIR
export OGL_LIB_DIR
export MWCONFIG_NAME
export MWCURRENT_LIBPATH
export MWCURRENT_PATH
export LD_LIBRARY_PATH
export SHLIB_PATH
export LIBPATH
export PATH

#
# architecture dependent inits (library dependencies)
#
# if you need to override the defaults provided here, do it
# in your .profile
#
case ${MWOS} in
linux)
	X11_LIB_DIR=/usr/X11R6/lib
	;;

sunos5)
	X11_LIB_DIR=${OPENWINHOME}/lib
	;;
ux11)
	X11_LIB_DIR=/usr/lib/X11R5
	mwsetonce OGL_LIB_DIR /opt/graphics/OpenGL/lib
	;;
aix4)
	X11_LIB_DIR=/usr/lib
	;;
	
esac

# setup MWREGISTRY to point to HKEY LOCAL MACHINE file
if [ "${MWREGISTRY:-not_set}" = "not_set" ]; then
 MWREGISTRY="${MWUSER_DIRECTORY}/hklm_${MWCONFIG_NAME}.bin"
 export MWREGISTRY
fi

new_path="${MWHOME}/bin-${MWCONFIG_NAME}_optimized"
if [ "${MWDEBUG:-}" != "" ]; then
   new_libpath="${MWHOME}/lib-${MWCONFIG_NAME}:${MWHOME}/lib-${MWCONFIG_NAME}_debug:${MWHOME}/lib-${MWCONFIG_NAME}_optimized"
else
   new_libpath="${MWHOME}/lib-${MWCONFIG_NAME}:${MWHOME}/lib-${MWCONFIG_NAME}_optimized"
fi

#Adding the support for stingray
if [ "${MWSTINGRAY_HOME:-}" != ""  ] ; then
   if [ -d "${MWSTINGRAY_HOME}" ] ; then
      new_path="${new_path}:${MWSTINGRAY_HOME}/bin-${MWCONFIG_NAME}_optimized"
      if [ "${MWDEBUG:-}" != "" ]; then
         new_libpath="${new_libpath}:${MWSTINGRAY_HOME}/lib-${MWCONFIG_NAME}_debug:${MWSTINGRAY_HOME}/lib-${MWCONFIG_NAME}_optimized"
      else
         new_libpath="${new_libpath}:${MWSTINGRAY_HOME}/lib-${MWCONFIG_NAME}_optimized"
      fi
   fi
fi

# Adding support for ODBC
if [ "${MWODBC_HOME:-}" != ""  ] ; then
   if [ -d "${MWODBC_HOME}"/. ] ; then
      new_libpath="${new_libpath}:${MWODBC_HOME}/${MWCONFIG_NAME}/lib"
   fi
fi

#Add the GCC libraries for Linux
if [ "${MWARCH_OS}" = "i86_linux" ] ; then
   gcclibdir="${MWHOME}"/../misc/linux/gcc/fixed3/lib
   if [ -d "${gcclibdir}"/. ] ; then
      new_libpath="${new_libpath}:${gcclibdir}"
   fi
   libgcc=libgcc_s.so.1
   if [ ! -r /lib/$libgcc -a ! -r /usr/lib/$libgcc -a -d ${gcclibdir}_rh7.3 ]; then
      new_libpath="${new_libpath}:${gcclibdir}_rh7.3"
   fi
   unset libgcc
   unset gcclibdir
fi

#
if [ "${MWCURRENT_LIBPATH:-notset}" = "notset" ] ; then
   LD_LIBRARY_PATH="${new_libpath}:${LD_LIBRARY_PATH:-}"
   SHLIB_PATH="${new_libpath}:${SHLIB_PATH:-}"
   LIBPATH="${new_libpath}:${LIBPATH:-}"
   # Tricky: PATH may already contain MainWin directories,
   # add the new ones after these.
   PATH=`echo :$PATH | sed "s,:${MWHOME},:@${MWHOME},g" | sed "s,:\([^@]\),:${new_path}:\1,"|sed -e 's,:@,:,g' -e 's,^:,,'`
#
else
#
   LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | sed -e 's@'"${MWCURRENT_LIBPATH}"@"$new_libpath"'@'`
   SHLIB_PATH=`echo $SHLIB_PATH | sed -e 's@'"${MWCURRENT_LIBPATH}"@"$new_libpath"'@'`
   LIBPATH=`echo $LIBPATH | sed -e 's@'"${MWCURRENT_LIBPATH}"@"$new_libpath"'@'`
   PATH=`echo $PATH | sed -e 's@'"${MWCURRENT_PATH}"@"$new_path"'@'`
fi
#
MWCURRENT_LIBPATH="${new_libpath}"
MWCURRENT_PATH="${new_path}"
unset new_libpath
unset new_path
MWRUNTIME=1
export MWRUNTIME

if [ "${MWOS}" = "aix4" -o "${MWOS}" = "linux" ]; then
    LIBPATH=`echo $LIBPATH |tr ":" "\012"|grep -v '^/usr/lib$'|tr "\012" ":"`
fi
if [  ${X11_LIB_DIR:-"not_set"} != "not_set" ]; then
    expand_lib_path $X11_LIB_DIR
fi

if [ -d ${OGL_LIB_DIR:="/dev/null"} ]; then
    expand_lib_path ${OGL_LIB_DIR}
fi
