dnl	This file is an input file used by the GNU "autoconf" program to
dnl	generate the file "configure", which is run during Tk installation
dnl	to configure the system for the local environment.
AC_INIT(tk.h)
AC_PROG_INSTALL
AC_PROG_RANLIB
CC=${CC-cc}
AC_SUBST(CC)
AC_UNISTD_H

#--------------------------------------------------------------------
#	Include sys/select.h if it exists and if it supplies things
#	that appear to be useful and aren't already in sys/types.h.
#	This appears to be true only on the RS/6000 under AIX.  Some
#	systems like OSF/1 have a sys/select.h that's of no use, and
#	other systems like SCO UNIX have a sys/select.h that's
#	pernicious.  If "fd_set" isn't defined anywhere then set a
#	special flag.
#--------------------------------------------------------------------

echo checking for sys/select.h
AC_COMPILE_CHECK(fd_set, [#include <sys/types.h>],
	[fd_set readMask, writeMask;], ,
	AC_HEADER_EGREP(fd_mask, sys/select.h, AC_DEFINE(HAVE_SYS_SELECT_H),
		AC_DEFINE(NO_FD_SET)))

#--------------------------------------------------------------------
#	Supply a substitute for stdlib.h if it doesn't define strtol,
#	strtoul, or strtod (which it doesn't in some versions of SunOS).
#--------------------------------------------------------------------

echo checking for proper stdlib.h
AC_HEADER_EGREP(strtol, stdlib.h, tk_stdlib=1, tk_stdlib=0)
AC_HEADER_EGREP(strtoul, stdlib.h, , tk_stdlib=0)
AC_HEADER_EGREP(strtod, stdlib.h, , tk_stdlib=0)
if test $tk_stdlib = 0; then
    AC_DEFINE(NO_STDLIB_H)
fi

#--------------------------------------------------------------------
#	Check for various typedefs and provide substitutes if
#	they don't exist.
#--------------------------------------------------------------------

AC_MODE_T
AC_PID_T
AC_SIZE_T
AC_UID_T

#--------------------------------------------------------------------
#	Locate the X11 header files and the X11 library archive.  Try
#	the ac_find_x macro first, but if it doesn't find the X stuff
#	(e.g. because there's no xmkmf program) then check through
#	a list of possible directories.
#--------------------------------------------------------------------

AC_PROGRAM_CHECK(tk_ok, xmkmf, 1, 0)
if test $tk_ok = 1; then
    AC_FIND_X
fi
if test "$XINCLUDE_DIR" != ""; then
    x_includes="$XINCLUDE_DIR"
fi
if test "$x_includes" = /usr/include; then
    XINCLUDES="# no special path needed"
elif test "$x_includes" != ""; then
    XINCLUDES=" -I$x_includes"
else
    echo checking for X11 header files
    XINCLUDES="# no special path needed"
    AC_TEST_CPP([#include <X11/Intrinsic.h>], , XINCLUDES="nope")
    if test "$XINCLUDES" = nope; then
        dirs="/usr/unsupported/include /usr/local/include /usr/X386/include /usr/include/X11R4 /usr/X11R5/include /usr/include/X11R5 /usr/openwin/include /usr/X11/include"
        for i in $dirs ; do
	    if test -r $i/X11/Intrinsic.h; then
	        XINCLUDES=" -I$i"
	    fi
        done
    fi
fi
if test "$XINCLUDES" = nope; then
  echo "Warning:  couldn't find any X11 include files."
  XINCLUDES="# no include files found"
fi
AC_SUBST(XINCLUDES)

if test "$XLIBRARY_DIR" != ""; then
    x_libraries="$XLIBRARY_DIR"
fi
if test "$x_libraries" = /usr/lib; then
    XLIBSW=-lX11
elif test "$x_libraries" != ""; then
    XLIBSW="-L$x_libraries -lX11"
else
    echo "checking for X11 library archive"
    AC_HAVE_LIBRARY(X11, XLIBSW="-lX11", XLIBSW=nope)
    if test "$XLIBSW" = nope; then
	dirs="/usr/unsupported/lib /usr/local/lib /usr/X386/lib /usr/lib/X11R4 /usr/X11R5/lib /usr/lib/X11R5 /usr/openwin/lib /usr/X11/lib"
	for i in $dirs ; do
	    if test -r $i/libX11.a; then
		XLIBSW="-L$i -lX11"
	    fi
	done
    fi
fi
if test "$XLIBSW" = nope ; then
    AC_HAVE_LIBRARY(Xwindow, XLIBSW=-lXwindow)
fi
if test "$XLIBSW" = nope ; then
    echo "Warning:  couldn't find the X11 library archive.  Using -lX11."
    XLIBSW=-lX11
fi
AC_SUBST(XLIBSW)

#--------------------------------------------------------------------
#	Check for the existence of various libraries.  The order here
#	is important, so that then end up in the right order in the
#	command line generated by Make.
#--------------------------------------------------------------------

AC_HAVE_LIBRARY(Xbsd, [LIBS="$LIBS -lXbsd"])
AC_HAVE_LIBRARY(socket, [LIBS="$LIBS -lsocket"])
AC_HAVE_LIBRARY(nsl, [LIBS="$LIBS -lnsl"])

AC_OUTPUT(Makefile)
