#! /bin/sh
#
# Copyright (C) 1998 by USC/ISI
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation, advertising
# materials, and other materials related to such distribution and use
# acknowledge that the software was developed by the University of
# Southern California, Information Sciences Institute.  The name of the
# University may not be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#

#
# Maintainer: Ya Xu <yaxu@isi.edu>
# Version Date: 1998/07/14 21:54:39 $
#
#

die() {
      echo "$@" 
      exit 1
}
# Get current path
CUR_PATH=`pwd`

# create tcl8.0 and tk8.0 installation directory

if [ ! -d tclbox ]
then
mkdir tclbox
fi

if [ ! -d tkbox ]
then
mkdir tkbox
fi

#compile and install nam

cd ./nam-1

./configure --with-otcl=../otcl --with-tclcl=../tclcl --with-tcl=../tclbox --with-tk=../tkbox --with-tcldebug=no --disable-static --prefix=/mit/sipbnet || die "Nam configuration failed! Exiting ..."

if make
then 
    echo "Nam has been installed successfully."
else
    echo "Nam make failed! Continue ..."
fi

cd ../

# install nam, ns, xgraph into bin

if [ ! -d bin ]
then
mkdir bin
fi

cd bin

ln -s $CUR_PATH/ns-2/ns ns

if test -x $CUR_PATH/nam-1/nam
then
    ln -s $CUR_PATH/nam-1/nam nam
else
    echo "Please compile your nam separately."
fi

if test -x $CUR_PATH/xgraph/xgraph
then
    ln -s $CUR_PATH/xgraph/xgraph xgraph
else
    echo "Please compile your xgraph separately."
fi

if test -x $CUR_PATH/gt-itm/bin/sgb2ns
then 
    ln -s $CUR_PATH/gt-itm/bin/sgb2ns sgb2ns
    ln -s $CUR_PATH/gt-itm/bin/sgb2hierns sgb2hierns
    ln -s $CUR_PATH/gt-itm/bin/sgb2comns sgb2comns
    ln -s $CUR_PATH/gt-itm/bin/itm itm
    ln -s $CUR_PATH/gt-itm/bin/sgb2alt sgb2alt
    ln -s $CUR_PATH/gt-itm/bin/edriver edriver
else
    echo "Please compile your gt-itm & sgb2ns separately."
fi

echo "Ns-allinone package has been installed successfully."
echo "Here are the installation places:"
echo "ns:	$CUR_PATH/ns-2/ns"
echo "otcl:	$CUR_PATH/otcl"
echo "tclcl:	$CUR_PATH/tclcl"
echo "tcl8.0:	$CUR_PATH/tclbox"
echo "tk8.0:	$CUR_PATH/tkbox"

if [ -x $CUR_PATH/nam-1/nam ]
then
echo "nam:	$CUR_PATH/nam-1/nam"
fi

if [ -x $CUR_PATH/xgraph/xgraph ]
then
echo "xgraph:	$CUR_PATH/xgraph"
fi
if [ -x $CUR_PATH/gt-itm/bin/sgb2ns ] 
then
echo "gt-itm:   $CUR_PATH/itm, edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hierns"
fi

echo ""
echo "You can delete $CUR_PATH/tcl8.0 and $CUR_PATH/tk8.0 if "
echo "you want save your disk space"

echo "-----------------------------------------------------"
echo "Please put $CUR_PATH/bin into your PATH environment."
echo "Please put $CUR_PATH/otcl into your LD_LIBRARY_PATH environment!"
echo ""
echo "You can run the ns validation suite with"
echo "cd ns-2; ./validate"

exit 0

