#! /bin/sh
#
# BEGIN LICENSE BLOCK
# Version: CMPL 1.1
#
# The contents of this file are subject to the Cisco-style Mozilla Public
# License Version 1.1 (the "License"); you may not use this file except
# in compliance with the License.  You may obtain a copy of the License
# at www.eclipse-clp.org/license.
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
# the License for the specific language governing rights and limitations
# under the License. 
# 
# The Original Code is  The ECLiPSe Constraint Logic Programming System. 
# The Initial Developer of the Original Code is  Cisco Systems, Inc. 
# Portions created by the Initial Developer are
# Copyright (C) 1995-2006 Cisco Systems, Inc.  All Rights Reserved.
# 
# Contributor(s): IC-Parc, Imperial College London
# 
# END LICENSE BLOCK
#
# This is a shell script. Run it to install ECLiPSe.
#

usage="\
Usage: $0 [options]
Options:
	--link
		Link a new executable (don't ask)
	--no-link
		Don't link a new executable (don't ask)

	--docs
		Build the reference documentation (don't ask)
	--no-docs
		Don't build the reference documentation (don't ask)
"

link=no
docs=ask

while [ $# -gt 0 ]; do
	case "$1" in

	--link)
		link=yes ;;
	--no-link)
		link=no ;;

	--docs)
		docs=yes ;;
	--no-docs)
		docs=no ;;

	--)
		shift; break ;;
	-*)
		echo "$0: unrecognised option: \`$1'" 1>&2
		echo "$usage" 1>&2
		exit 1 ;;
	*)
		break ;;
	esac
	shift
done

if [ $# -ne 0 ]; then
	echo "$0: unexpected arguments: \`$*'" 1>&2
	echo "$usage" 1>&2
	exit 1
fi

if echo -n|grep n >/dev/null; then
    ECHO_NL=
else
    ECHO_NL="-n"
fi

# ask <prompt> <variable> [<possible_values>]
ask () {
    eval answer=\$$2
    accept=
    while test -z "$accept"; do
	echo
	echo "$1 [$answer]? "
	echo $ECHO_NL "Hit return to accept, or enter new value: "
	read new
	if test -z "$new"; then
	    accept=y
	else
	    if test $# = 3; then
		for val in $3; do
		    if test "$new" = "$val"; then
			answer="$new"
		        break 2
		    fi
		done
		if test "$new" != "$answer"; then
		    echo "ERROR: Legal values are:" $3
		fi
	    else
		answer="$new"
	    fi
	fi
    done
    eval $2=\"$answer\"
}


# test whether this configuration has a java interface

have_java_interface () {
    test -f $ECLIPSEDIR/lib/$ARCH/*ec_java.*
}


echo "----------------------------------------------------------------------"
echo Welcome to the ECLiPSe installation procedure
echo "----------------------------------------------------------------------"

ARCH_GUESS=`./ARCH`

if test -z "$ARCH"; then
    if echo $ARCH_GUESS|grep " " >/dev/null; then
	echo NOTE: This machine supports multiple architectures:
	for ARCH in $ARCH_GUESS; do
	    echo $ARCH
	done
	# ARCH now set to the last member of ARCH_GUESS
    else
	if test "$ARCH_GUESS" = unknown; then
	    echo WARNING: Unknown machine architecture
	fi
	ARCH=$ARCH_GUESS
    fi
else
    if test "$ARCH_GUESS" = unknown; then
	echo WARNING: Cannot determine machine architecture
	echo WARNING: Using the value of your ARCH environment variable as default
    else
	# If ARCH_GUESS contains multiple values, disambiguate using ARCH
	for guess in $ARCH_GUESS; do
	    if test $ARCH = $guess; then
		break
	    fi
	done
	if test $ARCH != $guess; then
	    # An end user's $ARCH may have an unrelated setting - ignore it
	    echo WARNING: Ignoring your ARCH environment variable
	    ARCH=$guess
	fi
    fi
fi

ask "Which machine achitecture (ARCH) are we installing for" ARCH

if test $ARCH = "i386_nt" ; then
    echo "Nothing to do for $ARCH"
    exit 0
fi

# directory defaults
ECLIPSEDIR=`pwd`
EXE_DIR="\$ECLIPSEDIR/bin/$ARCH"
TCL_DIR="${TCL_DIR:-\$ECLIPSEDIR/tcltk/$ARCH}"
TCL_ARCH_DIR="${TCL_ARCH_DIR:-\$ECLIPSEDIR/tcltk/$ARCH}"
TCL_VERSION="${TCL_VERSION:-8.4}"
WISH_DIRECTORY="$TCL_ARCH_DIR/bin"
TCL_ARCH_LIBRARY="$TCL_ARCH_DIR/lib"
TCL_LIBRARY="$TCL_DIR/lib/tcl$TCL_VERSION"
TK_LIBRARY="$TCL_DIR/lib/tk$TCL_VERSION"
DAVINCIHOME="${DAVINCIHOME:-\$ECLIPSEDIR/daVinci/$ARCH}"
USER_OBJECTS=""
TCL_FRAMEWORK="/System/Library/Frameworks"
case $ARCH in
    *_macosx)
# name of environment variable for specifying library paths
	LD_LIB_PATH_NAME=DYLD_LIBRARY_PATH
	FRAMEWORK_PATH_NAME=DYLD_FRAMEWORK_PATH
	XWISH_DIRECTORY="\$WISH_DIRECTORY"
	XWISH_EXEC="xwish$TCL_VERSION"
	;;
    *)
	LD_LIB_PATH_NAME=LD_LIBRARY_PATH
	FRAMEWORK_PATH_NAME=""
	;;
esac

# read the architecture's defaults
. "lib/$ARCH/INST_PARAMS"

# load the previous installation's settings
if test -f "lib/$ARCH/SITE_PARAMS"; then
    . "lib/$ARCH/SITE_PARAMS"
fi



echo "----------------------------------------------------------------------"
echo "You now need to specify the directory path name that eclipse"
echo "will use to find its libraries and other support files."
echo "This should be the FULL PATHNAME OF THE CURRENT DIRECTORY."
echo "If you have a networked file system, you may want to specify"
echo "a symbolic path under which this directory can be found on all"
echo "the networked machines."
ask "What is the current directory (ECLIPSEDIR)" ECLIPSEDIR

while test `cd "$ECLIPSEDIR";/bin/pwd` != `/bin/pwd`; do
    echo
    echo "This is not same as the current directory! Please try again:"
    ask "What is the current (=installation) directory" ECLIPSEDIR
done

LIB_ARCH_DIR="$ECLIPSEDIR/lib/$ARCH"


echo "----------------------------------------------------------------------"
echo "Please specify now where you want the ECLiPSe executables to be"
echo "installed. This can be within the ECLiPSe directory structure"
echo "or alternatively in a place where you usually put executables,"
echo "e.g. a directory that is already in your PATH."
ask "Where do you want to install executables" EXE_DIR

if test ! -d "$EXE_DIR"; then
    mkdir -p "$EXE_DIR"
    chmod 2755 "$EXE_DIR"
else
    if test ! -w "$EXE_DIR"; then
    	echo "You do not have write permission for that directory!"
    	exit 1
    fi
fi

# if default EXE_DIR is used, make sure parent permissions are ok
if test -d "$ECLIPSEDIR/bin"; then chmod 2755 "$ECLIPSEDIR/bin"; fi


echo "----------------------------------------------------------------------"
echo "Now some questions about your Tcl/Tk installation."
echo "If you have unpacked the tcltk-package that comes with the ECLiPSe"
echo "distribution, then just accept the defaults by hitting return."
echo "Also, if you don't want to use the tkeclipse graphical development"
echo "environment, just hit return."
echo "If you want to use your existing Tcl/Tk installation (e.g. on Linux)"
echo "please specify the corresponding information here:"

ask "What is the version number of your Tcl/Tk installation (8.X)" TCL_VERSION "8.3 8.4 8.5"
ask "In which directory is the wish$TCL_VERSION executable" WISH_DIRECTORY

case $ARCH in
    *_macosx)
	echo "On MacOSX, the native Aqua Tcl/Tk is packaged using Frameworks."
	ask "In which directory is the Tcl Framework (where Tcl.framework is)" TCL_FRAMEWORK
	echo "If you have an X11 version of Tcl/Tk $TCL_VERSION, you can also"
	echo "setup xtkeclipse (and xtktools) to run the X version of TkECLiPSe."
	ask "In which directory is the wish$TCL_VERSION executable for X11 (none if you don't have it)" XWISH_DIRECTORY

	if test $XWISH_DIRECTORY != "none"; then
	    ask "What is the name of the wish$TCL_VERSION executable for X11" XWISH_EXEC
	   ask "Where is the X11 Tcl/Tk objects library directory (.dylib files)" TCL_ARCH_LIBRARY
           TK_ARCH_LIBRARY="$TCL_ARCH_LIBRARY"
	fi
        ;;
   *)
        ask "Where is the Tcl/Tk objects library directory (.so/.a files)" TCL_ARCH_LIBRARY
        TK_ARCH_LIBRARY="$TCL_ARCH_LIBRARY"
        ;;

esac 
ask "Where is the Tcl library directory (.tcl files)" TCL_LIBRARY
ask "Where is the Tk library directory (.tcl files)" TK_LIBRARY

#echo "----------------------------------------------------------------------"
#echo "ECLiPSe can interface to the daVinci graph drawing package"
#echo "(see http://www.informatik.uni-bremen.de/agbkb/forschung/daVinci)."
#echo "If you have daVinci installed, or are going to install it later,"
#echo "please give the directory name here. If you do this, ECLiPSe/daVinci"
#echo "users will not need to set the DAVINCIHOME environment variable."
#ask "Where is the daVinci home directory" DAVINCIHOME

echo "----------------------------------------------------------------------"
if have_java_interface; then
    echo "ECLiPSe can interface to Java (version 1.2 or later).  If you wish"
    echo "to make use of this interface, please specify the location of your"
    echo "Java Runtime Environment (JRE_HOME)."
    ask "Where is your Java Runtime Environment installed" JRE_HOME
else
    echo "Java interface not supported in this configuration, skipping."
fi

echo "----------------------------------------------------------------------"
if [ -d "$ECLIPSEDIR/doc/bips/kernel" ] ; then
    case "$docs" in
	yes)
		echo "You have requested generation of the reference documentation."
		BUILD_DOCS=y ;;

	no)
		echo "You have requested no generation of the reference documentation."
		BUILD_DOCS=n ;;

	*)
		if [ -f "$ECLIPSEDIR/doc/bips/index.html" ] ; then
			echo "You appear to already have the ECLiPSe reference documentation."
			ask "Do you wish to regenerate it" REBUILD_DOCS "y n"
			BUILD_DOCS=$REBUILD_DOCS
		else
			echo "You do not appear to have the ECLiPSe reference documentation."
			echo "It will be generated for you."
			BUILD_DOCS=y
		fi
		;;
    esac
else
    echo "You didn't unpack the ECLiPSe reference documentation."
    BUILD_DOCS=n
fi


case "$link" in
	yes)
		echo "----------------------------------------------------------------------"
		echo "You have requested a customised configuration of eclipse."
		SIMPLE=n ;;

	no)
		echo "----------------------------------------------------------------------"
		echo "You have requested the default configuration of eclipse."
		SIMPLE=y ;;

	*)
		echo "----------------------------------------------------------------------"
		echo "Now you have the choice between installing"
		echo ""
		echo "[y] The default configuration of eclipse:"
		echo "      This is recommended. It requires no special tools."
		echo ""
		echo "[n] A customised configuration of eclipse:"
		echo "      This allows you to statically link your own object files"
		echo "      with ECLiPSe.  A linker or C compiler is required."

		ask "Do you want to install the default configuration" SIMPLE "y n"
		;;
esac

echo "----------------------------------------------------------------------"

if test $SIMPLE != y; then
#--------------------------------------------------------------
# Customised configuration
#--------------------------------------------------------------

#ask "Do you want support for parallelism" WANT_PARALLELISM "y n"
#
#if test $WANT_PARALLELISM = y; then
#    ask "Do you want the Tcl/Tk worker manager interface" WANT_TCL_WM "y n"
#    # we need mps for parallelism
#    WANT_MPS=y
#else
#    ask "Do you want support for message passing" WANT_MPS "y n"
#fi

ask "Extra object files you want linked with your ECLiPSe" USER_OBJECTS

ask "The compiler/linker to be used for linking" CC
ask "Extra linker options that might be required" LDFLAGS
ask "Extra system libraries that might be required" SYSLIBS

ask "Where is the X11 library directory" X_LIBRARIES
SYSLIBSX="-L\"$TCL_ARCH_LIBRARY\" -ltcl -L\"$TK_ARCH_LIBRARY\" -ltk -L\"$X_LIBRARIES\" -lX11 $SYSLIBS"

echo "----------------------------------------------------------------------"


#--------------------------------------------------------------
# Make a properly configured eclipse executable
#--------------------------------------------------------------

cd "$LIB_ARCH_DIR"

OBJECTS="standalone.o"
if test "$OBJECTS_SUFFIX" = "so"; then
    LIBRARIES="libeclipse.so libgmp.so"
else
    LIBRARIES="libeclipse.a libdummies.a libgmp.a libshm.a"
fi

if test "$WANT_PARALLELISM" = "y"; then
    echo Installing with parallel option
    OBJECTS="$OBJECTS parallel.o"
fi

if test "$WANT_MPS" = "y"; then
    echo Installing with mps option
    LIBRARIES="libeclipsemps.a libpds.a $LIBRARIES"
fi


`if [ -r /bin/ranlib -o -r /usr/bin/ranlib ]; then echo ranlib; else echo true; fi` *.a

echo Making executable "$LIB_ARCH_DIR/eclipse.exe"
$CC $LDFLAGS $OBJECTS $USER_OBJECTS $LIBRARIES $SYSLIBS -o "$LIB_ARCH_DIR/eclipse.exe"
chmod 755 "$LIB_ARCH_DIR/eclipse.exe"

#--------------------------------------------------------------
# Make optional executables
#--------------------------------------------------------------

if test "$WANT_MEGALOG" = "y"; then
    echo Making "$EXE_DIR/bang_server"
    $CC $LDFLAGS bang_server.o $LIBRARIES $SYSLIBS -o "$EXE_DIR/bang_server"
    chmod 755 "$EXE_DIR/bang_server"
fi

if test "$WANT_MPS" = "y"; then
    echo Making "$EXE_DIR/nsrv"
    $CC $LDFLAGS nsrv_server.o $LIBRARIES $SYSLIBS -o "$EXE_DIR/nsrv"
    chmod 755 "$EXE_DIR/nsrv"
fi

if test "$WANT_PARALLELISM" = "y"; then
    rm -f "$EXE_DIR/worker"
    ln -s eclipse "$EXE_DIR/worker"

    echo Making "$LIB_ARCH_DIR/peclipse.exe"
    if test "$WANT_TCL_WM"; then
	$CC $LDFLAGS wm.o wm_interface.o $LIBRARIES $SYSLIBSX -o "$LIB_ARCH_DIR/peclipse.exe"
    else
	$CC $LDFLAGS wm.o $LIBRARIES $SYSLIBS -o "$LIB_ARCH_DIR/peclipse.exe"
    fi
    chmod 755 "$LIB_ARCH_DIR/peclipse.exe"

    echo Making "$EXE_DIR/peclipse"
    rm -f "$EXE_DIR/peclipse"
    cat > "$EXE_DIR/peclipse" <<EOF
#! /bin/sh
ECLIPSEDIR="\${ECLIPSEDIR:-$ECLIPSEDIR}"
TCL_LIBRARY="\${TCL_LIBRARY:-$TCL_LIBRARY}"
TK_LIBRARY="\${TK_LIBRARY:-$TK_LIBRARY}"
export ECLIPSEDIR TCL_LIBRARY TK_LIBRARY
exec "$LIB_ARCH_DIR/peclipse.exe" "\$@"
EOF
    chmod 755 "$EXE_DIR/peclipse"

fi

fi

#--------------------------------------------------------------
# End of customised configuration
#--------------------------------------------------------------



#--------------------------------------------------------------
# Default configuration, just make the eclipse wrapper script
#--------------------------------------------------------------

dest="$EXE_DIR/eclipse"
echo Making "$dest"
rm -f "$dest"
cat > "$dest" <<EOF
#! /bin/sh
ECLIPSEDIR="\${ECLIPSEDIR:-$ECLIPSEDIR}"
$LD_LIB_PATH_NAME="\$ECLIPSEDIR/lib/$ARCH:$TCL_ARCH_LIBRARY:\$$LD_LIB_PATH_NAME"
EOF
case $ARCH in 
    *_macosx)
	cat >> "$dest" <<EOF
DYLD_FRAMEWORK_PATH="\$TCL_FRAMEWORK:\$DYLD_FRAMWORK_PATH"
EOF
	;;
esac
cat >> "$dest" <<EOF
TCL_LIBRARY="\${TCL_LIBRARY:-$TCL_LIBRARY}"
TK_LIBRARY="\${TK_LIBRARY:-$TK_LIBRARY}"
DAVINCIHOME="\${DAVINCIHOME:-$DAVINCIHOME}"
JRE_HOME="\${JRE_HOME:-$JRE_HOME}"
export ECLIPSEDIR TCL_LIBRARY TK_LIBRARY $FRAMEWORK_PATH_NAME $LD_LIB_PATH_NAME DAVINCIHOME JRE_HOME
exec "$LIB_ARCH_DIR/eclipse.exe" "\$@"
EOF
chmod 755 "$dest"

dest="$EXE_DIR/tkeclipse"
echo Making "$dest"
rm -f "$dest"
cat > "$dest" <<EOF
#! /bin/sh
ECLIPSEDIR="\${ECLIPSEDIR:-$ECLIPSEDIR}"
$LD_LIB_PATH_NAME="\$ECLIPSEDIR/lib/$ARCH:$TCL_ARCH_LIBRARY:\$$LD_LIB_PATH_NAME"
EOF
case $ARCH in 
    *_macosx)
	cat >> "$dest" <<EOF
DYLD_FRAMEWORK_PATH="\$TCL_FRAMEWORK:\$DYLD_FRAMWORK_PATH"
EOF
	;;
esac
cat >> "$dest" <<EOF
TCL_LIBRARY="\${TCL_LIBRARY:-$TCL_LIBRARY}"
TK_LIBRARY="\${TK_LIBRARY:-$TK_LIBRARY}"
DAVINCIHOME="\${DAVINCIHOME:-$DAVINCIHOME}"
JRE_HOME="\${JRE_HOME:-$JRE_HOME}"
export ECLIPSEDIR TCL_LIBRARY TK_LIBRARY $FRAMEWORK_PATH_NAME $LD_LIB_PATH_NAME DAVINCIHOME JRE_HOME
exec "$WISH_DIRECTORY/wish$TCL_VERSION" "$ECLIPSEDIR/lib_tcl/tkeclipse.tcl" -- "\$@"
EOF
chmod 755 "$dest"

#-------------------------------------------------------------------
# xtkeclipse and xtktools
#-------------------------------------------------------------------

case $ARCH in
    *_macosx)

	if test $XWISH_DIRECTORY != none; then

	    dest="$EXE_DIR/xtkeclipse"
	    echo Making "$dest"
	    rm -f "$dest"
	    cat > "$dest" <<EOF
#! /bin/sh
ECLIPSEDIR="\${ECLIPSEDIR:-$ECLIPSEDIR}"
DYLD_LIBRARY_PATH="\$ECLIPSEDIR/lib/$ARCH:$TCL_ARCH_LIBRARY:\$DYLD_LIBRARY_PATH"
DYLD_FRAMEWORK_PATH="\$TCL_FRAMEWORK:\$DYLD_FRAMEWORK_PATH"
TCL_LIBRARY="\${TCL_LIBRARY:-$TCL_LIBRARY}"
TK_LIBRARY="\${TK_LIBRARY:-$TK_LIBRARY}"
DAVINCIHOME="\${DAVINCIHOME:-$DAVINCIHOME}"
JRE_HOME="\${JRE_HOME:-$JRE_HOME}"
export ECLIPSEDIR TCL_LIBRARY TK_LIBRARY DYLD_FRAMEWORK_PATH DYLD_LIBRARY_PATH DAVINCIHOME JRE_HOME
exec "$XWISH_DIRECTORY/$XWISH_EXEC" "$ECLIPSEDIR/lib_tcl/tkeclipse.tcl" -- "\$@"
EOF
	    chmod 755 "$dest"

	    dest="$EXE_DIR/xtktools"
	    echo Making "$dest"
	    rm -f "$dest"
	    cat > "$dest" <<EOF
#! /bin/sh
ECLIPSEDIR="\${ECLIPSEDIR:-$ECLIPSEDIR}"
DYLD_LIBRARY_PATH="\$ECLIPSEDIR/lib/$ARCH:$TCL_ARCH_LIBRARY:\$DYLD_LIBRARY_PATH"
DYLD_FRAMEWORK_PATH="\$TCL_FRAMEWORK:\$DYLD_FRAMEWORK_PATH"
TCL_LIBRARY="\${TCL_LIBRARY:-$TCL_LIBRARY}"
TK_LIBRARY="\${TK_LIBRARY:-$TK_LIBRARY}"
DAVINCIHOME="\${DAVINCIHOME:-$DAVINCIHOME}"
export ECLIPSEDIR TCL_LIBRARY TK_LIBRARY DYLD_FRAMEWORK_PATH DYLD_LIBRARY_PATH DAVINCIHOME
exec "$XWISH_DIRECTORY/$XWISH_EXEC" "$ECLIPSEDIR/lib_tcl/tktools.tcl" -- "\$@"
EOF
	    chmod 755 "$dest"

	fi
	;;
esac

#-----------------------------------------------------------------

if have_java_interface; then

    #--------------------------------------------------------------
    # make the jeclipse script
    #--------------------------------------------------------------

    #suppresses a java warning which comes up in linux

    JIT_OPTION=""

    case $ARCH in
    i386_linux)
	JIT_OPTION="-Djava.compiler="
        ;;
    esac
    
    dest="$EXE_DIR/jeclipse"
    echo Making "$dest"
    rm -f "$dest"
    cat > "$dest" <<EOF
#! /bin/sh
ECLIPSEDIR="\${ECLIPSEDIR:-$ECLIPSEDIR}"
EOF
case $ARCH in
    *_macosx)
	cat >> "$dest" <<EOF
DYLD_LIBRARY_PATH="\$ECLIPSEDIR/lib/$ARCH:$TCL_ARCH_LIBRARY:\$DYLD_LIBRARY_PATH"
DYLD_FRAMEWORK_PATH="\$TCL_FRAMEWORK:\$DYLD_FRAMEWORK_PATH"
export DYLD_FRAMEWORK_PATH DYLD_LIBRARY_PATH 
EOF
	;;
    *)
	cat >> "$dest" <<EOF
# No longer necessary to set the LD_LIBRARY_PATH as this is hacked around
# in java.
# LD_LIBRARY_PATH="\$ECLIPSEDIR/lib/$ARCH:\$LD_LIBRARY_PATH"
EOF
	;;
esac

cat >> "$dest" <<EOF
JRE_HOME="\${JRE_HOME:-$JRE_HOME}"
CLASSPATH="\$ECLIPSEDIR/lib/eclipse.jar:\${JRE_HOME}/lib/rt.jar"
export ECLIPSEDIR JRE_HOME
exec "\${JRE_HOME}/bin/java" ${JIT_OPTION} -Declipse.directory="\$ECLIPSEDIR" -classpath "\$CLASSPATH" com.parctechnologies.eclipse.JEclipse "\$@"
EOF
    chmod 755 "$dest"

fi


#-------------------------------------------------------------------
# tktools
#-------------------------------------------------------------------

dest="$EXE_DIR/tktools"
echo Making "$dest"
rm -f "$dest"
cat > "$dest" <<EOF
#! /bin/sh
ECLIPSEDIR="\${ECLIPSEDIR:-$ECLIPSEDIR}"
$LD_LIB_PATH_NAME="\$ECLIPSEDIR/lib/$ARCH:$TCL_ARCH_LIBRARY:\$$LD_LIB_PATH_NAME"
EOF
case $ARCH in 
    *_macosx)
	cat >> "$dest" <<EOF
DYLD_FRAMEWORK_PATH="\$TCL_FRAMEWORK:\$DYLD_FRAMWORK_PATH"
EOF
	;;
esac
cat >> "$dest" <<EOF
TCL_LIBRARY="\${TCL_LIBRARY:-$TCL_LIBRARY}"
TK_LIBRARY="\${TK_LIBRARY:-$TK_LIBRARY}"
DAVINCIHOME="\${DAVINCIHOME:-$DAVINCIHOME}"
export ECLIPSEDIR TCL_LIBRARY TK_LIBRARY $FRAMEWORK_PATH_NAME $LD_LIB_PATH_NAME DAVINCIHOME 
exec "$WISH_DIRECTORY/wish$TCL_VERSION" "$ECLIPSEDIR/lib_tcl/tktools.tcl" -- "\$@"
EOF
chmod 755 "$dest"

#--------------------------------------------------------------
# Build the reference documentation
#--------------------------------------------------------------

if [ "$BUILD_DOCS" = y ] ; then
	echo "Building reference documentation, please wait."
	"$EXE_DIR/eclipse" -e 'lib(document),ecis_to_htmls.'
else
	echo "Skipping build of reference documentation."
fi

#--------------------------------------------------------------
# Save the parameters for the next run
#--------------------------------------------------------------

dest="$ECLIPSEDIR/lib/$ARCH/SITE_PARAMS"
rm -f "$dest"
cat >"$dest" <<EOF
ECLIPSEDIR='$ECLIPSEDIR'
EXE_DIR='$EXE_DIR'
SIMPLE="$SIMPLE"
WANT_MEGALOG="$WANT_MEGALOG"
WANT_PARALLELISM="$WANT_PARALLELISM"
WANT_TCL_WM="$WANT_TCL_WM"
WANT_MPS="$WANT_MPS"
REBUILD_DOCS="$REBUILD_DOCS"
TCL_LIBRARY='$TCL_LIBRARY'
TK_LIBRARY='$TK_LIBRARY'
DAVINCIHOME='$DAVINCIHOME'
TCL_ARCH_LIBRARY='$TCL_ARCH_LIBRARY'
WISH_DIRECTORY='$WISH_DIRECTORY'
XWISH_DIRECTORY='$XWISH_DIRECTORY'
TCL_VERSION='$TCL_VERSION'
TCL_FRAMEWORK='$TCL_FRAMEWORK'
X_LIBRARIES='$X_LIBRARIES'
USER_OBJECTS='$USER_OBJECTS'
JRE_HOME='$JRE_HOME'
EOF
chmod a+r "$dest"


echo "----------------------------------------------------------------------"
echo ECLiPSe installation done.
echo You should now add "$EXE_DIR"
echo to your PATH environment variable.

exit 0

