#!/bin/bash


function check_result {
	if [ "$?" -ne 0 ]; then
		echo 
		echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
		echo "Error: Unable to compile" \"$1\"
		exit
	fi
}

function print_info {
	echo "------------------------------------------------------------------"
	echo "Compiling" \"$1\"
}

MAKE_FLAGS=""


# Compile tcl8.4.14
print_info tcl8.4.14
cd tcl8.4.14;
cd unix;
make clean;
./configure;
make $MAKE_FLAGS;
print_info tcl8.4.14
cd ../..;


# Compile tk
print_info tk8.4.14
cd tk8.4.14;
cd unix;
make clean;
rm config.cache;
./configure;
make $MAKE_FLAGS;
check_result tk8.4.14
cd ../..;


# Compile and configure otcl-1.13
print_info otcl-1.13
cd otcl-1.13;
make clean;
./configure;
make $MAKE_FLAGS;
check_result otcl-1.13
cd ..;
rm otcl;
ln -s otcl-1.13 otcl;


# Compile tclcl-1.19
print_info tclcl-1.19
cd tclcl-1.19;
make clean;
./configure;
make $MAKE_FLAGS;
check_result tctcl-1.19
cd ..;
rm tclcl;
ln -s tclcl-1.19 tclcl;



# Now compile P2
print_info P2
cd P2;
./setup;
make clean;
rm config.cache;
./configure;
make $MAKE_FLAGS;
check_result P2
sh create_lib.sh;
cd ..;



# Now we can compile ns2
print_info ns2 
cd ns;
make clean;
./configure;
make $MAKE_FLAGS;
check_result ns2 


