dnl autoconf rules to find tcl & tk 
dnl $Header: configure.in.tk,v 1.2 96/05/16 01:03:40 van Exp $ (LBL)

AC_ARG_WITH(tcl,	--with-tcl=path	specify a pathname for tcl, d=$withval, d="")
tcldir=tcl8.6
tcllib=tcl86
if test "$d" != "" ; then 
	if test ! -d $d ; then 
		echo "'$d' is not a directory"
		exit 1
	fi
	V_INCLUDE_TCL=-I$d/include
	if test ! -r $d/include/tcl.h ; then
		echo "can't find tcl.h in $d/include"
		exit 1
	fi
	places="$d/lib/lib${tcllib}.so \
		$d/lib/lib${tcllib}.a \
		$d/lib/libtcl.so \
		$d/lib/libtcl.a"
	V_LIB_TCL=FAIL
	for dir in $places; do
		if test -r $dir ; then
			V_LIB_TCL=$dir
			break
		fi
	done
	if test $V_LIB_TCL = FAIL ; then
		echo "can't find libtcl.a in $d/lib"
		exit 1
	fi
	places="$d/lib/${tcldir} \
		$d/lib/tcl"
	V_LIBRARY_TCL=FAIL
	for dir in $places; do
		if test -r $dir/init.tcl ; then
			V_LIBRARY_TCL=$dir
			break
		fi
	done
	if test $V_LIBRARY_TCL = FAIL ; then
		echo "can't find init.tcl in $d/lib/tcl"
		exit 1
	fi
else
	AC_TEST_CPP([#include <tcl.h>], V_INCLUDE_TCL="", V_INCLUDE_TCL=FAIL)
	if test "$V_INCLUDE_TCL" = FAIL; then
		echo "checking for tcl.h"
		places="$PWD/../${tcldir} \
			/usr/src/local/${tcldir} \
			/import/tcl/include/${tcldir} \
			$prefix/include \
			$prefix/include/${tcldir} \
			$x_includes/tk \
			$x_includes \
			/usr/local/include \
			/usr/contrib/include \
			/usr/include"
		for dir in $places; do
			if test -r $dir/tcl.h ; then
				V_INCLUDE_TCL=-I$dir
			        break
			fi
		done
		if test "$V_INCLUDE_TCL" = FAIL; then
			echo "can't find tcl.h"
			exit 1
		fi
	fi
	V_TCL_CONFIG=FAIL
	echo "checking for tclConfig.sh"
	places="/usr/local/lib/${tcldir} \
		/usr/contrib/lib/${tcldir} \
		/usr/lib/${tcldir} \
		/usr/lib/tk/${tcldir} \
		/import/tcl/lib/${tcldir} \
		$prefix/lib/${tcldir} \
		$x_libraries/${tcldir} \
		/usr/local/lib/tcl \
		/usr/lib/tcl \
		/usr/lib/tk/tcl \
		/import/tcl/lib/tcl \
		$prefix/lib/tcl \
		$x_libraries/tcl \
		$x_libraries/tcl"
	for dir in $places; do
		if test -r $dir/tclConfig.sh ; then
			V_TCL_CONFIG=$dir/tclConfig.sh
		        break
		fi
	done
	if test "$V_TCL_CONFIG" = FAIL; then
		echo "can't find tclConfig.sh"
		exit 1
	fi
	. ${V_TCL_CONFIG}
	V_LIB_TCL="${TCL_LIB_FLAG}"
	echo "checking for tcl/init.tcl"
	V_LIBRARY_TCL=FAIL
	places="/usr/local/lib/${tcldir} \
		/usr/contrib/lib/${tcldir} \
		/usr/lib/${tcldir} \
		/usr/lib/tk/${tcldir} \
		/import/tcl/lib/${tcldir} \
		$prefix/lib/${tcldir} \
		$x_libraries/${tcldir} \
		/usr/local/lib/tcl \
		/usr/lib/tcl \
		/usr/lib/tk/tcl \
		/import/tcl/lib/tcl \
		$prefix/lib/tcl \
		$x_libraries/tcl \
		$x_libraries/tcl"
	for dir in $places; do
		if test -r $dir/init.tcl; then
			V_LIBRARY_TCL=$dir
			break
		fi
	done
	if test "$V_LIBRARY_TCL" = FAIL; then
		echo "can't find tcl/init.tcl"
		exit 1
	fi
fi
AC_SUBST(V_INCLUDE_TCL)
AC_SUBST(V_LIB_TCL)
AC_SUBST(V_LIBRARY_TCL)

AC_ARG_WITH(tk,	--with-tk=path	specify a pathname for tk, d=$withval, d="")
tkdir=tk8.6
tklib=tk86
if test "$d" != "" ; then 
	if test ! -d $d ; then 
		echo "'$d' is not a directory"
		exit 1
	fi
	V_INCLUDE_TK=-I$d/include
	if test ! -r $d/include/tk.h ; then
		echo "can't find tk.h in $d/include"
		exit 1
	fi
	places="$d/lib/lib${tklib}.so \
		$d/lib/lib${tklib}.a \
		$d/lib/libtk.so \
		$d/lib/libtk.a"
	V_LIB_TK=FAIL
	for dir in $places; do
		if test -r $dir ; then
			V_LIB_TK=$dir
			break
		fi
	done
	if test $V_LIB_TK = FAIL ; then
		echo "can't find libtk.a in $d/lib"
		exit 1
	fi
	places="$d/lib/${tkdir} \
		$d/lib/tk"
	V_LIBRARY_TK=FAIL
	for dir in $places; do
		if test -r $dir/tk.tcl ; then
			V_LIBRARY_TK=$dir
			break
		fi
	done
	if test $V_LIBRARY_TK = FAIL ; then
		echo "can't find tk.tcl in $d/lib/tk"
		exit 1
	fi
else
	AC_TEST_CPP([#include <tk.h>], V_INCLUDE_TK="", V_INCLUDE_TK=FAIL)
	if test "$V_INCLUDE_TK" = FAIL; then
		echo "checking for tk.h"
		V_INCLUDE_TK=""
		places="\
			$prefix/include \
			$prefix/include/${tkdir} \
			/usr/local/include \
			/usr/contrib/include \
			/usr/include/tcl \
			/usr/include\
			$x_includes/tk \
			$x_includes \
			$PWD/../${tkdir} \
			/usr/src/local/${tkdir} \
			/import/tcl/include/${tkdir} \
			"
		for dir in $places; do
			if test -r $dir/tk.h ; then
				V_INCLUDE_TK=-I$dir
				break
			fi
		done
		if test "$V_INCLUDE_TK" = FAIL; then
			echo "can't find tk.h"
			exit 1
		fi
	fi
	V_TK_CONFIG=FAIL
	echo "checking for tkConfig.sh"
	places="/usr/local/lib/${tkdir} \
		/usr/contrib/lib/${tkdir} \
		/usr/lib/${tkdir} \
		/usr/lib/tk/${tkdir} \
		/import/tcl/lib/${tkdir} \
		$prefix/lib/${tkdir} \
		$x_libraries/${tkdir} \
		$PWD/../${tkdir}/library \
		/usr/src/local/${tkdir}/library \
		/usr/local/lib/tk \
		/usr/lib/tk \
		/usr/lib/tk/tk \
		/import/tcl/lib/tk \
		$prefix/lib/tk \
		$x_libraries/tk \
		$x_libraries/tk"
	for dir in $places; do
		if test -r $dir/tkConfig.sh ; then
			V_TK_CONFIG=$dir/tkConfig.sh
		        break
		fi
	done
	if test "$V_TK_CONFIG" = FAIL; then
		echo "can't find tkConfig.sh"
		exit 1
	fi
	. ${V_TK_CONFIG}
	V_LIB_TK="${TK_LIB_FLAG}"
	echo "checking for tk/tk.tcl"
	V_LIBRARY_TK=FAIL
	places="/usr/local/lib/${tkdir} \
		/usr/contrib/lib/${tkdir} \
		/usr/lib/${tkdir} \
		/usr/lib/tk/${tkdir} \
		/import/tcl/lib/${tkdir} \
		$prefix/lib/${tkdir} \
		$x_libraries/${tkdir} \
		$PWD/../${tkdir}/library \
		/usr/src/local/${tkdir}/library \
		/usr/local/lib/tk \
		/usr/lib/tk \
		/usr/lib/tk/tk \
		/import/tcl/lib/tk \
		$prefix/lib/tk \
		$x_libraries/tk \
		$x_libraries/tk"
	for dir in $places; do
		if test -r $dir/tk.tcl; then
			V_LIBRARY_TK=$dir
			break
		fi
	done
	if test "$V_LIBRARY_TK" = FAIL; then
		echo "can't find tk/tk.tcl"
		exit 1
	fi
fi
if test -r $V_LIBRARY_TK/optionMenu.tcl ; then
	V_TKDOSNAMES='$(LIBRARY_TK)/optionMenu.tcl $(LIBRARY_TK)/scrollbar.tcl'
	V_NEED_DL=""
else
	V_TKDOSNAMES='$(LIBRARY_TK)/optMenu.tcl $(LIBRARY_TK)/scrlbar.tcl'
	V_NEED_DL=YES
fi
AC_SUBST(V_TKDOSNAMES)
AC_SUBST(V_INCLUDE_TK)
AC_SUBST(V_LIB_TK)
AC_SUBST(V_LIBRARY_TK)
