dnl Process this file with autoconf to produce a configure script.
AC_INIT(libdesk/dsk_ls.c)

AC_ARG_WITH(tcl, [  --with-tcl=DIR          read Tcl configuration from DIR],
	TCLCONF_PATH=$withval)
AC_ARG_WITH(tk, [  --with-tk=DIR           read Tk configuration from DIR],
	TKCONF_PATH=$withval)
	
# -----------------------------------------------------------------------
#
# Read tclConfig.sh and tkConfig4.1.sh:
#
# -----------------------------------------------------------------------
AC_MSG_CHECKING(for tclConfig7.5.sh)
if test -z "$TCLCONF_PATH" ; then
  TCLCONF_PATH="$HOME/lib /usr/local/lib /usr/lib /usr/X11/lib /usr/share/lib /usr/local/lib/tcl7.6"
fi
success=0
for d in $TCLCONF_PATH; do
  if test -r $d/tclConfig7.5.sh ; then
    TCLCONF_PATH=$d
    success=1
    break
  fi
done
if test $success = 1 ; then
  AC_MSG_RESULT($TCLCONF_PATH)
else
  AC_MSG_RESULT(not found)
  echo
  echo [Couldn\'t find tclConfig7.5.sh.]
  echo [Please restart configure with the argument --with-tcl=dir, where dir is]
  echo [the path of tclConfig7.5.sh.]
  echo [If you cannot locate this file, maybe Tcl/Tk needs to be installed first.]
  echo [Note that TkDesk 1.0b5 requires either Tcl/Tk 7.5/4.1 or 7.6/4.2.]
  exit 1
fi

AC_MSG_CHECKING(for tkConfig4.1.sh)
if test -z "$TKCONF_PATH" ; then
  TKCONF_PATH="$TCLCONF_PATH $HOME/lib /usr/local/lib /usr/lib /usr/X11/lib /usr/share/lib /usr/local/lib/tk4.2"
fi
success=0
for d in $TKCONF_PATH; do
  if test -r $d/tkConfig4.1.sh ; then
    TKCONF_PATH=$d
    success=1
    break
  fi
done
if test $success = 1 ; then
  AC_MSG_RESULT($TKCONF_PATH)
else
  AC_MSG_RESULT(not found)
  echo
  echo [Couldn\'t find tkConfig4.1.sh.]
  echo [Please restart configure with the argument --with-tk=dir, where dir is]
  echo [the path of tkConfig4.1.sh.]
  echo [If you cannot locate this file, maybe Tcl/Tk needs to be installed first.]
  echo [Note that TkDesk 1.0b5 requires either Tcl/Tk 7.5/4.1 or 7.6/4.2.]
  exit 1
fi

. $TCLCONF_PATH/tclConfig7.5.sh
. $TKCONF_PATH/tkConfig4.1.sh

# -----------------------------------------------------------------------
#
# Check version of installed Tcl/Tk libraries:
#
# -----------------------------------------------------------------------
AC_MSG_CHECKING(version of Tcl/Tk)
AC_MSG_RESULT($TCL_VERSION/$TK_VERSION)
if test "$TCL_VERSION" != "7.5" -a "$TCL_VERSION" != "7.6"; then
  echo
  echo [TkDesk requires Tcl/Tk versions 7.5/4.1 or 7.6/4.2.]
  echo [Older versions are unlikely to work, while newer ones are not]
  echo [yet supported \(but hopefully will be soon\).]
  exit 1
fi
if test "$TK_VERSION" != "4.1" -a "$TK_VERSION" != "4.2"; then
  echo
  echo [TkDesk requires Tcl/Tk versions 7.5/4.1 or 7.6/4.2.]
  echo [Older versions are unlikely to work, while newer ones are not]
  echo [yet supported \(but hopefully will be soon\).]
  exit 1
fi

# -----------------------------------------------------------------------
#
# Check for itcl 2.x
#
# -----------------------------------------------------------------------
AC_MSG_CHECKING(for itcl 2.x)
if test -r $TCLCONF_PATH/itclConfig7.5.sh ; then
  . $TCLCONF_PATH/itclConfig7.5.sh
else
  ITCL_VERSION="no"
fi
AC_MSG_RESULT($ITCL_VERSION)

# -----------------------------------------------------------------------
#
# Determine include directories
#
# -----------------------------------------------------------------------
if test "$ITCL_VERSION" != "no" ; then
  TCL_INCLUDE_PATH=$TCL_EXEC_PREFIX/include/itcl
  TK_INCLUDE_PATH=$TCL_INCLUDE_PATH
  NEED_ITCL_LIB=
  # ITCL_LIB_SPEC already set in itclConfig7.5.sh
  ITCL_LIB_STATIC=${TCLCONF_PATH}/libitcl${ITCL_VERSION}.a
else
  TCL_INCLUDE_PATH=$TCL_EXEC_PREFIX/include
  TK_INCLUDE_PATH=$TK_EXEC_PREFIX/include
  NEED_ITCL_LIB=lib_itcl
  ITCL_LIB_SPEC=itcl/libitcl.a
  ITCL_LIB_STATIC=itcl/libitcl.a
fi

# -----------------------------------------------------------------------
#
# Perform substitutions
#
# -----------------------------------------------------------------------
AC_SUBST(TCL_LD_SEARCH_FLAGS)
AC_SUBST(TCL_EXEC_PREFIX)
AC_SUBST(TK_EXEC_PREFIX)
AC_SUBST(TCL_INCLUDE_PATH)
AC_SUBST(TK_INCLUDE_PATH)
AC_SUBST(TK_XINCLUDES)
AC_SUBST(TCL_LIB_SPEC)
AC_SUBST(TK_LIB_SPEC)
AC_SUBST(TK_LIBS)

TCL_LIB_STATIC=${TCLCONF_PATH}/libtcl${TCL_VERSION}.a
TK_LIB_STATIC=${TKCONF_PATH}/libtk${TK_VERSION}.a
AC_SUBST(TCL_LIB_STATIC)
AC_SUBST(TK_LIB_STATIC)

AC_SUBST(NEED_ITCL_LIB)
AC_SUBST(ITCL_LIB_SPEC)
AC_SUBST(ITCL_LIB_STATIC)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB

dnl Checks for header files.
AC_PATH_X
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(errno.h fcntl.h float.h limits.h malloc.h memory.h sys/time.h statvfs.h sys/statvfs.h unistd.h waitflags.h sys/vfs.h sys/param.h sys/mount.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_MODE_T
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_HEADER_TIME
AC_STRUCT_TM

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(gethostname gettimeofday socket strdup strcasecmp statvfs statfs)
AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl", , -lnsl)
AC_SUBST(LIBS)

# -----------------------------------------------------------------------
#
# Custom Tests:	union wait and long string declaration
#
# -----------------------------------------------------------------------


# -----------------------------------------------------------------------
#
#	Check whether <sys/wait.h> defines the type "union wait" 
#	correctly.  It's needed because of weirdness in HP-UX where 
#	"union wait" is defined in both the BSD and SYS-V  environments.  
#	Checking the usability of WIFEXITED seems to do	the trick.
#
# -----------------------------------------------------------------------

AC_MSG_CHECKING([whether union wait is defined correctly])
AC_CACHE_VAL(blt_cv_struct_wait_works,
    AC_TRY_COMPILE([#include <sys/types.h> 
#include <sys/wait.h>], [
union wait x;
WIFEXITED(x);		/* Generates compiler error if WIFEXITED
			 * uses an int. */
], 
    	[blt_cv_struct_wait_works="yes"], 
	[blt_cv_struct_wait_works="no"]))

if test "${blt_cv_struct_wait_works}" = "no"; then
    AC_DEFINE(NO_UNION_WAIT)
fi
AC_MSG_RESULT([$blt_cv_struct_wait_works])

AC_CONFIG_HEADER(config.h)
AC_OUTPUT(Makefile libdesk/Makefile itcl/Makefile blt/Makefile netscape-remote/Makefile tkdeskclient/Makefile)
