#!/bin/sh

# Copyright (c) 1996-2001 by Waterloo Maple Inc.
# All rights reserved. Unauthorized duplication prohibited.
# Permission is granted to modify this file to be appropriate
# for use at the installation for which Maple was purchased.

# This script is used to start both the TTY and X11/Motif versions
# of Maple 7.

# Set the MAPLE environment variable. This variable is needed both by this
# script (to find various files), and by the Maple kernel and interface.
# Change the following line appropriately for your site if you did not
# install Maple in the directory indicated.
MAPLE=/usr/local/maple
export MAPLE

# Start by determining the system we are running on.
MAPLE_SYS_BIN=`$MAPLE/bin/maple.system.type`


# For Solaris users, you may need to uncomment the following two lines.
# XKEYSYMDB=/usr/openwin/lib/XKeysymDB
# export XKEYSYMDB

# For HPUX users, you many need to uncomment the
# following two lines and set the path for XKeysymDB correctly.
# XKEYSYMDB=/usr/lib/X11/XKeysymDB
# export XKEYSYMDB


# Parse all command line parameters. Parameters are collected into kernel
# and Iris parameters. The special parameter -x is used to start the X
# Window (Motif) interface.
PARAM=
IPARAM=
XMAPLE=
INSTALL=
DISPLAYARG=""
while [ x$1 != x ]
do
    case $1 in
    -x)
	XMAPLE=1
	;;
    -single)
	IPARAM="-km s"
	;;
    -parallel)
	IPARAM="-km p"
	;;
    -d|-display)
	if [ $# > 1 ] 
	then
		DISPLAYARG="-d $2"
		shift
	else
		echo "$0: display name required"
	fi
	;;
    *)
	PARAM="$PARAM $1"
	;;
    esac
    shift
done

#Add standard maple preprocessor include directory to command line
INCLUDES="-I $MAPLE/lib/include"

# Special per-platform processing
#
# In order to link to MATLAB from within Maple you will need to uncomment
# the lines referring to the matlab location.  In each case, the MATLAB 
# variable should be the same as that used to install MATLAB.
#
# For all systems, correct the path on the next line and uncomment
# the following two lines.
# MATLAB=/usr/local/matlab
# export MATLAB
#
case $MAPLE_SYS_BIN in
    "bin.HP_RISC_UNIX")
# For HP700 systems
SHLIB_PATH=$MAPLE/$MAPLE_SYS_BIN:$SHLIB_PATH
# SHLIB_PATH=$MATLAB/extern/lib/hp700:$SHLIB_PATH
export SHLIB_PATH
	;;
    "bin.IBM_RISC_UNIX")
# For RS/6000 systems
LIBPATH=$MAPLE/$MAPLE_SYS_BIN:$LIBPATH
# LIBPATH=$MATLAB/extern/lib/ibm_rs:$LIBPATH
export LIBPATH
	;;
    "bin.SUN_SPARC_SOLARIS")
# For Sun Sparc Solaris systems
LD_LIBRARY_PATH=$MAPLE/$MAPLE_SYS_BIN:$LD_LIBRARY_PATH
# LD_LIBRARY_PATH=$MATLAB/extern/lib/sol2:$LD_LIBRARY_PATH
# PATH=$MATLAB/bin:$PATH
export LD_LIBRARY_PATH
	;;
    "bin.DEC_ALPHA_UNIX")
# For Dec Alpha Unix systems
LD_LIBRARY_PATH=$MAPLE/$MAPLE_SYS_BIN:$LD_LIBRARY_PATH
# LD_LIBRARY_PATH=$MATLAB/extern/lib/alpha:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
	;;
    "bin.SGI_MIPS_UNIX")
# For SGI Unix systems
LD_LIBRARY_PATH=$MAPLE/$MAPLE_SYS_BIN:$LD_LIBRARY_PATH
# LD_LIBRARY_PATH=$MATLAB/extern/lib/sgi:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
	;;
    "bin.IBM_INTEL_LINUX")
# NOTE: Under LINUX, the Matlab link is only known to function for version 5.2
# of Matlab or later.  The Matlab link may function with earlier versions of 
# Matlab 5 on some builds of LINUX.
# For Intel Linux systems
LD_LIBRARY_PATH=$MAPLE/$MAPLE_SYS_BIN:$LD_LIBRARY_PATH
# LD_LIBRARY_PATH=$MATLAB/extern/lib/lnx86:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
	;;
    *)
	;;
esac

# This variable tells Maple's Motif interface where to find its resource
# file. This should be set even if TTY Maple is being run, as the user
# might still open a Motif plot window.
XUSERFILESEARCHPATH=$MAPLE/X11_defaults/Maple7
export XUSERFILESEARCHPATH

# Set the PATH so that Maple can find its various auxiliary programs.
PATH=$MAPLE/$MAPLE_SYS_BIN:$PATH
export PATH

# Start the Motif version of Maple if -x was specified; otherwise,
# start the TTY version. X11/Motif parameters are not allowed if the
# TTY version is started.
if [ "$XMAPLE" ]
then
    exec ${MAPLE}/$MAPLE_SYS_BIN/maplew $IPARAM $DISPLAYARG $PARAM
else
    if [ "$IPARAM" ]
    then
	echo "$0: invalid parameters: $IPARAM"
    else
	exec ${MAPLE}/$MAPLE_SYS_BIN/cmaple $INCLUDES $PARAM
    fi
fi
