#!/bin/sh
#
# $Id: post-configure,v 1.5 1995/02/13 04:57:22 asami Exp $
#
# Find tcl.h and libtcl.so.7.3 and put that directory in Makefile
#

tcl_include_dir=""

for d in /usr/local/include /usr/X11R6/include /usr/X11R6/include/X11 \
	/usr/include /usr/include/X11; do
	if [ -f "$d/tcl.h" ]; then
		tcl_include_dir=$d
		break
	fi
done

if [ "$tcl_include_dir" = "" ]; then
	echo "error: tcl.h not found, can't continue"
	exit 1
else
	echo "tcl.h found in $tcl_include_dir"
fi

# Since LIB_DEPENDS is already checked in the Makefile, it should be
# there....otherwise, it's probably just built and ldconfig hasn't
# been run yet so we have to go look for it.

tmp=`ldconfig -r | grep -e '-ltcl\.7\.' | awk '{print $3}'`
tcl_lib_dir=""

# Should we do something like this to see where the user might have
# put local stuff?
# ldconfig -r | awk '{print $3}' | sed -e 's./[^/]*$..' | sort | uniq

if [ "$tmp" = "" ]; then
	for d in /usr/local/lib /usr/X11R6/lib /usr/lib; do
		if [ -f "$d/libtcl.a" ]; then
			tcl_lib_dir=$d
			break
		fi
	done
else
	tcl_lib_dir=`dirname $tmp`
fi

if [ "$tcl_lib_dir" = "" ]; then
	echo "error: tcl library not found, can't continue"
	exit 1
else
	echo "tcl library found in $tcl_lib_dir"
fi

sed	-e "s;@tcl_include_dir@;$tcl_include_dir;" \
	-e "s;@tcl_bin_dir@;$tcl_lib_dir;" \
	< $WRKSRC/Makefile > $WRKSRC/Makefile.bak && \
	mv $WRKSRC/Makefile.bak $WRKSRC/Makefile
