dnl----------------------------------------------------------------------------
dnl configure.in -
dnl----------------------------------------------------------------------------
dnl  This file is an input file used by the GNU "autoconf" program to
dnl  generate the file "configure", which is run during Tcl installation
dnl  to configure the system for the local environment.  Many of these
dnl  checks are duplicates of those required by Tcl & Tk, since TclX
dnl  includes there internal header files.  The sections from Tcl and Tk
dnl  are grouped together and marked for easy sycning with Outerhout's
dnl  releases.
dnl
dnl  Although the generated configure script is under the GNU Public
dnl  License, Extended Tcl remains freely redistributable for any purpose,
dnl  including commercial use.
dnl----------------------------------------------------------------------------
dnl $Id: configure.in,v 8.33.4.1 2002/11/02 02:48:14 karll Exp $
dnl----------------------------------------------------------------------------
AC_INIT(../tcl/generic/tclExtend.h)
ifdef([AC_REVISION],AC_REVISION($Revision: 8.33.4.1 $),)dnl

#------------------------------------------------------------------------------
# Define srcbasedir and bldbasedir as absolute paths to the top of the TclX
# tree.
#------------------------------------------------------------------------------

srcbasedir=`cd $srcdir/..; pwd|sed -e 's,/tmp_mnt,,'`
AC_SUBST(srcbasedir)
bldbasedir=`cd ..; pwd | sed -e 's,/tmp_mnt,,'`
AC_SUBST(bldbasedir)

#------------------------------------------------------------------------------
# System information and date for including in some files.
#------------------------------------------------------------------------------
if test -f /usr/lib/NextStep/software_version; then
    UNAME_OUT=NEXTSTEP-`awk '/3/,/3/' /usr/lib/NextStep/software_version`
else
    UNAME_OUT=`uname -s`-`uname -r`
fi
AC_SUBST(UNAME_OUT)

DATE_OUT=`date`
AC_SUBST(DATE_OUT)

#------------------------------------------------------------------------------
# If the --srcdir option has been used, make sure we are in a directory called
# "unix" and build the other output directories, configure will not do this.
#------------------------------------------------------------------------------

case `pwd` in
  */unix) ;;
  *) echo '*** Error: Should be in a directory named "unix".  If you are using'
     echo 'the --srcdir option, create a directory called "unix" and run'
     echo 'configure from there.  Other build directories will be created'
     echo 'under the parent directory of "unix".'
     exit 1 ;;
esac
if test ! -d ../tcl ; then
   mkdir ../tcl || exit 1
fi
if test ! -d ../tcl/unix ; then
   mkdir ../tcl/unix || exit 1
fi
if test ! -d ../tk ; then
   mkdir ../tk || exit 1
fi
if test ! -d ../tk/unix ; then
   mkdir ../tk/unix || exit 1
fi

#------------------------------------------------------------------------------
# Check command line looking for the --enable-tk=YES/NO option.
#------------------------------------------------------------------------------

AC_ARG_ENABLE(tk,
    [  --enable-tk=YES|NO         build Tk specific code and wishx],
    [TKX_BUILD=$enableval],
    [TKX_BUILD=YES])

case "$TKX_BUILD" in
    YES|yes)
        AC_MSG_RESULT(Will build Tk specific code and wishx)
        TKX_BUILD=YES
        ;;
    NO|no)
        AC_MSG_RESULT(Will not build Tk specific code and wishx)
        TKX_BUILD=NO
        ;;
     *)
        AC_MSG_ERROR(Invalid argument to --enable-tk=, expected YES or NO)
        ;;
esac
AC_SUBST(TKX_BUILD)

#------------------------------------------------------------------------------
# Check for the --enable-shared option.
#------------------------------------------------------------------------------

SC_ENABLE_SHARED
AC_SUBST(SHARED_BUILD)

#------------------------------------------------------------------------------
# We need the real value of prefix and exec-prefix now, not when the generated
# script is ready to output them.
#------------------------------------------------------------------------------

test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix=$prefix

AC_SUBST(prefix)
AC_SUBST(exec_prefix)

#------------------------------------------------------------------------------
# Extract the version information out of tclExtend.h.
#------------------------------------------------------------------------------

AC_MSG_CHECKING(TclX versions)

eval `egrep '^#define T.*_VERSION' $srcbasedir/tcl/generic/tclExtend.h | \
      sed -e 's/#define //' -e 's/ *"/="/'`
AC_MSG_RESULT($TCLX_FULL_VERSION)

AC_SUBST(TCLX_VERSION)
AC_SUBST(TCLX_FULL_VERSION)

AC_SUBST(TKX_VERSION)
AC_SUBST(TKX_FULL_VERSION)

#------------------------------------------------------------------------------
# Get location of Tcl source directory and configuration information from
# tclConfig.sh.
#------------------------------------------------------------------------------

SC_PATH_TCLCONFIG
SC_LOAD_TCLCONFIG

LIBS=$TCL_LIBS   # Need for configure tests.

AC_SUBST(TCL_VERSION)
AC_SUBST(TCL_DEFS)
AC_SUBST(TCL_LIBS)
AC_SUBST(TCL_EXEC_PREFIX)
TCL_SHLIB_CFLAGS=`echo "$TCL_SHLIB_CFLAGS" |sed -e "s|-fPIC|-fpic|" -e "s|-PIC|-pic|" -e "s|-K PIC|-K pic|" -e "s|-KPIC|-Kpic|" -e "s|+Z|+z|"`
AC_SUBST(TCL_SHLIB_CFLAGS)
AC_SUBST(TCL_SHLIB_LD)
AC_SUBST(TCL_SHLIB_LD_LIBS)
AC_SUBST(TCL_DL_LIBS)
AC_SUBST(TCL_LD_FLAGS)
AC_SUBST(TCL_LD_SEARCH_FLAGS)
AC_SUBST(TCL_EXTRA_CFLAGS)
AC_SUBST(TCL_CFLAGS_WARNING)
AC_SUBST(TCL_BUILD_LIB_SPEC)
AC_SUBST(TCL_LIB_SPEC)
AC_SUBST(TCL_BUILD_STUB_LIB_SPEC)
AC_SUBST(TCL_STUB_LIB_SPEC)

# These are substituted into the run scripts
TCL_LIB_DIR="${TCL_BIN_DIR}"
TCL_LIBRARY_DIR="${TCL_SRC_DIR}/library"
AC_SUBST(TCL_LIB_DIR)
AC_SUBST(TCL_LIBRARY_DIR)

#------------------------------------------------------------------------------
# Get location of Tk source directory and configuration information from
# tkConfig.sh.
#------------------------------------------------------------------------------

if test "$TKX_BUILD" = "YES"; then
    SC_PATH_TKCONFIG
    SC_LOAD_TKCONFIG
fi

AC_SUBST(TK_VERSION)
AC_SUBST(TK_DEFS)
AC_SUBST(TK_LIBS)
AC_SUBST(TK_EXEC_PREFIX)
AC_SUBST(TK_XINCLUDES)
AC_SUBST(TK_XLIBSW)
AC_SUBST(TK_LD_SEARCH_FLAGS)
AC_SUBST(TK_BUILD_LIB_SPEC)
AC_SUBST(TK_LIB_SPEC)
AC_SUBST(TK_BUILD_STUB_LIB_SPEC)
AC_SUBST(TK_STUB_LIB_SPEC)

# These are substituted into the run scripts
TK_LIB_DIR="${TK_BIN_DIR}"
TK_LIBRARY_DIR="${TK_SRC_DIR}/library"
AC_SUBST(TK_LIB_DIR)
AC_SUBST(TK_LIBRARY_DIR)

#------------------------------------------------------------------------------
# The TclX and TkX runtime directories.  This is where the shared runtime and
# help files are installed.
#------------------------------------------------------------------------------
AC_SUBST(TCLX_INST_LIB)
AC_SUBST(TKX_INST_LIB)

#------------------------------------------------------------------------------
# Check for various programs used during the build.  If the CC environment
# variable is not set, the compiler used to build Tcl is used.
#------------------------------------------------------------------------------

SC_ENABLE_GCC
AC_PROG_CC

#------------------------------------------------------------------------------
# If we're using GCC, see if the compiler understands -pipe.  If so, use it.
# It makes compiling go faster.
#------------------------------------------------------------------------------

if test -z "$no_pipe"; then
if test -n "$GCC"; then
  AC_MSG_CHECKING([if the compiler understands -pipe])
  OLDCC="$CC"  
  CC="$CC -pipe"
  AC_TRY_COMPILE(,,
    AC_MSG_RESULT(yes),
    CC="$OLDCC"
    AC_MSG_RESULT(no))
fi  
fi

#------------------------------------------------------------------------------
# If we're using GCC, we want to see all the compiler warnings.
#------------------------------------------------------------------------------

if test -n "$GCC"; then 
    AC_MSG_CHECKING([if the compiler understands -Wall])
    OLDCC="$CC"
    CC="$CC -Wall"
  AC_TRY_COMPILE(,,
    AC_MSG_RESULT(yes),
    CC="$OLDCC"
    AC_MSG_RESULT(no))
fi  

AC_SUBST(CC)
AC_SUBST(SYSCFLAGS)
AC_PROG_RANLIB

#------------------------------------------------------------------------------
# Test if we are to include debugging symbols in the binary targets
#------------------------------------------------------------------------------

SC_CONFIG_CFLAGS
SC_ENABLE_SYMBOLS

CFLAGS="${CFLAGS_DEFAULT}"
TCLX_DBGX=${DBGX}
TKX_DBGX=${DBGX}

AC_SUBST(TCLX_DBGX)
AC_SUBST(TKX_DBGX)


#------------------------------------------------------------------------------
# Set this back to ${TCL_DBGX} because the UNSHARED_LIB_SUFFIX references
# below refer to DBGX, not TCL_DBGX
#------------------------------------------------------------------------------

DBGX=${TCL_DBGX}

#------------------------------------------------------------------------------
# The tclX shell still needs to know this value so that it can construct
# the correct library name for libtcl.
#------------------------------------------------------------------------------

AC_SUBST(TCL_DBGX)
AC_SUBST(TK_DBGX)

#------------------------------------------------------------------------------
# Determine the names of the TclX libraries and the link specifications and
# other shared library stuff.
#------------------------------------------------------------------------------

#
# Generate the library names using the Tcl macros.
#
SHLIB_SUFFIX=${TCL_SHLIB_SUFFIX}

VERSION=$TCL_VERSION
eval "TCL_STLIB_NAME=libtcl${TCL_UNSHARED_LIB_SUFFIX}"

VERSION=$TK_VERSION
eval "TK_STLIB_NAME=libtk${TCL_UNSHARED_LIB_SUFFIX}"

DBGX=${TCLX_DBGX}
VERSION=$TCLX_VERSION
eval "TCLX_STLIB_NAME=libtclx${UNSHARED_LIB_SUFFIX}"
eval "TCLX_SHLIB_NAME=libtclx${SHARED_LIB_SUFFIX}"
eval "TCLX_SHLIB_NAME=${TCLX_SHLIB_NAME}"

DBGX=${TKX_DBGX}
VERSION=$TKX_VERSION
eval "TKX_STLIB_NAME=libtkx${UNSHARED_LIB_SUFFIX}"
eval "TKX_SHLIB_NAME=libtkx${SHARED_LIB_SUFFIX}"
eval "TKX_SHLIB_NAME=${TKX_SHLIB_NAME}"

#
# Determine suffix to use for the object files for the shared library.
#
if test "x${TCL_SHLIB_CFLAGS}" != "x"; then
    SHOBJ_SUFFIX="..o"
else
    SHOBJ_SUFFIX=".o"
fi

#
# Determine the arguments for specifying the prefered TclX libraries on the
# link lines.
# A few system (AIX) have the same extension of shared and static libraries,
# so shlib target must not be defined if not being build.
#
case "$SHARED_BUILD" in
    1)
        TCLX_LIB_FLAG="-ltclx${TCLX_VERSION}${TCLX_DBGX}"
        TKX_LIB_FLAG="-ltkx${TKX_VERSION}${TCLX_DBGX}"
        if test "X${TCL_LIB_VERSIONS_OK}" = "Xnodots" ; then
            TCLX_LIB_FLAG=`echo ${TCLX_LIB_FLAG} | tr -d .`
            TKX_LIB_FLAG=`echo ${TKX_LIB_FLAG} | tr -d .`
        fi
        TCLX_BUILD_LIB_SPEC="-L$bldbasedir/tcl/unix ${TCLX_LIB_FLAG}"
        TCLX_LIB_SPEC="-L$TCLX_INST_LIB ${TCLX_LIB_FLAG}"
        TKX_BUILD_LIB_SPEC="-L$bldbasedir/tk/unix ${TKX_LIB_FLAG}"
        TKX_LIB_SPEC="-L$TCLX_INST_LIB ${TKX_LIB_FLAG}"
        TCLX_STLIB_BUILD_REF=${TCLX_STLIB_NAME}
        TKX_STLIB_BUILD_REF=${TKX_STLIB_NAME}
        TCLX_SHLIB_BUILD_REF=${TCLX_SHLIB_NAME}
        TKX_SHLIB_BUILD_REF=${TKX_SHLIB_NAME}
        TCLX_SHLIB_BUILD_TARGET=${TCLX_SHLIB_NAME}
        TKX_SHLIB_BUILD_TARGET=${TKX_SHLIB_NAME}
	TCLX_LIB_NAME=${TCLX_SHLIB_NAME}
	TKX_LIB_NAME=${TKX_SHLIB_NAME}
        ;;
    0)
        AC_MSG_RESULT(Will not build shared libraries)
        TCLX_BUILD_LIB_SPEC="$bldbasedir/tcl/unix/${TCLX_STLIB_NAME}"
        TCLX_LIB_SPEC="$TCLX_INST_LIB/${TCLX_STLIB_NAME}"
        TKX_BUILD_LIB_SPEC="$bldbasedir/tk/unix/${TKX_STLIB_NAME}"
        TKX_LIB_SPEC="$TCLX_INST_LIB/${TKX_STLIB_NAME}"
        TCLX_STLIB_BUILD_REF=${TCLX_STLIB_NAME}
        TKX_STLIB_BUILD_REF=${TKX_STLIB_NAME}
        TCLX_SHLIB_BUILD_REF=""
        TKX_SHLIB_BUILD_REF=""
        TCLX_SHLIB_BUILD_TARGET=NO_SHLIB
        TKX_SHLIB_BUILD_TARGET=NO_SHLIB
 	TCLX_LIB_NAME=${TCLX_STLIB_NAME}
 	TKX_LIB_NAME=${TKX_STLIB_NAME}
        ;;
esac

#
# If the names ended up the same, dont build twice.
#
if test "x$TCLX_STLIB_BUILD_TARGET" = "x$TCLX_SHLIB_BUILD_TARGET"; then
	TCLX_BUILD_STANDALONE="tclXinitSA${SHOBJ_SUFFIX}"
	TKX_BUILD_STANDALONE="tkXinitSA${SHOBJ_SUFFIX}"
	TCLX_BUILD_DUMMY_STANDALONE="tclXinitSA${SHOBJ_SUFFIX}"
	TKX_BUILD_DUMMY_STANDALONE="tkXinitSA${SHOBJ_SUFFIX}"
else
	TCLX_BUILD_STANDALONE="tclXinitSA.o"
	TKX_BUILD_STANDALONE="tkXinitSA.o"
	TCLX_BUILD_DUMMY_STANDALONE="tclXinitDSA${SHOBJ_SUFFIX}"
	TKX_BUILD_DUMMY_STANDALONE="tkXinitDSA${SHOBJ_SUFFIX}"
fi

AC_SUBST(SHOBJ_SUFFIX)
AC_SUBST(TCL_STLIB_NAME)
AC_SUBST(TK_STLIB_NAME)
AC_SUBST(TCLX_STLIB_NAME)
AC_SUBST(TCLX_SHLIB_NAME)
AC_SUBST(TCLX_STLIB_BUILD_REF)
AC_SUBST(TCLX_SHLIB_BUILD_REF)
AC_SUBST(TCLX_SHLIB_BUILD_TARGET)
AC_SUBST(TKX_STLIB_NAME)
AC_SUBST(TKX_SHLIB_NAME)
AC_SUBST(TKX_STLIB_BUILD_REF)
AC_SUBST(TKX_SHLIB_BUILD_REF)
AC_SUBST(TKX_SHLIB_BUILD_TARGET)
AC_SUBST(TCLX_BUILD_LIB_SPEC)
AC_SUBST(TCLX_LIB_SPEC)
AC_SUBST(TKX_BUILD_LIB_SPEC)
AC_SUBST(TKX_LIB_SPEC)
AC_SUBST(TCLX_LIB_NAME)
AC_SUBST(TKX_LIB_NAME)

# These are substituted into the run scripts
TCLX_BIN_DIR="${bldbasedir}/tcl/unix"
TCLX_LIB_DIR="${bldbasedir}/tcl/unix"
TCLX_RUNTIME_DIR="${bldbasedir}/tcl/unix"
AC_SUBST(TCLX_BIN_DIR)
AC_SUBST(TCLX_LIB_DIR)
AC_SUBST(TCLX_RUNTIME_DIR)

TKX_BIN_DIR="${bldbasedir}/tk/unix"
TKX_LIB_DIR="${bldbasedir}/tk/unix"
TKX_RUNTIME_DIR="${bldbasedir}/tk/unix"
AC_SUBST(TKX_BIN_DIR)
AC_SUBST(TKX_LIB_DIR)
AC_SUBST(TKX_RUNTIME_DIR)

#------------------------------------------------------------------------------
# Test for UnixWare -o bug.  Macros are used in targets to build the shared
# objects.
#------------------------------------------------------------------------------
AC_MSG_CHECKING([for UnixWare -o bug])
rm -rf conftest*
cat > conftest.$ac_ext <<EOF
int main() { return 0; }
EOF
${CC-cc} -c -o conftest..o conftest.$ac_ext
if test -f conftest..o; then
    OBJ_SAVE="@:"
    OBJ_RESTORE="@:"
    CC_SHOBJ_FLAG='-o $@'
    AC_MSG_RESULT([OK])
else
    OBJ_SAVE='@b=`basename $@ ..o`; if test -f $$b.o ; then rm -f $$b.sav; mv $$b.o $$b.sav'
    OBJ_RESTORE='@b=`basename $@ ..o`;mv $$b.o $@; if test -f $$b.sav ; then mv$$b.sav $$b'
    CC_SHOBJ_FLAG=""
    AC_MSG_RESULT([buggy])
fi
rm -rf conftest*

AC_SUBST(OBJ_SAVE)
AC_SUBST(OBJ_RESTORE)
AC_SUBST(CC_SHOBJ_FLAG)

#------------------------------------------------------------------------------
# Test if there are shared versions of the socket, math and c libraries.
#------------------------------------------------------------------------------

SHARED_LIBS=""
if test "x${SHLIB_SUFFIX}" = "x..o" -o "x${SHLIB_SUFFIX}" = "x.a"; then
    if test "x${SHLIB_CFLAGS}" = "x-G 0"; then
	TEST_SUFFIX="_G0.a"
    else
	TEST_SUFFIX=".a"
    fi
else
    if test "x${TCL_SHARED_LIB_SUFFIX}" = 'x${VERSION}.a' -a "x${SHLIB_SUFFIX}" = "x.so"; then
	TEST_SUFFIX=".a"
	SHARED_LIBS="${TCL_LIB_SPEC}"
    else
	TEST_SUFFIX="${SHLIB_SUFFIX}"
    fi
fi

dirs="/lib/libm${TEST_SUFFIX}* /usr/lib/libm${TEST_SUFFIX}*"
for i in $dirs ; do
    if test -f $i; then
	SHARED_LIBS="${SHARED_LIBS} -lm"
	break;
    fi
done
dirs="/lib/libc${TEST_SUFFIX}* /usr/lib/libc${TEST_SUFFIX}*"
for i in $dirs ; do
    if test -f $i; then
	SHARED_LIBS="${SHARED_LIBS} -lc"
	break;
    fi
done
AC_SUBST(SHARED_LIBS)

#------------------------------------------------------------------------------
# Check for Plus patch being installed. Does libtcl.a contains a definition of
# Tcl_InitStandAlone() and does Tk contain Tk_InitStandAlone.
#------------------------------------------------------------------------------
AC_MSG_CHECKING([standalone support of Tcl (Plus patch)])
if test -f "${TCL_BUILD}/unix/${TCL_STLIB_NAME}"; then
    x=`nm -p "${TCL_BUILD}/unix/${TCL_STLIB_NAME}" |grep 'Tcl_InitStandAlone'`
    if test "x$x" != "x"; then
        # Build variables already set
	AC_MSG_RESULT([yes])
        AC_DEFINE(HAVE_TCL_STANDALONE)
    else
	AC_MSG_RESULT([no])
	TCLX_BUILD_STANDALONE=""
	TCLX_BUILD_DUMMY_STANDALONE=""
    fi
else
    AC_MSG_RESULT([no])
    TCLX_BUILD_STANDALONE=""
    TCLX_BUILD_DUMMY_STANDALONE=""
fi
AC_SUBST(TCLX_BUILD_STANDALONE)
AC_SUBST(TCLX_BUILD_DUMMY_STANDALONE)

AC_MSG_CHECKING([standalone support of Tk (Plus patch)])
if test "${TKX_BUILD}" = "YES" -a -f "${TK_BUILD}/unix/${TK_STLIB_NAME}"; then
    x=`nm -p "${TK_BUILD}/unix/${TK_STLIB_NAME}" |grep 'Tk_InitStandAlone'`
    if test "x$x" != "x"; then
        # Build variables already set
	AC_MSG_RESULT([yes])
        AC_DEFINE(HAVE_TK_STANDALONE)
    else
	AC_MSG_RESULT([no])
	TKX_BUILD_STANDALONE=""
	TKX_BUILD_DUMMY_STANDALONE=""
    fi
else
    AC_MSG_RESULT([no])
    TKX_BUILD_STANDALONE=""
    TKX_BUILD_DUMMY_STANDALONE=""
fi
AC_SUBST(TKX_BUILD_STANDALONE)
AC_SUBST(TKX_BUILD_DUMMY_STANDALONE)

#------------------------------------------------------------------------------
# Determine if Tcl was built with threading support.
#------------------------------------------------------------------------------
SC_ENABLE_THREADS

#------------------------------------------------------------------------------
# Determine if we have symbolic links on the filesystem we are building
# on.  They are needed the setup the help so the help test will work.
# If we don't have them, we have to copy the files.
#------------------------------------------------------------------------------
AC_PROG_LN_S
if test "$LN_S" = "ln"; then
    HAVE_SYML="NO"
else
    HAVE_SYML="YES"
fi
AC_SUBST(HAVE_SYML)

#------------------------------------------------------------------------------
# Some make programs require includes to be 
#     .include "file"
# others...
#     include file
# Checks the MAKE environment variable for the name of the make command to use.
#------------------------------------------------------------------------------

AC_MSG_CHECKING("how make handles includes")
cat > confmakeinc <<EOF

EOF
  cat > confmakefile <<EOF
include confmakeinc

all:
EOF

if ${MAKE-make} -f confmakefile >/dev/null 2>/dev/null; then
    MAKEINCLUDE="include"
    MAKEQUOTE=''
    AC_MSG_RESULT(common make include syntax)
else
    MAKEINCLUDE=".include"
    MAKEQUOTE='"'
    AC_MSG_RESULT(BSD make include syntax)
fi
rm confmakefile confmakeinc

AC_SUBST(MAKEINCLUDE)
AC_SUBST(MAKEQUOTE)

#------------------------------------------------------------------------------
# Check for system header files.
#------------------------------------------------------------------------------

AC_HEADER_CHECK(limits.h, , AC_DEFINE(NO_LIMITS_H))
AC_HEADER_CHECK(sys/select.h, , AC_DEFINE(NO_SYS_SELECT_H))

#------------------------------------------------------------------------------
# Check for missing typedefs.
#------------------------------------------------------------------------------

AC_CHECK_TYPE(clock_t, long)
AC_CHECK_TYPE(time_t, long)
AC_CHECK_TYPE(off_t, long)

#------------------------------------------------------------------------------
# What type do signals return?
#------------------------------------------------------------------------------

AC_RETSIGTYPE

#------------------------------------------------------------------------------
# Test to see if "times" returns a status or the amount of elapsed real time.
#------------------------------------------------------------------------------

AC_MSG_CHECKING(checking to see what 'times' returns)
AC_TRY_RUN([
#include <sys/types.h>
#include <sys/times.h>
main() {
struct tms cpu;
times (&cpu);
sleep (2);
if (times (&cpu) > 0)
     exit (0);
else 
     exit (1);
}
], [AC_MSG_RESULT(elapsed real time)],
   [AC_MSG_RESULT(a status)
    AC_DEFINE(TIMES_RETS_STATUS)],
   [AC_MSG_ERROR(cross-compiling not supported)])

#------------------------------------------------------------------------------
#     Determine if "." is used as separator for the manual directory
#     names.  i.e. man/man.1 vs man/man1
#------------------------------------------------------------------------------

AC_MSG_CHECKING(man directory/section separator)
mandirs="/usr/man/man.1 /usr/man/cat.1 /usr/share/man.1 /usr/share/cat.1
         /usr/man/u_man/man.1 /usr/man/cat.C"
gotdotdir="NO"
for d in $mandirs
do
    if test -d $d
    then
        gotdotdir="YES"
    fi
done

mandirs="/usr/man/man1   /usr/man/cat1   /usr/share/man1   /usr/share/man1
         /usr/man/man1.Z /usr/man/cat1.Z /usr/share/man1.Z /usr/share/man1.Z
         /usr/man/u_man/man1 /usr/share/man/man1"
gotnodotdir="NO"
for d in $mandirs
do
    if test -d $d
    then
        gotnodotdir="YES"

    fi
done

if test $gotdotdir = YES -a $gotnodotdir = NO
then
    MAN_DIR_SEPARATOR="."
    AC_MSG_RESULT(man/man.1 style)
elif test $gotdotdir = NO -a $gotnodotdir = YES
then
    MAN_DIR_SEPARATOR=""
    AC_MSG_RESULT(man/man1 style)
else
    MAN_DIR_SEPARATOR=""
    AC_MSG_RESULT([WARNING: couldn't determine, assuming man/man1 style])
fi
AC_SUBST(MAN_DIR_SEPARATOR)

#------------------------------------------------------------------------------
# Check for additional libraries the Tcl/Tk does not check for.
#------------------------------------------------------------------------------

# This is needed for DEC Alphas
AC_CHECK_LIB(dnet_stub, main, [TCLX_LIBS="$TCLX_LIBS -ldnet_stub"])

#------------------------------------------------------------------------------
# Older SCO systems don't have ftruncate, but have chsize in libx.  Newer
# versions have both.  Only check for chsize in libx if we don't have
# truncate.
#------------------------------------------------------------------------------

AC_CHECK_FUNC(ftruncate, ,
        [AC_DEFINE(NO_FTRUNCATE)
         AC_CHECK_LIB(x, chsize,
                [AC_DEFINE(HAVE_CHSIZE)
                 [TCLX_LIBS="$TCLX_LIBS -lx"]])])

#------------------------------------------------------------------------------
# Check for various Unix or library functions that can be used by TclX.
# These must be after the library checks.
#------------------------------------------------------------------------------

AC_CHECK_FUNC(select, , AC_DEFINE(NO_SELECT))
AC_CHECK_FUNC(setitimer, , AC_DEFINE(NO_SETITIMER))
AC_CHECK_FUNC(sigaction, , AC_DEFINE(NO_SIGACTION))
AC_CHECK_FUNC(setpgid, , AC_DEFINE(NO_SETPGID))
AC_CHECK_FUNC(getgroups, , AC_DEFINE(NO_GETGROUPS))
AC_CHECK_FUNC(bzero, , AC_DEFINE(NO_BZERO))
AC_CHECK_FUNC(bcopy, , AC_DEFINE(NO_BCOPY))
AC_CHECK_FUNC(fsync, , AC_DEFINE(NO_FSYNC))
AC_CHECK_FUNC(getpriority, , AC_DEFINE(NO_GETPRIORITY))
AC_CHECK_FUNC(strcoll, , AC_DEFINE(NO_STRCOLL))
AC_CHECK_FUNC(fchown, , AC_DEFINE(NO_FCHOWN))
AC_CHECK_FUNC(fchmod, , AC_DEFINE(NO_FCHMOD))
AC_CHECK_FUNC(truncate, , AC_DEFINE(NO_TRUNCATE))
AC_CHECK_FUNC(waitpid, , AC_DEFINE(NO_WAITPID))
AC_CHECK_FUNC(sysconf, , AC_DEFINE(NO_SYSCONF))

#------------------------------------------------------------------------------
# Test for socket related functions.
#------------------------------------------------------------------------------

AC_CHECK_FUNC(inet_aton, , AC_DEFINE(NO_INET_ATON))
AC_CHECK_FUNC(gethostname, , AC_DEFINE(NO_GETHOSTNAME))

#------------------------------------------------------------------------------
# Check for catgets.  Not the some systems (NetBSD 1.0) have catclose declared
# as type void rather than type int.
#------------------------------------------------------------------------------

AC_CHECK_FUNC(catgets,
    [AC_MSG_CHECKING([catclose return value])
     AC_TRY_COMPILE([#include <nl_types.h>], [
        if (catclose ((nl_catd) 0) == 0) exit (0);],
        AC_MSG_RESULT(ok), [
        AC_MSG_RESULT([broken catclose return type])
        AC_DEFINE(BAD_CATCLOSE)])],
    [AC_DEFINE(NO_CATGETS)])

#------------------------------------------------------------------------------
# Check for missing functions that we need.  Must be done after library checks.
#------------------------------------------------------------------------------

AC_CHECK_FUNC(random, ,[LIBOBJS="$LIBOBJS random.o"]
              AC_DEFINE(NO_RANDOM))
AC_CHECK_FUNC(rename, ,[LIBOBJS="$LIBOBJS rename.o"])
AC_SUBST(LIBOBJS)

LIBSOBJS=`echo $LIBOBJS |sed -e s/\\\\.o/$SHOBJ_SUFFIX/g`
AC_SUBST(LIBSOBJS)

#------------------------------------------------------------------------------
# Determine if random is declared in stdlib.h or math.h.  If it is, we don't
# want to redeclare it.  Some systems, such as the DEC Alpha, have random
# declared as returning int rather than long, since long is 64 bit.
#------------------------------------------------------------------------------

found_random=NO
AC_HEADER_EGREP("random", stdlib.h, [found_random=YES])
AC_HEADER_EGREP("random", math.h, [found_random=YES])

if test "$found_random" = "NO"; then
    AC_DEFINE(NO_RANDOM_PROTO)
fi

#------------------------------------------------------------------------------
# Determine if floor is declared in stdlib.h or math.h.  If it is, we don't
# want to redeclare it.
#------------------------------------------------------------------------------

found_floor=NO
AC_HEADER_EGREP("floor", stdlib.h, [found_floor=YES])
AC_HEADER_EGREP("floor", math.h, [found_floor=YES])

if test "$found_floor" = "NO"; then
    AC_DEFINE(NO_FLOOR_PROTO)
fi

#------------------------------------------------------------------------------
# Determine if we have enough tools to generate the help files.
# Allow --with-helpdir to specify help file outputs
#------------------------------------------------------------------------------

AC_PATH_PROGS(NROFF, nroff, :, ${PATH})

if test "x${NROFF}" = "x:" ; then
    AC_MSG_WARN(No nroff executable found.  Cannot build help files.) ;
    BUILDHELP=
else
    BUILDHELP=buildhelp
fi
AC_SUBST(BUILDHELP)

AC_ARG_WITH(help, [  --with-help              directory containing generated help files], with_help=${withval})
if test x"${with_help}" != x ; then
    HELP_DIR=${with_help}
else
    HELP_DIR=${srcbasedir}/tcl/help
fi
AC_SUBST(HELP_DIR)

#------------------------------------------------------------------------------
# Generate the make files.
#------------------------------------------------------------------------------

AC_SUBST(TCLX_LIBS)

AC_OUTPUT(Makefile \
          Common.mk \
          runtcl \
          runtcl.static \
          runtcl.standalone \
          runwishx \
          runwishx.static \
          runwishx.standalone \
          tools/Makefile \
          ../tcl/unix/Makefile \
          ../tcl/unix/tclxConfig.sh \
          ../tcl/unix/pkgIndex.tcl \
          ../tcl/unix/runtest \
          ../tcl/unix/runtest.static \
          ../tcl/unix/runtest.standalone \
          ../tk/unix/Makefile \
          ../tk/unix/tkxConfig.sh \
          ../tk/unix/pkgIndex.tcl \
          ../tk/unix/runtest \
          ../tk/unix/runtest.static \
          ../tk/unix/runtest.standalone,
          [chmod a+xr,go-w runtcl
           chmod a+xr,go-w runtcl.static
           chmod a+xr,go-w runtcl.standalone
           chmod a+xr,go-w runwishx
           chmod a+xr,go-w runwishx.static
           chmod a+xr,go-w runwishx.standalone
           chmod a+xr,go-w ../tcl/unix/runtest
           chmod a+xr,go-w ../tcl/unix/runtest.static
           chmod a+xr,go-w ../tcl/unix/runtest.standalone
           chmod a+xr,go-w ../tk/unix/runtest
           chmod a+xr,go-w ../tk/unix/runtest.static
           chmod a+xr,go-w ../tk/unix/runtest.standalone])
