#!/bin/csh -f
# **********************************************************************
# Computer Vision/Image Processing Tool Project - Dr. Scott Umbaugh SIUE
# **********************************************************************
#
#             File Name: install.csh
#           Description: CVIPtools installation script
#         Related Files: 
#   Initial Coding Date: Sun Dec 22 21:34:43 CST 1996,
#     major revision at: Fri Aug  1 11:00:08 CDT 1997
#           Portability: C Shell script
#            References:
#             Author(s): Arve Kjoelen and Yansheng Wei
#                        Southern Illinois University @ Edwardsville
#
## Copyright (C) 1997 SIUE - by Scott Umbaugh, Arve Kjoelen and Yansheng Wei.
##
## Permission to use, copy, modify, and distribute this software and its
## documentation for any purpose and without fee is hereby granted, provided
## that the above copyright notice appear in all copies and that both that
## copyright notice and this permission notice appear in supporting
## documentation.  This software is provided "as is" without express or
## implied warranty.
##
# RCS (Revision Control System) Information
# ...Added automatically by RCS 
#
## $Log: install,v $
## Revision 1.17  1997/08/14 05:03:23  wzheng
## *** empty log message ***
##
## Revision 1.16  1997/08/13 15:18:23  wzheng
## delete /include/rpc when source and destination are the same
## re-arrange the make
##
## Revision 1.15  1997/08/08 21:18:01  yawei
## remove everything before copying files
##
## Revision 1.14  1997/08/08 21:01:58  yawei
## fixed library installation directory check problem
##
## Revision 1.13  1997/08/08 16:46:43  yawei
## added ending help mesage
##
## Revision 1.12  1997/08/08 16:40:41  yawei
## added bash and ksh recognition.
##
## Revision 1.11  1997/08/06 23:20:22  yawei
## changed the cp -r syntax
##
## Revision 1.10  1997/08/05 20:59:40  yawei
## *** empty log message ***
##
## Revision 1.9  1997/08/05 20:58:54  yawei
## *** empty log message ***
##
## Revision 1.8  1997/08/05 20:57:21  yawei
## corrected typo
##
## Revision 1.7  1997/08/05 17:41:48  yawei
## changed ldl check
##
## Revision 1.6  1997/08/05 16:57:39  yawei
## *** empty log message ***
##
## Revision 1.5  1997/08/05 16:43:32  yawei
## switched order ot make distclean of tcl/tk
##
## Revision 1.4  1997/08/05 16:23:10  yawei
## clean up tcl/tk alter installation
##
## Revision 1.3  1997/08/05 13:27:34  yawei
## - added image installation
## - modified IMAGE_PATh
##
## Revision 1.8  1997/08/01 21:37:11  yawei
## remove binaries for the source installation before compile
##
## Revision 1.7  1997/08/01 21:04:46  yawei
## removed g3states.h for TIFF
##
## Revision 1.6  1997/08/01 20:46:05  yawei
## removed CVIPTCL/Imakefile first before copy back
##
## Revision 1.5  1997/08/01 20:24:00  yawei
## added tclIndex creation
##
## Revision 1.4  1997/08/01 19:25:18  yawei
## modified install for tk
##
## Revision 1.3  1997/08/01 16:01:50  yawei
## major revision
##
#

#!/bin/csh -f
## install - a rudimentary installation program
## for CVIPtools, vresions 3.0 and above.
## Author: Arve Kjoelen (akjoele@ee.siue.edu), - Sun Dec 22 21:34:43 CST 1996
##
## Heuristics:
##

set method=""
set srcdir=""
set destdir=""
set cdrom="false"
set masksave = `umask`
set installimg = "false"
set shell
umask 022

echo "/**********************************************************"
echo "*                   CVIPtools Setup                       *"
echo "* ======================================================  *"
echo "*                                                         *"
echo "* This setup script will perform the following functions  *"
echo "* To get you started with CVIPtools:                      *"
echo "* 1.  Prompt you for the installation method you want     *"
echo "* 2.  Add the following environment variables to your     *"
echo "*     .cshrc   or .profile file (depending on your shell):*"
echo "*     CVIPHOME, CVIP_IMGPATH, CVIP_DISPLAY, TCL_LIBRARY,  *"
echo "*     TK_LIBRARY, XF_LOAD_PATH                            *"
echo "* 3. Add the following three directories to your path:    *"
echo "*    CVIPHOME/CVIPTCL, CVIPHOME/bin, CVIPHOME/DISPLAY     *"
echo "***********************************************************"
echo "* and if you choosed source installation                  *"
echo "* 4. Attempt to compile the versions of tcl and tk bundled*"
echo "*    with CVIPtools                                       *"
echo "* 5. Attempt to compile CVIPtools by running consecutively*"
echo "*    xmkmf; make Makefiles;make includes;make depend; make*"
echo "*                                                         *"
echo "*    USE FULL PATHNAME IN ANSWERING THE QUESTIONS         *"
echo "***********************************************************"
echo "Hit return to continue"
echo ""
set ans = "$<"
set ans = ""
echo ""

directory:
echo "Let's first find out the directories:"

# Find the target directory
destdir:
echo "	Under which directory do you want to install CVIPtools? i.e."
echo -n "	CVIPHOME[$ans]:"
set ans = "$<"
if ( "$ans" == "" ) goto destdir

if ( -e "$ans" && ! -d "$ans" ) then
	echo "	($ans) exists and is not a directory, try another one"
	goto destdir
else if ( -e "$ans" && ! ( -r "$ans" && -w "$ans" && -x "$ans") ) then
	echo "	($ans) exists and permission denied, try another one"
	goto destdir
else if ( ! -e "$ans" && ! {(mkdir $ans)} ) then 
	echo "	can't create ($ans), permission denied, try another one"
	goto destdir
endif

# confirm the target directory
set destdir=$ans
echo "	All files under $destdir might be erased, continue?"
echo -n "	[Y/N]:"
set ans = "$<"
while ( $ans !~ [Yy] && $ans !~ [Nn] ) 
echo -n "		Wrong choice [Y/N]:"
set ans = "$<"
end
if ( $ans =~ [Nn] ) then
	set ans=""
	goto destdir
endif
echo "the target directory is: $destdir"

# Find the target directory
echo " "

srcdir:
if ( "$srcdir" == "" ) set srcdir=`pwd`
echo "	From which directory do you want to install CVIPtools?"
echo -n "	[$srcdir]:"
set ans = "$<"
if ( "$ans" == "" ) set ans=$srcdir

if ( ! -e "$ans" ) then 
	echo "	($ans) doesn't exist, try again"
	goto srcdir
else if ( -e "$ans" && ! -d "$ans" ) then
	echo "	($ans) exists and is not a directory, try again"
	goto srcdir
else if ( -e "$ans" && ! ( -r "$ans" && -x "$ans") ) then
	echo "	($ans) exists but permission denied, try again"
	goto srcdir
endif

set srcdir=$ans
echo "the source directory is: $srcdir"
set sys=`uname`
if ( $sys == "SunOS" ) set sys="Solaris"
if ( -e $srcdir/src && -e $srcdir/$sys ) then
	echo "	Seems you are installing from the CDROM"
	echo "	Do you want to install the images to your hard disk (about 27MB)"
	set cdrom = "true"
	echo -n "	[Y/N]:"
	set ans = "$<"
	while ( $ans !~ [Yy] && $ans !~ [Nn] ) 
		echo -n "		Wrong choice, try again[Y/N]:"
		set ans = "$<"
	end
	if ( $ans =~ [Yy] ) then
		set installimg = "true"
	endif
endif
echo ""


#source installation?
install_method:
echo ""
echo "Let's now figure out what you want"

echo "	Compile CVIPtools? In this case you"
echo "	need all the source files, then create the libraries "
echo "	and executables on your machine."
echo "	HINT: If you are using a 486 PC, it might take up to a maximum"
echo "   of 3 hours to install the source distribution"
src_install:
echo -n "	==> Source installation [Y/N]:"
set ans = "$<"
while ( $ans !~ [Yy] && $ans !~ [Nn] ) 
echo -n "		Wrong choice, try again[Y/N]:"
set ans = "$<"
end
if ( $ans =~ [Yy] ) then
	set method = "source"
	echo "	Checkiing your files..."
	set temp = $srcdir
	if ( $cdrom == "true" ) set temp = $srcdir/src
	if ( -d $temp/APPLICATIONS  \
			&& -d $temp/ARITHLOGIC  \
			&& -d $temp/BandUtilities  \
			&& -d $temp/COLOR  \
			&& -d $temp/COMPRESSION  \
			&& -d $temp/CONVERSION  \
			&& -d $temp/CVIPTCL  \
			&& -d $temp/DISPLAY  \
			&& -d $temp/FEATURE  \
			&& -d $temp/GEOMETRY  \
			&& -d $temp/HISTOGRAM  \
			&& -d $temp/IOUtilities  \
			&& -d $temp/Image  \
			&& -d $temp/MORPHOLOGICAL  \
			&& -d $temp/Mapping  \
			&& -d $temp/MatrixAlgebra  \
			&& -d $temp/NOISE  \
			&& -d $temp/Object  \
			&& -d $temp/ObjectManager  \
			&& -d $temp/RegionOfInterest  \
			&& -d $temp/SEGMENTATION  \
			&& -d $temp/SPATIALFILTER  \
			&& -d $temp/TRANSFORMS  \
			&& -d $temp/VectorAlgebra  \
			&& -d $temp/XFORMFILTER  \
			&& -d $temp/docs  \
			&& -d $temp/include  \
			&& -d $temp/man) then
		echo "	It seems you have all the directories"
	else
		echo "	You lack some of the directories, think again"
		goto  src_install
	endif
	goto confirm
endif

# Library install
echo ""
echo "	Install the CVIPtools libraries? in this "
echo "	case you will be able to run your CVIPlab program, or "
echo "	write other applications. Also you will be able to run  "
echo "	CVIPtools executables by default. If you only need to run"
echo "	CVIPtools, answer N"

lib_install:
echo -n "	==> Library install [Y/N]:"
set ans = "$<"
while ( $ans !~ [Yy] && $ans !~ [Nn] ) 
echo -n "		Wrong choice, try again[Y/N]:"
set ans = "$<"
end
if ( $ans =~ [Yy] ) then
	set method = "library"
	echo "	Checkiing your files..."
	set temp = $srcdir
	set temp1 = $srcdir
	if ( $cdrom == "true" ) then
		set temp = $srcdir/$sys
		set temp1 = $srcdir/src
	endif
	if ( -d $temp/lib  && -d $temp/bin  && -d $temp1/include  \
			&& -d $temp1/man) then
		echo "	It seems you have all the directories"
	else
		echo "	You lack some of the directories, think again"
		goto  lib_install
	endif
	goto confirm
endif

# Binary install
echo ""
echo "	Install the CVIPtools executables only? In this "
echo "	case you will be able to run your CVIPtools program, but "
echo "	you won't be able to write other applications. If you need more"
echo "	than only running CVIPtools, answer N"

bin_install:
echo -n "	==> Binary install [Y/N]:"
set ans = "$<"
while ( $ans !~ [Yy] && $ans !~ [Nn] ) 
echo -n "		Wrong choice, try again[Y/N]:"
set ans = "$<"
end
if ( $ans =~ [Yy] ) then
	set method = "binary"
	echo "	Checking your files..."
	set temp = $srcdir
	if ( $cdrom == "true" ) set temp = $srcdir/$sys
	if ( -e $temp/bin && -d $temp/bin ) then
		echo "	It seems you have all the directories"
	else
		echo "	You lack some of the directories, think again"
		goto  bin_install
	endif
	goto confirm
else 
	goto install_method
endif

confirm:
#Summary
echo ""
echo "**************** Installation Setup ********************"
echo "Source      directory: $srcdir"
echo "Destination directory: $destdir"
echo -n "Install from   CDROM : "
if ( "$cdrom" == "true" ) then
	echo "Yes"
else 
	echo "No"
endif
echo "Installation   Method: $method"
if ( "$installimg" == "true" ) then
	echo "Install  images from CDROM to the hard disk"
endif

echo ""
echo "	Do you want to change any of the settings listed above?"	
echo "	If you answer Y, we will go back to the beginning and setup"
echo "	everything again"

bin_install:
echo -n "	==> Reset [Y/N]:"
set ans = "$<"
while ( $ans !~ [Yy] && $ans !~ [Nn] ) 
	echo -n "		Wrong choice, try again[Y/N]:"
	set ans = "$<"
end
if ( $ans =~ [Yy] ) then
	clear
	set ans = ""
	goto directory
endif


copy_file:

cd $srcdir; set temp = `pwd`
cd $destdir; set temp1 = `pwd`
if ( "$temp" == "$temp1" ) then 
		echo "	You are installing CVIPtools on the same destination"
		echo "	directory as the source directory, no files need to"
		echo "	be copied."
		echo "  rpc is removed."
		if ( -e $destdir/include/rpc ) rm -rf $destdir/include/rpc
		goto compile
endif

#confirm copy file
echo ""
echo "	You are trying to install CVIPtools on a directory different"
echo "	from the source directory. I am going to copy the files from"
echo "	the source directory to the destination directory."
echo "Warning *******************"
echo "	EVERYTHING IN THE DESTINATION DIRECTORY WILL BE ERASED"
echo "	Do you want to continue with the installation?"
echo -n "	==> Continue [Y/N]:"
set ans = "$<"
while ( $ans !~ [Yy] && $ans !~ [Nn] ) 
	echo -n "		Wrong choice, try again[Y/N]:"
	set ans = "$<"
end
if ( $ans =~ [Nn] ) then
	echo "You have cancelled the installation"
	echo "Any key to go back to the beginning..."
	set ans = "$<"
	goto directory
endif

echo "	Comfirm copy files again"
echo -n "	==> Continue [Y/N]:"
set ans = "$<"
while ( $ans !~ [Yy] && $ans !~ [Nn] ) 
	echo -n "		Wrong choice, try again[Y/N]:"
	set ans = "$<"
end
if ( $ans =~ [Nn] ) then
	echo "You have cancelled the installation"
	echo "Any key to go back to the beginning..."
	set ans = "$<"
	goto directory
endif

echo ""

echo "	Remove old  files..."
rm -rf $destdir/*
switch ( "$method" ) 
	case source:
		echo "	Copy all the files, please wait..."
		cd  $srcdir
		if ( "$cdrom" == "true" )  cd $srcdir/src
		cp -r ./* $destdir/.
		if ( -e $destdir/include/rpc ) rm -rf $destdir/include/rpc
		if ( -e $destdir/CONVERSION/TIFF/g3states.h ) rm -f $destdir/CONVERSION/TIFF/g3states.h
		find $destdir \( -name "*.o" -o -name "*.a" \) -exec rm -f {} \;
		breaksw
	case library:
		echo "	Remove old  header files..."
		if ( -e $destdir/include ) rm -rf $destdir/include
		echo "	Copy the header files..."
		if ( "$cdrom" == "true" )  then
			cp -r $srcdir/src/include $destdir
		else
			cp  -r $srcdir/include $destdir
		endif
		if ( -e $destdir/include/rpc ) rm -rf $destdir/include/rpc

		echo "	Remove old  library and binary files..."
		if ( -e $destdir/lib ) rm -rf $destdir/lib
		if ( -e $destdir/bin ) rm -rf $destdir/bin
		if ( -e $destdir/CVIPTCL/lib ) rm -rf $destdir/CVIPTCL/lib
		if ( -e $destdir/CVIPTCL/GUI_SCRIPTS ) rm -rf $destdir/CVIPTCL/GUI_SCRIPTS
		echo "	Copy the library and binary files..."
		if ( "$cdrom" == "true" )  then
			cp -r $srcdir/$sys/lib $destdir
			cp -r $srcdir/$sys/bin $destdir
			if ( ! -e $destdir/CVIPTCL ) mkdir $destdir/CVIPTCL
			cp -r $srcdir/src/CVIPTCL/lib $destdir/CVIPTCL
			cp -r $srcdir/src/CVIPTCL/GUI_SCRIPTS $destdir/CVIPTCL
		else
			cp -r $srcdir/lib $destdir
			cp -r $srcdir/bin $destdir
			if ( ! -e $destdir/CVIPTCL ) mkdir $destdir/CVIPTCL
			cp -r $srcdir/CVIPTCL/lib $destdir/CVIPTCL
			cp -r $srcdir/CVIPTCL/GUI_SCRIPTS $destdir/CVIPTCL
		endif

		echo "	Remove old man pages and documentation..."
		if ( -e $destdir/man ) rm -rf $destdir/man
		if ( -e $destdir/docs ) rm -rf $destdir/docs
		echo "	install the man pages and documentation..."
		if ( "$cdrom" == "true" )  then
			cp -r $srcdir/src/man $destdir
			cp -r $srcdir/src/docs $destdir
		else
			cp -r $srcdir/man $destdir
			cp -r $srcdir/docs $destdir
		endif

		breaksw
	case binary:
		echo "	Remove old  binary and scriptfiles..."
		if ( -e $destdir/bin ) rm -rf $destdir/bin
		if ( -e $destdir/CVIPTCL/lib ) rm -rf $destdir/CVIPTCL/lib
		if ( -e $destdir/CVIPTCL/GUI_SCRIPTS ) rm -rf $destdir/CVIPTCL/GUI_SCRIPTS
		echo "	Copy the binary and script files..."
		if ( "$cdrom" == "true" )  then
			cp -r $srcdir/$sys/bin $destdir
			if ( ! -e $destdir/CVIPTCL ) mkdir $destdir/CVIPTCL
			cp -r $srcdir/src/CVIPTCL/lib $destdir/CVIPTCL
			cp -r $srcdir/src/CVIPTCL/GUI_SCRIPTS $destdir/CVIPTCL
		else
			cp -r $srcdir/bin $destdir
			if ( ! -e $destdir/CVIPTCL ) mkdir $destdir/CVIPTCL
			cp -r $srcdir/CVIPTCL/lib $destdir/CVIPTCL
			cp -r $srcdir/CVIPTCL/GUI_SCRIPTS $destdir/CVIPTCL
		endif

		echo "	Remove old man pages and documentation..."
		if ( -e $destdir/man ) rm -rf $destdir/man
		if ( -e $destdir/docs ) rm -rf $destdir/docs
		echo "	install the man pages and documentation..."
		if ( "$cdrom" == "true" )  then
			cp -r $srcdir/src/man $destdir
			cp -r $srcdir/src/docs $destdir
		else
			cp -r $srcdir/man $destdir
			cp -r $srcdir/docs $destdir
		endif
		breaksw
endsw
cd $destdir/bin
if ( -e "changes.txt") \rm -f changes.txt
if ( -e "cygwin.dll") \rm -f cygwin.dll
if ( -e "iregistr.txt") \rm -f iregistr.txt
if ( -e "ls.exe") \rm -f ls.exe
if ( -e "lviewpro.exe") \rm -f lviewpro.exe
if ( -e "lviewpro.gid") \rm -f lviewpro.gid
if ( -e "lviewpro.hlp") \rm -f lviewpro.hlp
if ( -e "readme.txt") \rm -f readme.txt
if ( -e "sregistr.txt") \rm -f sregistr.txt

if ( "$installimg" == "true" ) then
	echo "	install  images from CDROM to the hard disk"
	cp -r $srcdir/Images $destdir
endif

compile:


# Variable initializations
set sol2nisplus="false"
echo "********CVIPtools setup:********"
echo "Adding environment variables and path information..."
set sys=`uname -s`
if ("$sys" == "SunOS") then
   set rev=`uname -r | /bin/cut -c1`
   if ("$rev" == "5") then
      set ns=`/bin/cat /etc/nsswitch.conf | grep ^passwd | awk '{print $2}'`
      if ("$ns" == "nisplus") then
	 set sol2nisplus="true"
	 set ushell=`/usr/bin/niscat passwd.org_dir | grep $home | grep $user | awk -F: '{print $7}'`
      endif
   endif
endif

if ("$sol2nisplus" == "false") then
   set ushell=`cat /etc/passwd | grep $home | grep $user | awk -F: '{print $7}'`
endif

set shellfile = ""
# determine the shell in use
if ( "$ushell" =~ *csh* ) then
	set shell=csh
else if ( "$ushell" =~ *bash* ) then
	set shell=bash
	if ( -e $home/.bashrc ) then
		set shellfile = ".bashrc"
	else
		set shellfile = ".profile"
	endif
else if ( "$ushell" =~ *ksh* ) then
	set shell=ksh
	if ( -e $home/.kshrc ) then
		set shellfile = ".kshrc"
	else
		set shellfile = ".profile"
	endif
else if ( "$ushell" =~ *sh* ) then
	set shell=bsh
	set shellfile = ".bashrc"
else if ( -e $home/.cshrc ) then
   echo "	I guess you are using a csh or its variant"
	set shell=csh
else if ( -e $home/.profile ) then
   echo "	I guess you are using a Bourne shell or its variant"
	set shell=bsh
	set shellfile = ".bashrc"
else
   echo "Error: Could not recognize your default shell"
   echo "Looked for /bin/sh, /bin/ksh, /bin/csh, /bin/tcsh, /usr/local/bin/tcsh"
   echo "You will need to manually edit the equivalent of your .profile or"
   echo ".cshrc file"
   exit 2
endif

cd  $destdir
if ( ! $?CVIPHOME ) then
	if ( $shell == "csh" ) then
		echo "setenv CVIPHOME $cwd" >> $home/.cshrc
		if ( $cdrom == "true" ) then
			echo "setenv CVIP_IMGPATH $destdir/Images/COVER:$destdir/Images/CHAP1:$destdir/Images/CHAP2:$destdir/Images/CHAP3:$destdir/Images/CHAP4:$destdir/Images/CHAP5:$destdir/Images/CHAP6:$destdir/Images/CHAP7:$destdir/Images/CHAP8" >> $home/.cshrc
		else
			echo "setenv CVIP_IMGPATH ./" >> $home/.cshrc
		endif
		echo "setenv CVIP_DISPLAY picture" >> $home/.cshrc 
		echo "setenv TCL_LIBRARY ${cwd}/CVIPTCL/lib/tcl7.6" >> $home/.cshrc
		echo "setenv TK_LIBRARY ${cwd}/CVIPTCL/lib/tk4.2" >> $home/.cshrc
		echo "setenv XF_LOAD_PATH ${cwd}/CVIPTCL/GUI_SCRIPTS" >> $home/.cshrc
		echo "set path=("'$path' "${cwd} ${cwd}/CVIPTCL ${cwd}/bin)" >> $home/.cshrc
	else 
		echo "CVIPHOME=${cwd} " >> $home/$shellfile
		if ( $cdrom == "true" ) then
			echo "CVIP_IMGPATH=$destdir/Images/COVER:$destdir/Images/CHAP1:$destdir/Images/CHAP2:$destdir/Images/CHAP3:$destdir/Images/CHAP4:$destdir/Images/CHAP5:$destdir/Images/CHAP6:$destdir/Images/CHAP7:$destdir/Images/CHAP8" >> $home/$shellfile
		else
			echo "CVIP_IMGPATH=./" >> $home/$shellfile
		endif
		echo "CVIP_DISPLAY=picture" >> $home/$shellfile
		echo "TCL_LIBRARY=${cwd}/CVIPTCL/lib/tcl7.6" >> $home/$shellfile
		echo "TK_LIBRARY=${cwd}/CVIPTCL/lib/tk4.2" >> $home/$shellfile
		echo "XF_LOAD_PATH=${cwd}/CVIPTCL/GUI_SCRIPTS" >> $home/$shellfile
		echo "PATH="'${PATH}':"${cwd}/CVIPTCL:${cwd}/bin" >> $home/$shellfile
		echo "export CVIPHOME" >> $home/$shellfile
		echo "export CVIP_IMGPATH" >> $home/$shellfile
		echo "export CVIP_DISPLAY" >> $home/$shellfile
		echo "export TCL_LIBRARY" >> $home/$shellfile
		echo "export TK_LIBRARY" >> $home/$shellfile
		echo "export XF_LOAD_PATH" >> $home/$shellfile
		echo "export PATH" >> $home/$shellfile
	endif
else
      echo "CVIPHOME detected in your envirnoment - skipping environment "
      echo "setup..."
endif

echo " "
if ( "$method" != "source" ) goto end

echo "Here, here we are at the exciting point\!\!"
echo "Hit return to continue with building CVIPtools... "
echo ""
set ans = "$<"

cd  $destdir
setenv CVIPHOME $cwd
build:
pushd . >& /dev/null
echo "********CVIPtools setup:********"
echo "Configuring tcl..."
cd ./CVIPTCL/tcl7.6/unix
make distclean >& /dev/null
if ( "$1" == "" ) then
   ./configure --prefix=${CVIPHOME}/CVIPTCL
else
   ./configure --enable-gcc --prefix=${CVIPHOME}/CVIPTCL
endif
echo "********CVIPtools setup:********"
echo "Compiling tcl..."
make
make install
echo "********CVIPtools setup:********"
echo "Configuring tk..."
cd ../..
grep  ldl tcl7.6/unix/Makefile >& /dev/null
if ( "$status" != "0" ) then
	sed 's/-ldl//g' Imakefile > tmp
	rm -f Imakefile
	mv tmp Imakefile
endif
cd tk4.2/unix
if ( "$1" == "" ) then
   ./configure --prefix=${CVIPHOME}/CVIPTCL
else
   ./configure --enable-gcc --prefix=${CVIPHOME}/CVIPTCL
endif
echo "********CVIPtools setup:********"
echo "Compiling tk..."
make
make install-binaries 
make install-libraries
make install-man
make distclean >& /dev/null
cd ../../tcl7.6/unix
make distclean >& /dev/null
popd
echo "********CVIPtools setup:********"
echo "Beginning installation of CVIPtools proper..."
xmkmf
make Makefiles
make includes
make depend
if ( "$1" == "" ) then
   make
else
   make -e $1 'CCOPTIONS=-w -g -O' 'CDEBUGFLAGS='
endif
##make clean
##make

echo "Removing old  library files..."
rm -f ./lib/*
echo "Creating links for the library files..."
foreach i (`find . -name "*.a"`)
	ln -s .$i ./lib/.
end

end:
cd $destdir/CVIPTCL/GUI_SCRIPTS
if ( -e $destdir/CVIPTCL/cviptcl ) then
	echo "auto_mkindex ./ *.tcl; exit" | ../cviptcl > & /dev/null
else if ( -e $destdir/bin/cviptcl ) then
	echo "auto_mkindex ./ *.tcl; exit" | ../../bin/cviptcl > & /dev/null
else
	echo "can't update your tclIndex file"
endif

echo "=============================================================="
echo "=            CVIPtools Installation Complete                 ="
echo "=  You need to Update your environment by running ~/.cshrc   ="
echo "=  for csh/tcsh,   ~/.profile for sh, ~/.bashrc for bash,    ="
echo "=  ~/.kcshrc or ~/.profile for ksh                           ="
echo "=============================================================="
umask $masksave
