##########################################################################
# setup-mwuser
# -*- ksh -*-
# This file is to be "sourced" by sh/ksh users of MFW to set up 
# the necessary environment variables for MFW and for makefiles
# that rely on make.rules.simple(like those generated by genmake/genmakeC)
#
# Adding the following lines to your .kshrc/.profile is recommended
#	export MWHOME=<Directory where MFW is installed>
#	. ${MWHOME}/setupmw-user
#
###########################################################################


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

if [ -x "/usr/ucb/printenv" ]; then
	PRINTENV=/usr/ucb/printenv
else
	PRINTENV=printenv
fi

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

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

UNIX_SV) case `uname -r` in 
	4.2) MWOS=sysvr4_2
		case `uname -m` in
		i*86) MWARCH=i86;;
#add other SysV machines here
		*) echo "Unknown SYS_V machine" 1>&2
		esac;;
	4.2MP) MWOS=sysvr4_2
		case `uname -m` in
		R3000) MWARCH=mips;;
		*) echo "Unknown SYS_V machine" 1>&2
		esac;;
	*) echo "Versions of SYS_V other than 4.2 are not supported" 1>&2
	esac;;

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

UNIX_System_V) case `uname -r` in
	4.2) MWOS=sysvr4_2
		case `uname -m` in
		R3000) MWARCH=mips;;
		*) echo "Unknown UNIX_System_V machine" 1>&2
		esac;;
	*) echo "Versions of Unix System V other than 4.2 are not supported" 1>&2
	esac;;

IRIX*)
	# Silicon Graphics
	case `uname -r` in
	5.2)
	MWOS=irix5
	MWARCH=mips;;
	5.3)
	MWOS=irix53
	MWARCH=mips;;
	6.*)
	MWOS=irix6
	MWARCH=mips;;
	*) echo "Versions of Irix other than 5.2, 5.3, or 6.x are not supported";;
	esac;;
OSF1)
	case `uname -r` in
        V3.*)
	MWOS=osf1v2
	MWARCH=alpha;;
        V4.*)
	MWOS=osf1v4
	MWARCH=alpha;;
	*) echo "Versions of OSF/1 other than 3.x / 4.x are not supported";;
	esac;;
	
NEWS-OS)
	case `uname -r` in
	6.1)
	MWARCH=mips
	MWOS=news6;;
	*) echo "Versions of NEWS-OS other than 6.1 not supported";;
	esac;;

*)	
	# The  Motorola 88000 returns the name of the machine for uname
	# without any options same for SCO and some sysV.3 (seems to be a
	# bug in V.3) !
	case `uname -m` in
	m88k)
	    MWOS=sysv4
	    MWARCH=m88k;;
	#
	# this is for SCO3.2 and SCO5
	#
	i386)
	    MWARCH=i86
	    case `uname -s` in
		SCO_SV)
		    MWOS=sco5;;
		*)
	    	    MWOS=sco3;;
	    esac;;
	*) echo "Unknown architecture and operating system." 1>&2
	esac;;
esac

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

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

export MWARCH_OS
export MWARCH
export MWOS
export lib_path_name

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

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

lib_path_name=LD_LIBRARY_PATH
#
# shared library path variables
#
case ${MWOS} in
irix5 | irix53 | irix6 | osf1v2 | osf1v4) 
	LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-.}
	export LD_LIBRARY_PATH;;
sunos4)
	LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-.}:${OPENWINHOME:=/usr/openwin}/lib
	export OPENWINHOME
	export LD_LIBRARY_PATH;;
sunos5)
	LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-.}:${OPENWINHOME:=/usr/openwin}/lib:/usr/ucblib
	export OPENWINHOME
	export LD_LIBRARY_PATH;;
ux8 | ux9 | ux10 | ux11)
	lib_path_name=SHLIB_PATH
	SHLIB_PATH=.:${SHLIB_PATH:-.}
	export SHLIB_PATH;;
aix3 | aix4)
	lib_path_name=LIBPATH
	LIBPATH=.:${LIBPATH:-.}
	export LIBPATH;;
sco5 | news6)
	LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-.}
	export LD_LIBRARY_PATH;;
esac

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

#
# Set Font cache directory
#
MWFONT_CACHE_DIR=${MWFONT_CACHE_DIR:-${HOME}/windows}
export MWFONT_CACHE_DIR

#
# Allow MainWin library to use X scalable fonts (slower to render than
# bitmap fonts)
#
${MWSCALABLE_FONTS:=true}
export MWSCALABLE_FONTS

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

if [ ${MWRPC_ENDPOINT:-"not_set"}="not_set" ];then
  a=`id|sed ''s/uid=//\;s/\(.\*\$//''`
  MWRPC_ENDPOINT=`expr 10000 + $a % 65000`
  if [ $MWRPC_ENDPOINT -lt 10000 ];then
    MWRPC_ENDPOINT=`expr 10000 + ${MWRPC_ENDPOINT}`
  fi
  export MWRPC_ENDPOINT
fi
