#!/usr/bin/tcsh

###############################################################
#
#  Modified from the original ns_2.1b8_install.sh 
#  by  ee602ta@ee.tamu.edu
#
#  Disclaimer: Use at your own risk. No warranties. 
#
###############################################################
###############################################################
#                 Ns-2 installation script
#
#              send bug-reports to ee602ta@ee.tamu.edu
#
#   Caveat:  Use it at your own risk
#            No warranty whatsoever.
###############################################################
#
#  Instructions:
#  -------------
#  Copy ths file (ns-2.28_install.sh)
#  to your $HOME directory and "cd" to your $HOME 
#  directory
# 
# % chmod 700 ns-2.28_install.sh
# % sh ns-2.28_install.sh
#
# This will create a directory by name "ns-allinone-2.28" in your home
# directory, and create links to the main NS-2 source directories.  
#
# The "ns" executable is in the directory ~/ns-allinone-2.28/ns-2.28
#
# You can now proceed with any changes to the source in your 
# directory. To make changes to an existing file 
# (say tcp-reno.cc) you will have to
# first delete the link from your <$HOME>/ns-allinone-2.28/<subdir> 
# directory, copy the file
# from the original source into your <$HOME>/ns-allinone-2.28/<subdir>
# directory and then work on it.
#
# After you are done with your changes, run "make" and a 
# new "ns" will be created in your ~/ns-allinone-2.28/ns-2.28 directory.
# Use this to run your test tcl scripts
#
# For example, if you want to modify tcp-reno.cc, you would do
#
# % cd ~/ns-allinone-2.28/ns-2.28/<subdir>
# % rm tcp-reno.cc
# % cp <SOURCE_LOCATION>/tcp-reno.cc .
# % vi tcp-reno.cc ;# make changes to the file
# % cd ~/ns-allinone-2.28/ns-2.28
# % make
#
#
######################################################################

BASEDIR="/baby/ns-allinone-2.28"
sed_BASEDIR="\/baby\/ns-allinone-2.28"
NSVER="2.28"
TCLVER="8.4.5"
TKVER="8.4.5"
TCLCLVER="1.16"
OTCLVER="1.9"
NAMVER="1.11"
ZLIBVER="1.1.4"
XGRAPHVER="12.1"

echo "Creating main ns-2.28 directory..."
mkdir ns-allinone-2.28
cd ns-allinone-2.28

echo "Creating links..."

echo "linking $BASEDIR/bin ==> $PWD/bin"
ln -s $BASEDIR/bin bin

echo "linking $BASEDIR/nam-$NAMVER ==> $PWD/nam-$NAMVER"
ln -s $BASEDIR/nam-$NAMVER nam-$NAMVER

echo "linking $BASEDIR/otcl-$OTCLVER ==> $PWD/otcl-$OTCLVER"
ln -s $BASEDIR/otcl-$OTCLVER otcl-$OTCLVER

echo "linking $BASEDIR/tcl$TCLVER ==> $PWD/tcl$TCLVER"
ln -s $BASEDIR/tcl$TCLVER tcl$TCLVER

echo "linking $BASEDIR/tclcl-$TCLCLVER ==> $PWD/tclcl-$TCLCLVER"
ln -s $BASEDIR/tclcl-$TCLCLVER tclcl-$TCLCLVER

echo "linking $BASEDIR/tk$TKVER ==> $PWD/tk$TKVER"
ln -s $BASEDIR/tk$TKVER tk$TKVER

echo "linking $BASEDIR/cweb ==> $PWD/cweb"
ln -s $BASEDIR/cweb cweb

echo "linking $BASEDIR/lib ==> $PWD/lib"
ln -s $BASEDIR/lib lib

echo "linking $BASEDIR/sgb ==> $PWD/sgb"
ln -s $BASEDIR/sgb sgb

echo "linking $BASEDIR/zlib-$ZLIBVER ==> $PWD/zlib-$ZLIBVER"
ln -s $BASEDIR/zlib-$ZLIBVER zlib-$ZLIBVER

echo "linking $BASEDIR/gt-itm ==> $PWD/gt-itm"
ln -s $BASEDIR/gt-itm gvt-itm

echo "linking $BASEDIR/include ==> $PWD/include"
ln -s $BASEDIR/include include

echo "linking $BASEDIR/man ==> $PWD/man"
ln -s $BASEDIR/man man

echo "linking $BASEDIR/xgraph-$XGRAPHVER ==> $PWD/xgraph-$XGRAPHVER"
ln -s $BASEDIR/xgraph-$XGRAPHVER xgraph-$XGRAPHVER

echo "Making ns-2 source directory: $PWD/ns-$NSVER..."
mkdir ns-$NSVER
cd ns-$NSVER

echo "Symbolic links to the source directories will be created here"
echo "This may take some time"

for fname in `( ls -l $BASEDIR/ns-$NSVER | grep "^d" | awk ' {print $9 }' )`
do
{
	echo "Creating directory: $fname"
	mkdir $fname
	
	cd $fname

	ln -s $BASEDIR/ns-$NSVER/$fname/* .
	cd ../
}
done

for fname in `( ls -l $BASEDIR/ns-$NSVER | grep "^-" | awk '{print $9 }' )`
do
{
	echo "$BASEDIR/ns-$NSVER/$fname --->  $fname"
	ln -s $BASEDIR/ns-$NSVER/$fname $fname
}
done

echo "Copying Makefile"
\rm -f	Makefile
cp  $BASEDIR/ns-$NSVER/Makefile .

echo "Ns-2 installation complete"
echo "--------------------------"
echo "**************************"
echo "source /usr/local/bin/setup.ns to setup the library paths"
echo "**************************"
echo "--------------------------"



