dist=`perl ../../../loncom/build/distprobe`
arch=`uname -i`
if test ! -f ../tthdynamic/tthfunc.c
then
	if test -f compiles/tth.so.$arch.$dist
	then 
       		cp compiles/tth.so.$arch.$dist tth.so
		exit 0
	fi
	if test -f compiles/tth.so.$arch
	then 
        	cp compiles/tth.so.$arch tth.so
		exit 0
	fi
fi

if test -f /etc/redhat-release
then
	if rpm -q swig
	then
		echo "Swig found.  Assuming it works..."
	else
		echo "ERROR ERROR: Swig must exist but doesn't!!!"
		echo "To get swig, go to"
		echo "http://install.lon-capa.org/3.1/latestRPMS"
		echo "Install this RPM, swig-1.1p5-3.i386.rpm"
		exit 1
	fi
	if test -e /usr/include/asm
	then
		echo ""
	else
		echo "ERROR. You are missing a necessary symbolic link."
		echo "You should type, as superuser, a command like this:"
                echo "   ln -s /usr/src/linux/include/asm /usr/include/asm"
		exit 1
	fi
	if test -e /usr/include/linux
	then
		echo ""
	else
		echo "ERROR. You are missing a necessary symbolic link."
		echo "You should type, as superuser, a command like this:"
                echo "   ln -s /usr/src/linux/include/linux /usr/include/linux"
		exit 1
	fi
fi
make -f Makefile clean
cp ../tthdynamic/tthfunc.c .
cp ../ttmdynamic/ttmfunc.c .
swig -perl5 -noproxy tthfunc.i
dist=`perl ../../../loncom/build/distprobe`
if [[ $dist == "redhat8"  || $dist = "redhat9" ]];
then
        cat tthfunc_wrap.c | perl -pe '$_=~s-SWIGEXPORT\(void,boot_tth\)\(CV\* cv\)\;-SWIGEXPORT\(void,boot_tth\)\(pTHX_ CV\* cv\)\;-;' > tthfunc_wrap.c.new
        mv tthfunc_wrap.c.new tthfunc_wrap.c
fi
perl Makefile.PL
make -f Makefile 
cp blib/arch/auto/tth/tth.so . 
perl tth.pm
