dnl	This file is an input file used by the GNU "autoconf" program to
dnl	generate the file "configure", which is run during installation
dnl	to configure the system for the local environment.
AC_INIT(customize.tcl)

# @(#) configure.in 1.17 95/06/27 21:54:20

#--------------------------------------------------------------------
#	Versions of the relevant libraries
#--------------------------------------------------------------------

VERSION=2.0
TCL_VERSION=7.5
TK_VERSION=4.1
SCHEME_VERSION=0.5

#--------------------------------------------------------------------
#	Determine the compiler and whether or not we are cross compiling 
#--------------------------------------------------------------------

if test "x$CXX" = "x"; then

	# -----------------------------------------------------------
	# check for the C compiler if we are compiling C
	# -----------------------------------------------------------

    AC_PROG_CC


	# -----------------------------------------------------------
	# check for the preprocessor -- Note that the Insure preprocessor
	# (e.g., insure -E) does not print any output to standard output.
	# Therefore we must bypass it and go directly to the real
	# underlying compiler.  Since our copy of Insure is on a Linux
	# machine, we assume that the real underlying compiler is cc.
	# -----------------------------------------------------------

    if test "$CC" = "insure"; then
	CPP="cc -E";
	echo "checking how to run the C preprocessor ... $CPP";
    else
	AC_PROG_CPP
    fi

    AC_LANG_C

else

	# -----------------------------------------------------------
	# force the use of g++ rather than gcc if we are compiling g++
	# -----------------------------------------------------------

    if test "$CXX" = "gcc"; then
	CXX="g++";
    fi

	# -----------------------------------------------------------
	# check for the C++ compiler if we are compiling C++
	# -----------------------------------------------------------
	
    CC=$CXX
    AC_PROG_CXX

	# -----------------------------------------------------------
	# check for the preprocessor -- Note that the Insure preprocessor
	# (e.g., insure -E) does not print any output to standard output.
	# Therefore we must bypass it and go directly to the real
	# underlying compiler.  Since our copy of Insure is on a Linux
	# machine, we assume that the real underlying compiler is g++.
	# -----------------------------------------------------------

    if test "$CXX" = "insure"; then
	CXXCPP="g++ -E";
	echo "checking how to run the C++ preprocessor ... $CXXCPP";
    else
	AC_PROG_CXXCPP
    fi

    AC_LANG_CPLUSPLUS

	# -----------------------------------------------------------
	# check for libstdc++ if we are compiling C++
	# -----------------------------------------------------------

    CXX_LIBS=""
    AC_CHECK_LIB(stdc++, main, [CXX_LIBS="$CXX_LIBS -lstdc++"])
    AC_CHECK_LIB(C, main, [CXX_LIBS="$CXX_LIBS -lC"])
    AC_CHECK_LIB(Csup, main, [CXX_LIBS="$CXX_LIBS -lCsup"])

	# -----------------------------------------------------------
	# can't use #pragma interface, etc., unless we are using g++
	# -----------------------------------------------------------

    if test "$CXX" != "g++"; then
	AC_DEFINE(NO_PRAGMAS)
    fi
fi

if test $cross_compiling = "yes"; then
    echo ""
    echo "FATAL ERROR: can not yet cross-compile the Agent Tcl system"
    echo ""
    exit 1
fi

#--------------------------------------------------------------------
#	Determine if ranlib is present
#--------------------------------------------------------------------

AC_PROG_RANLIB

#--------------------------------------------------------------------
#	Determine the "make" command line
#--------------------------------------------------------------------

AC_PROG_MAKE_SET

#--------------------------------------------------------------------
#	Check for the srand and srandom functions
#--------------------------------------------------------------------

AC_CHECK_FUNC(srand, , AC_DEFINE(NO_SRAND_FUNCTION))
AC_CHECK_FUNC(srandom, , AC_DEFINE(NO_SRANDOM_FUNCTION))

#--------------------------------------------------------------------
#	Check for the remove function
#--------------------------------------------------------------------

AC_CHECK_FUNC(remove, , AC_DEFINE(NO_REMOVE_FUNCTION))

#--------------------------------------------------------------------
#	Check for the unsetenv function
#--------------------------------------------------------------------

AC_CHECK_FUNC(unsetenv, , AC_DEFINE(NO_UNSETENV_FUNCTION))

#--------------------------------------------------------------------
#	Check for the writev function
#--------------------------------------------------------------------

AC_CHECK_FUNC(writev, , AC_DEFINE(NO_WRITEV_FUNCTION))

#--------------------------------------------------------------------
#	On a few very rare systems, all of the libm.a stuff is
#	already in libc.a.  Set compiler flags accordingly.
#	Also, Linux requires the "ieee" library for math to
#	work right (and it must appear before "-lm").
#--------------------------------------------------------------------

MATH_LIBS=""
AC_CHECK_LIB(m, main, [MATH_LIBS="-lm"])
AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"])
AC_SUBST(MATH_LIBS)

#--------------------------------------------------------------------
#	Interactive UNIX requires -linet instead of -lsocket, plus it
#	needs net/errno.h to define the socket-related error codes.
#--------------------------------------------------------------------

AC_CHECK_LIB(inet, main, [LIBS="$LIBS -linet"])
AC_CHECK_HEADER(net/errno.h, AC_DEFINE(HAVE_NET_ERRNO_H))

#--------------------------------------------------------------------
#	Check for the existence of the -lsocket and -lnsl libraries.
#	The order here is important, so that they end up in the right
#	order in the command line generated by make.  Here are some
#	special considerations:
#	1. Use "connect" and "accept" to check for -lsocket, and
#	   "gethostbyname" to check for -lnsl.
#	2. Use each function name only once:  can't redo a check because
#	   autoconf caches the results of the last check and won't redo it.
#	3. Use -lnsl and -lsocket only if they supply procedures that
#	   aren't already present in the normal libraries.  This is because
#	   IRIX 5.2 has libraries, but they aren't needed and they're
#	   bogus:  they goof up name resolution if used.
#	4. On some SVR4 systems, can't use -lsocket without -lnsl too.
#	   To get around this problem, check for both libraries together
#	   if -lsocket doesn't work by itself.
#--------------------------------------------------------------------

tcl_checkBoth=0
AC_CHECK_FUNC(connect, tcl_checkSocket=0, tcl_checkSocket=1)
if test "$tcl_checkSocket" = 1; then
    AC_CHECK_LIB(socket, main, LIBS="$LIBS -lsocket", tcl_checkBoth=1)
fi
if test "$tcl_checkBoth" = 1; then
    tk_oldLibs=$LIBS
    LIBS="$LIBS -lsocket -lnsl"
    AC_CHECK_FUNC(accept, tcl_checkNsl=0, [LIBS=$tk_oldLibs])
fi
AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"]))

#--------------------------------------------------------------------
#	See if we need -lcrypt and then check for the existence of -lcrypt
#--------------------------------------------------------------------

CRYPT_LIBS=""

AC_MSG_CHECKING([if we need a crypt library])
AC_TRY_LINK([extern "C" char *crypt (char *key, char *salt);],
	[char *c; c = crypt ("ab", "ab");], crypt_needed=no, crypt_needed=yes)
AC_MSG_RESULT($crypt_needed)

if test $crypt_needed = yes; then
    AC_CHECK_LIB(crypt, main, [CRYPT_LIBS="-lcrypt"])
    AC_SUBST(CRYPT_LIBS)
fi

#--------------------------------------------------------------------
#	Locate the X11 header files and the X11 library archive.  Try
#	the ac_path_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.  Under some conditions the
#	autoconf macro will return an include directory that contains
#	no include files, so double-check its result just to be safe.
#--------------------------------------------------------------------

AC_PATH_X
not_really_there=""
if test "$no_x" = ""; then
    if test "$x_includes" = ""; then
	AC_TRY_CPP([#include <X11/XIntrinsic.h>], , not_really_there="yes")
    else
	if test ! -r $x_includes/X11/Intrinsic.h; then
	    not_really_there="yes"
	fi
    fi
fi
if test "$no_x" = "yes" -o "$not_really_there" = "yes"; then
    echo checking for X11 header files
    XINCLUDES="# no special path needed"
    AC_TRY_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 /usr/sww/include"
        for i in $dirs ; do
	    if test -r $i/X11/Intrinsic.h; then
	        XINCLUDES=" -I$i"
	    fi
        done
    fi
else
    if test "$x_includes" != ""; then
	XINCLUDES=-I$x_includes
    else
	XINCLUDES="# no special path needed"
    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 "$no_x" = yes; then
    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 /usr/sww/X11/lib"
	for i in $dirs ; do
	    if test -r $i/libX11.a; then
		XLIBSW="-L$i -lX11"
	    fi
	done
    fi
else
    if test "$x_libraries" = ""; then
	XLIBSW=-lX11
    else
	XLIBSW="-L$x_libraries -lX11"
    fi
fi
if test "$XLIBSW" = nope ; then
    AC_CHECK_LIB(Xwindow, XCreateWindow, 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)

#--------------------------------------------------------------------
# One more check related to the X libraries.  The standard releases
# of Ultrix don't support the "xauth" mechanism, so send won't work
# unless TK_NO_SECURITY is defined.  However, there are usually copies
# of the MIT X server available as well, which do support xauth.
# Check for the MIT stuff and use it if it exists.
#
# Note: can't use ac_check_lib macro (at least, not in Autoconf 2.1)
# because it can't deal with the "-" in the library name.
#--------------------------------------------------------------------

if test -d /usr/include/mit ; then
    AC_MSG_CHECKING([MIT X libraries])
    tk_oldCFlags=$CFLAGS
    CFLAGS="$CFLAGS -I/usr/include/mit"
    tk_oldLibs=$LIBS
    LIBS="$LIBS -lX11-mit"
    AC_TRY_LINK([
	#include <X11/Xlib.h>
    ], [
	XOpenDisplay(0);
    ], [
	AC_MSG_RESULT(yes)
	XLIBSW="-lX11-mit"
	XINCLUDES="-I/usr/include/mit"
    ], AC_MSG_RESULT(no))
    CFLAGS=$tk_oldCFlags
    LIBS=$tk_oldLibs
fi

#---------------------------------------------------------------------
#       Check for the sys/ioctl.h header file
#---------------------------------------------------------------------

AC_CHECK_HEADER(sys/ioctl.h,AC_DEFINE(HAVE_SYS_IOCTL_H),)

#---------------------------------------------------------------------
#       Check for the sys/un.h header file
#---------------------------------------------------------------------

AC_CHECK_HEADER(sys/un.h,AC_DEFINE(HAVE_SYS_UN_H),)

#---------------------------------------------------------------------
#       Check for the I/O header file: uio.h
#---------------------------------------------------------------------

AC_CHECK_HEADER(sys/uio.h,AC_DEFINE(HAVE_SYS_UIO_H),)

#---------------------------------------------------------------------
#       Check for the file I/O header file: filio.h
#---------------------------------------------------------------------

AC_CHECK_HEADER(sys/filio.h,AC_DEFINE(HAVE_SYS_FILIO_H),)

#---------------------------------------------------------------------
#	Check for the crypt header file: crypt.h
#---------------------------------------------------------------------

AC_CHECK_HEADER(crypt.h,AC_DEFINE(HAVE_CRYPT_H),)

#--------------------------------------------------------------------
#	Check for the string header files: string.h, strings.h and bstring.h
#--------------------------------------------------------------------

AC_CHECK_HEADER(strings.h,AC_DEFINE(HAVE_STRINGS_H),)
AC_CHECK_HEADER(bstring.h,AC_DEFINE(HAVE_BSTRING_H),)
AC_CHECK_HEADER(ctype.h,AC_DEFINE(HAVE_CTYPE_H),)

#--------------------------------------------------------------------
#	Check for the malloc header file: malloc.h
#--------------------------------------------------------------------

AC_CHECK_HEADER(malloc.h,AC_DEFINE(HAVE_MALLOC_H),)

#--------------------------------------------------------------------
#	Supply substitutes for missing POSIX header files.  Special
#	notes:
#	    - stdlib.h doesn't define strtol, strtoul, or
#	      strtod insome versions of SunOS
#	    - some versions of string.h don't declare procedures such
#	      as strstr
#--------------------------------------------------------------------

AC_MSG_CHECKING(for dirent.h)
AC_TRY_LINK([#include <sys/types.h>
#include <dirent.h>], [
#ifndef _POSIX_SOURCE
#   ifdef __Lynx__
	/*
	 * Generate compilation error to make the test fail:  Lynx headers
	 * are only valid if really in the POSIX environment.
	 */

	missing_procedure();
#   endif
#endif
DIR *d;
struct dirent *entryPtr;
char *p;
d = opendir("foobar");
entryPtr = readdir(d);
p = entryPtr->d_name;
closedir(d);
], tcl_ok=yes, tcl_ok=no)
if test $tcl_ok = no; then
    AC_DEFINE(NO_DIRENT_H)
fi
AC_MSG_RESULT($tcl_ok)
AC_CHECK_HEADER(errno.h, , AC_DEFINE(NO_ERRNO_H))
AC_CHECK_HEADER(float.h, , AC_DEFINE(NO_FLOAT_H))
AC_CHECK_HEADER(limits.h, , AC_DEFINE(NO_LIMITS_H))
AC_CHECK_HEADER(stdlib.h, tcl_ok=1, tcl_ok=0)
AC_EGREP_HEADER(strtol, stdlib.h, , tcl_ok=0)
AC_EGREP_HEADER(strtoul, stdlib.h, , tcl_ok=0)
AC_EGREP_HEADER(strtod, stdlib.h, , tcl_ok=0)
if test $tcl_ok = 0; then
    AC_DEFINE(NO_STDLIB_H)
fi
AC_CHECK_HEADER(string.h, tcl_ok=1, tcl_ok=0)
AC_EGREP_HEADER(strstr, string.h, , tcl_ok=0)
AC_EGREP_HEADER(strerror, string.h, , tcl_ok=0)
if test $tcl_ok = 1; then
    AC_DEFINE(HAVE_STRING_H)
fi
AC_CHECK_HEADER(sys/wait.h, , AC_DEFINE(NO_SYS_WAIT_H))
AC_HAVE_HEADERS(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.
#--------------------------------------------------------------------

AC_MSG_CHECKING([fd_set and sys/select])
AC_TRY_COMPILE([#include <sys/types.h>],
	[fd_set readMask, writeMask;], tk_ok=yes, tk_ok=no)
if test $tk_ok = no; then
    AC_HEADER_EGREP(fd_mask, sys/select.h, tk_ok=yes)
    if test $tk_ok = yes; then
	AC_DEFINE(HAVE_SYS_SELECT_H)
    fi
fi
AC_MSG_RESULT($tk_ok)
if test $tk_ok = no; then
    AC_DEFINE(NO_FD_SET)
fi

#------------------------------------------------------------------------------
#       Find out all about time handling differences.
#------------------------------------------------------------------------------

AC_CHECK_HEADERS(sys/time.h)
AC_HEADER_TIME
AC_STRUCT_TIMEZONE

AC_MSG_CHECKING([tm_tzadj in struct tm])
AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_tzadj;],
        [AC_DEFINE(HAVE_TM_TZADJ)
         AC_MSG_RESULT(yes)],
        AC_MSG_RESULT(no))

AC_MSG_CHECKING([tm_gmtoff in struct tm])
AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_gmtoff;],
        [AC_DEFINE(HAVE_TM_GMTOFF)
         AC_MSG_RESULT(yes)],
        AC_MSG_RESULT(no))

#
# Its important to include time.h in this check, as some systems (like convex)
# have timezone functions, etc.
#
AC_MSG_CHECKING([timezone variable])
AC_TRY_COMPILE([#include <time.h>],
        [extern long timezone;
         timezone += 1;],
        [AC_DEFINE(HAVE_TIMEZONE_VAR)
         AC_MSG_RESULT(yes)],
        AC_MSG_RESULT(no))

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

AC_MODE_T
AC_PID_T
AC_SIZE_T
AC_UID_T

#--------------------------------------------------------------------
# See if we have the type sig_atomic_t
#--------------------------------------------------------------------

AC_MSG_CHECKING([for sig_atomic_t])
AC_TRY_COMPILE([#include <sys/types.h>
#include <signal.h>],[
sig_atomic_t s;
],sig_atomic=yes,sig_atomic=no)

if test $sig_atomic = no; then
  AC_DEFINE(NO_SIGATOMIC_T)
fi

AC_MSG_RESULT($sig_atomic)

#--------------------------------------------------------------------
# See if we have fcntl file locking 
#--------------------------------------------------------------------

AC_MSG_CHECKING([for fcntl file locking])
AC_TRY_COMPILE([#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>],[
struct flock lockInfo;
lockInfo.l_type = F_WRLCK;
],fcntl_lock=yes,fcntl_lock=no)

if test $fcntl_lock = no; then
  AC_DEFINE(NO_FCNTL_LOCKING)
fi

AC_MSG_RESULT($fcntl_lock)

#--------------------------------------------------------------------
# See if we can cast sigaction handler as void (*) (...)
#--------------------------------------------------------------------

AC_MSG_CHECKING([if sigaction handler can be cast to type \"void (*) (...)\"])
AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/signal.h>
void func (int a) {};],[
struct sigaction act;
act.sa_handler = (void (*) (...)) func;
],sigaction_cast=yes,sigaction_cast=no)

if test $sigaction_cast = yes; then
  AC_DEFINE(SIGACTION_CAST)
fi

AC_MSG_RESULT($sigaction_cast)

#--------------------------------------------------------------------
# See if we can cast sigaction handler as void (*) ()
#--------------------------------------------------------------------

AC_MSG_CHECKING([if sigaction handler can be cast to type \"void (*) ()\"])
AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/signal.h>
void func (int a) {};],[
struct sigaction act;
act.sa_handler = (void (*) ()) func;
],sigaction_cast=yes,sigaction_cast=no)

if test $sigaction_cast = yes; then
  AC_DEFINE(SIGACTION_PAREN_CAST)
fi

AC_MSG_RESULT($sigaction_cast)

#--------------------------------------------------------------------
# See if struct sockaddr_un has the sun_len field
#--------------------------------------------------------------------

AC_MSG_CHECKING([for sun_len field in sockaddr_un])
AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>],[
struct sockaddr_un unixSocket;
unixSocket.sun_len = 0;
],sun_len=yes,sun_len=no)

if test $sun_len = yes; then
  AC_DEFINE(SUNLEN_EXISTS)
fi

AC_MSG_RESULT($sun_len)

#--------------------------------------------------------------------
#       We will use "mkstemp" when creating temporary files if it is
# 	available
#--------------------------------------------------------------------

AC_CHECK_FUNC(mkstemp, AC_DEFINE(USE_MKSTEMP))

#--------------------------------------------------------------------
#	The code below deals with several issues related to gettimeofday:
#	1. Some systems don't provide a gettimeofday function at all
#	   (set NO_GETTOD if this is the case).
#	2. SGI systems don't use the BSD form of the gettimeofday function,
#	   but they have a BSDgettimeofday function that can be used instead.
#	3. See if gettimeofday is declared in the <sys/time.h> header file.
#	   if not, set the GETTOD_NOT_DECLARED flag so that tclPort.h can
#	   declare it.
#--------------------------------------------------------------------

AC_CHECK_FUNC(BSDgettimeofday, AC_DEFINE(HAVE_BSDGETTIMEOFDAY),
AC_CHECK_FUNC(gettimeofday, , AC_DEFINE(NO_GETTOD)))
AC_MSG_CHECKING([for gettimeofday declaration])
AC_EGREP_HEADER(gettimeofday, sys/time.h, AC_MSG_RESULT(present), [
    AC_MSG_RESULT(missing)
    AC_DEFINE(GETTOD_NOT_DECLARED)
])


#--------------------------------------------------------------------
#	See if we have a function prototype for gethostname
#--------------------------------------------------------------------
AC_MSG_CHECKING([for gethostname declaration])
AC_EGREP_HEADER(gethostname, unistd.h, AC_MSG_RESULT(present), [
    AC_MSG_RESULT(missing)
    AC_DEFINE(GETHOSTNAME_NOT_DECLARED)
])

#--------------------------------------------------------------------
#	See if we have boolean_t
#--------------------------------------------------------------------
AC_MSG_CHECKING([for boolean_t])
AC_EGREP_HEADER(boolean_t, sys/types.h, AC_MSG_RESULT(yes), [
    AC_MSG_RESULT(no)
    AC_DEFINE(NO_BOOLEAN_T)
])

#--------------------------------------------------------------------
#	The check below checks 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([union wait])
AC_TRY_LINK([#include <sys/types.h> 
#include <sys/wait.h>], [
union wait x;
WIFEXITED(x);		/* Generates compiler error if WIFEXITED
			 * uses an int. */
], tcl_ok=yes, tcl_ok=no)
AC_MSG_RESULT($tcl_ok)
if test $tcl_ok = no; then
    AC_DEFINE(NO_UNION_WAIT)
fi

#--------------------------------------------------------------------
#	Check to see whether the system supports the matherr function
#	and its associated type "struct exception".
#--------------------------------------------------------------------

AC_MSG_CHECKING([matherr support])
AC_TRY_COMPILE([#include <math.h>], [
struct exception x;
x.type = DOMAIN;
x.type = SING;
], tcl_ok=yes, tcl_ok=no)
AC_MSG_RESULT($tcl_ok)
if test $tcl_ok = yes; then
    AC_DEFINE(NEED_MATHERR)
fi

#--------------------------------------------------------------------
#	The statements below define a collection of symbols related to
#	dynamic loading and shared libraries:
#
#	DL_OBJS -	Name of the object file that implements dynamic
#			loading for Tcl on this system.
#	DL_LIBS -	Library file(s) to include in tclsh and other base
#			applications in order for the "load" command to work.
#	LD_FLAGS -	Flags to pass to the compiler when linking object
#			files into an executable application binary such
#			as tclsh.
#	LD_SEARCH_FLAGS-Flags to pass to ld, such as "-R /usr/local/tcl/lib",
#			that tell the run-time dynamic linker where to look
#			for shared libraries such as libagrand.so.  Depends on
#			the variable LIB_INSTALL_DIR in the Makefile.
#	MAKE_LIB -	Command to execute to build the Tcl library;
#			differs depending on whether or not Tcl is being
#			compiled as a shared library.
#	SHLIB_CFLAGS -	Flags to pass to cc when compiling the components
#			of a shared library (may request position-independent
#			code, among other things).
#	SHLIB_LD -	Base command to use for combining object files
#			into a shared library.
#	SHLIB_LD_LIBS -	Dependent libraries for the linker to scan when
#			creating shared libraries.  This symbol typically
#			goes at the end of the "ld" commands that build
#			shared libraries. The value of the symbol is
#			"${LIBS}" if all of the dependent libraries should
#			be specified when creating a shared library.  If
#			dependent libraries should not be specified (as on
#			SunOS 4.x, where they cause the link to fail, or in
#			general if Tcl and Tk aren't themselves shared
#			libraries), then this symbol has an empty string
#			as its value.
#	SHLIB_SUFFIX -	Suffix to use for the names of dynamically loadable
#			extensions.  An empty string means we don't know how
#			to use shared libraries on this platform.
#	LIB_FILE -	Name of the file that contains the Tcl library, such
#			as libagrand7.5.so or libagrand7.5.a.
#	LIB_SUFFIX -Specifies everything that comes after the "libagrand"
#			in the shared library name, using the $VERSION variable
#			to put the version in the right place.  This is used
#			by platforms that need non-standard library names.
#			Examples:  ${VERSION}.so.1.1 on NetBSD, since it needs
#			to have a version after the .so, and ${VERSION}.a
#			on AIX, since the Tcl shared library needs to have
#			a .a extension whereas shared objects for loadable
#			extensions have a .so extension.  Defaults to
#			${VERSION}${SHLIB_SUFFIX}.
#--------------------------------------------------------------------

# Step 1: set the variable "system" to hold the name and version number
# for the system.  This can usually be done via the "uname" command, but
# there are a few systems, like Next, where this doesn't work.

AC_MSG_CHECKING([system version (for dynamic loading)])
if test -f /usr/lib/NextStep/software_version; then
    system=NEXTSTEP-`awk '/3/,/3/' /usr/lib/NextStep/software_version`
else
    system=`uname -s`-`uname -r`
    if test "$?" -ne 0 ; then
	AC_MSG_RESULT([unknown (can't find uname command)])
	system=unknown
    else
	# Special check for weird MP-RAS system (uname returns weird
	# results, and the version is kept in special file).
    
	if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
	    system=MP-RAS-`awk '{print $3}' /etc/.relid'`
	fi
	if test "`uname -s`" = "AIX" ; then
	    system=AIX-`uname -v`.`uname -r`
	fi
	AC_MSG_RESULT($system)
    fi
fi

# Step 2: check for existence of -ldl library.  This is needed because
# Linux can use either -ldl or -ldld for dynamic loading.

AC_CHECK_LIB(dl, dlopen, have_dl=yes, have_dl=no)

# Step 3: disable dynamic loading if requested via a command-line switch.

AC_ARG_ENABLE(load, [  --disable-load          disallow dynamic loading and "load" command],
    [tcl_ok=$enableval], [tcl_ok=yes])
if test "$tcl_ok" = "no"; then
    system=unknown
fi

# Step 4: set configuration options based on system name and version.
# We are doing both the PGP flags and the shared library flags.

fullSrcDir=`cd $srcdir; pwd`
AIX=no
BSD_LIBS=""
SHARED_LIB_SUFFIX=""
UNSHARED_LIB_SUFFIX=""
LIB_VERSIONS_OK=ok
case $system in
    AIX-*)
	# we need -lbsd
	BSD_LIBS="-lbsd"
	# PGP
	PGP_FLAGS="-DUNIX=1 -DPORTABLE=1 -DNOTERMIO=1 -DMODERN=1 -DHIGHFIRST=1 -DIDEA32=1"
	# shared libraries
	SHLIB_CFLAGS=""
	SHLIB_LD="$fullSrcDir/ldAix /bin/ld -bhalt:4 -bM:SRE -bE:lib.exp -H512 -T512"
	SHLIB_LD_LIBS='${LIBS}'
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o tclLoadAix.o"
	DL_LIBS="-lld"
	LD_FLAGS=""
	LD_SEARCH_FLAGS='-L${LIB_INSTALL_DIR}'
	AC_DEFINE(NO_DLFCN_H)
	AIX=yes
	SHARED_LIB_SUFFIX='${VERSION}.a'
	SHARED_LINK_SUFFIX='.a'
	;;
    HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*)
	# PGP
	PGP_FLAGS="-DUNIX=1 -DPORTABLE=1 -DHIGHFIRST=1 -DUSE_SELECT=1 -DIDEA32=1"
	# shared libraries
	SHLIB_CFLAGS="+z"
	SHLIB_LD="ld -b"
	SHLIB_LD_LIBS='${LIBS}'
	SHLIB_SUFFIX=".sl"
	DL_OBJS="tclLoadShl.o"
	DL_LIBS="-ldld"
	LD_FLAGS="-Wl,-E"
	LD_SEARCH_FLAGS='-Wl,+b,${LIB_INSTALL_DIR}:.'
	;;
    IRIX-4.*)
	# PGP
	PGP_FLAGS=""
	# shared libraries
	SHLIB_CFLAGS="-G 0"
	SHLIB_SUFFIX="..o"
	SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0"
	SHLIB_LD_LIBS=""
	DL_OBJS="tclLoadAout.o"
	DL_LIBS=""
	LD_FLAGS="-Wl,-D,08000000"
	LD_SEARCH_FLAGS=""
	;;
    IRIX-5.*)
	# PGP
	PGP_FLAGS="-DUNIX=1 -DPORTABLE=1 -DUSE_NBIO=1 -DHIGHFIRST=1"
	# shared libraries
	SHLIB_CFLAGS=""
	SHLIB_LD="ld -shared -rdata_shared"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS=""
	LD_FLAGS=""
	LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_INSTALL_DIR}'
	;;
    IRIX-6.*|IRIX64-6*)
	# PGP
	PGP_FLAGS="-DUNIX=1 -DPORTABLE=1 -DUSE_NBIO=1 -DHIGHFIRST=1"
	# shared libraries
	SHLIB_CFLAGS=""
	SHLIB_LD="ld -shared -rdata_shared"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS=""
	LD_FLAGS=""
	LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_INSTALL_DIR}'
	;;
    Linux*)
	# platform
	machine=`uname -m`
	case $machine in
	  i386|i486|i586|i686)
	    AC_DEFINE(LINUX_I386_PLATFORM)
	    ;;
	esac
	# PGP
	PGP_FLAGS="-DUNIX=1 -DPORTABLE=1 -DIDEA32=1"
	# shared libraries
	SHLIB_CFLAGS="-fPIC"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	if test "$have_dl" = yes; then
	    SHLIB_LD="${CC} -shared"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    LD_FLAGS="-rdynamic"
	    LD_SEARCH_FLAGS=""
	else
	    AC_CHECK_HEADER(dld.h, [
		SHLIB_LD="ld -shared"
		DL_OBJS="tclLoadDld.o"
		DL_LIBS="-ldld"
		LD_FLAGS=""
		LD_SEARCH_FLAGS=""])
	fi
	;;
    MP-RAS-02*)
	# PGP
	PGP_FLAGS=""
	# shared libraries
	SHLIB_CFLAGS="-K PIC"
	SHLIB_LD="cc -G"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS="-ldl"
	LD_FLAGS=""
	LD_SEARCH_FLAGS=""
	;;
    MP-RAS-*)
	# PGP
	PGP_FLAGS=""
	# shared libraries
	SHLIB_CFLAGS="-K PIC"
	SHLIB_LD="cc -G"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS="-ldl"
	LD_FLAGS="-Wl,-Bexport"
	LD_SEARCH_FLAGS=""
	;;
    NetBSD-*|FreeBSD-*)
	# PGP
	PGP_FLAGS="-DUNIX=1 -DPORTABLE=1 -DIDEA32=1 -DMAX_NAMELEN=255"
	# shared libraries
	# Not available on all versions:  check for include file.
	AC_CHECK_HEADER(dlfcn.h, [
	    SHLIB_CFLAGS="-fpic"
	    SHLIB_LD="ld -Bshareable"
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl2.o"
	    DL_LIBS=""
	    LD_FLAGS=""
	    LD_SEARCH_FLAGS=""
	], [
	    SHLIB_CFLAGS=""
	    SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0"
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX="..o"
	    DL_OBJS="tclLoadAout.o"
	    DL_LIBS=""
	    LD_FLAGS=""
	    LD_SEARCH_FLAGS=""
	])

	# FreeBSD doesn't handle version numbers with dots.  Also, have to
	# append a dummy version number to .so file names.

	SHARED_LIB_SUFFIX='`echo ${VERSION} | tr -d .`.so.1.0'
	SHARED_LINK_SUFFIX='.so'
	UNSHARED_LIB_SUFFIX='`echo ${VERSION} | tr -d .`.a'
	UNSHARED_LINK_SUFFIX='.a'
	LIB_VERSIONS_OK=nodots
	;;
    NEXTSTEP-*)
	# PGP
	PGP_FLAGS=""
	# shared libraries
	# Not available on all versions:  check for include file.
	SHLIB_CFLAGS=""
	SHLIB_LD="cc -nostdlib -r"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadNext.o"
	DL_LIBS=""
	LD_FLAGS=""
	LD_SEARCH_FLAGS=""
	;;
    OSF1-1.[012])
	# PGP
	PGP_FLAGS=""
	# shared libraries
	# OSF/1 1.[012] from OSF, and derivatives, including Paragon OSF/1
	SHLIB_CFLAGS=""
	# Hack: make package name same as library name
	SHLIB_LD='ld -R -export $@:'
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadOSF.o"
	DL_LIBS=""
	LD_FLAGS=""
	LD_SEARCH_FLAGS=""
	;;
    OSF1-1.*)
	# PGP
	PGP_FLAGS=""
	# shared libraries
	# OSF/1 1.3 from OSF using ELF, and derivatives, including AD2
	SHLIB_CFLAGS="-fpic"
	SHLIB_LD="ld -shared"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS=""
	LD_FLAGS=""
	LD_SEARCH_FLAGS=""
	;;
    OSF1-V*)
	# PGP
	PGP_FLAGS="-D_BSD -DUNIX=1 -DPORTABLE=1 -DNOTERMIO=1"
	# shared libraries
        # Digital OSF/1
	SHLIB_CFLAGS=""
	SHLIB_LD='ld -shared -expect_unresolved "*"'
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS=""
	LD_FLAGS=""
	LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_INSTALL_DIR}'
	;;
    RISCos-*)
	# PGP
	PGP_FLAGS=""
	# shared libraries
	SHLIB_CFLAGS="-G 0"
	SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX="..o"
	DL_OBJS="tclLoadAout.o"
	DL_LIBS=""
	LD_FLAGS="-Wl,-D,08000000"
	LD_SEARCH_FLAGS=""
	;;
    SCO_SV-3.2*)
	# PGP
	PGP_FLAGS=""
	# shared libraries
        # Note, dlopen is available only on SCO 3.2.5 and greater.  However,
        # this test works, since "uname -s" was non-standard in 3.2.4 and
        # below.
	SHLIB_CFLAGS="-Kpic -belf"
	SHLIB_LD="ld -G"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS=""
	LD_FLAGS="-belf -Wl,-Bexport"
	LD_SEARCH_FLAGS=""
	;;
     SINIX*5.4*)
	# PGP
	PGP_FLAGS=""
	# shared libraries
	SHLIB_CFLAGS="-K PIC"
	SHLIB_LD="cc -G"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS="-ldl"
	LD_FLAGS=""
	LD_SEARCH_FLAGS=""
	;;
    SunOS-4*)
	# PGP
	PGP_FLAGS="-DUNIX=1 -DPORTABLE=1 -DHIGHFIRST=1 -DIDEA32=1"
	# shared libraries
	SHLIB_CFLAGS="-PIC"
	SHLIB_LD="ld"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS="-ldl"
	LD_FLAGS=""
	LD_SEARCH_FLAGS='-L${LIB_INSTALL_DIR}'

	# SunOS can't handle version numbers with dots in them in library
	# specs, like -ltcl7.5, so use -ltcl75 instead.  Also, it
	# requires an extra version number at the end of .so file names.
	# So, the library has to have a name like libagrand75.so.1.0

	SHARED_LIB_SUFFIX='`echo ${VERSION} | tr -d .`.so.1.0'
	SHARED_LINK_SUFFIX='.so'
	UNSHARED_LIB_SUFFIX='`echo ${VERSION} | tr -d .`.a'
	UNSHARED_LINK_SUFFIX='.a'
	LIB_VERSIONS_OK=nodots
	;;
    SunOS-5*)
	# PGP
	PGP_FLAGS="-DSOLARIS -DUNIX=1 -DPORTABLE=1 -DHIGHFIRST=1 -DIDEA32=1"
	# shared libraries
	SHLIB_CFLAGS="-KPIC"
	SHLIB_LD="/usr/ccs/bin/ld -G -z text"
	SHLIB_LD_LIBS='${LIBS}'
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS="-ldl"
	LD_FLAGS=""
	LD_SEARCH_FLAGS='-R ${LIB_INSTALL_DIR}'
	;;
    ULTRIX-4.*)
	# PGP
	PGP_FLAGS="-DUNIX=1 -DPORTABLE=1 -DUSE_SELECT=1 -DIDEA32=1"
	# shared libraries
	SHLIB_CFLAGS="-G 0"
	SHLIB_SUFFIX="..o"
	SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0"
	SHLIB_LD_LIBS=""
	DL_OBJS="tclLoadAout.o"
	DL_LIBS=""
	LD_FLAGS="-Wl,-D,08000000"
	LD_SEARCH_FLAGS=""
	;;
    UNIX_SV*)
	# PGP
	PGP_FLAGS=""
	# shared libraries
	SHLIB_CFLAGS="-K PIC"
	SHLIB_LD="cc -G"
	SHLIB_LD_LIBS=""
	SHLIB_SUFFIX=".so"
	DL_OBJS="tclLoadDl.o"
	DL_LIBS="-ldl"
	LD_FLAGS="-Wl,-Bexport"
	LD_SEARCH_FLAGS=""
	;;
esac

AC_MSG_CHECKING(if we can compile the random bits library)

if test "x$PGP_FLAGS" = "x"; then
    AC_MSG_RESULT(no);
    echo ""
    echo "FATAL ERROR: don't know how to compile the random bits library"
    echo "on this machine.  Please contact rgray@cs.dartmouth.edu with a"
    echo "description of your machine and its operating system."
    echo ""
    exit 1
fi

AC_MSG_RESULT(yes);

# If pseudo-static linking is in use (see K. B. Kenny, "Dynamic Loading for
# Tcl -- What Became of It?".  Proc. 2nd Tcl/Tk Workshop, New Orleans, LA,
# Computerized Processes Unlimited, 1994), then we need to determine which
# of several header files defines the a.out file format (a.out.h, sys/exec.h,
# or sys/exec_aout.h).  At present, we support only a file format that
# is more or less version-7-compatible.  In particular,
#	- a.out files must begin with `struct exec'.
#	- the N_TXTOFF on the `struct exec' must compute the seek address
#	  of the text segment
#	- The `struct exec' must contain a_magic, a_text, a_data, a_bss
#	  and a_entry fields.
# The following compilation should succeed if and only if either sys/exec.h
# or a.out.h is usable for the purpose.
#
# Note that the modified COFF format used on MIPS Ultrix 4.x is usable; the
# `struct exec' includes a second header that contains information that
# duplicates the v7 fields that are needed.

if test "x$DL_OBJS" = "xtclLoadAout.o" ; then
    AC_MSG_CHECKING(sys/exec.h)
    AC_TRY_COMPILE([#include <sys/exec.h>],[
	struct exec foo;
	unsigned long seek;
	int flag;
#if defined(__mips) || defined(mips)
	seek = N_TXTOFF (foo.ex_f, foo.ex_o);
#else
	seek = N_TXTOFF (foo);
#endif
	flag = (foo.a_magic == OMAGIC);
	return foo.a_text + foo.a_data + foo.a_bss + foo.a_entry;
], tcl_ok=usable, tcl_ok=unusable)
    AC_MSG_RESULT($tcl_ok)
    if test $tcl_ok = usable; then
	AC_DEFINE(USE_SYS_EXEC_H)
    else
	AC_MSG_CHECKING(a.out.h)
	AC_TRY_COMPILE([#include <a.out.h>],[
	    struct exec foo;
	    unsigned long seek;
	    int flag;
#if defined(__mips) || defined(mips)
	    seek = N_TXTOFF (foo.ex_f, foo.ex_o);
#else
	    seek = N_TXTOFF (foo);
#endif
	    flag = (foo.a_magic == OMAGIC);
	    return foo.a_text + foo.a_data + foo.a_bss + foo.a_entry;
	], tcl_ok=usable, tcl_ok=unusable)
	AC_MSG_RESULT($tcl_ok)
	if test $tcl_ok = usable; then
	    AC_DEFINE(USE_A_OUT_H)
	else
	    AC_MSG_CHECKING(sys/exec_aout.h)
	    AC_TRY_COMPILE([#include <sys/exec_aout.h>],[
		struct exec foo;
		unsigned long seek;
		int flag;
#if defined(__mips) || defined(mips)
		seek = N_TXTOFF (foo.ex_f, foo.ex_o);
#else
		seek = N_TXTOFF (foo);
#endif
		flag = (foo.a_midmag == OMAGIC);
		return foo.a_text + foo.a_data + foo.a_bss + foo.a_entry;
	    ], tcl_ok=usable, tcl_ok=unusable)
	    AC_MSG_RESULT($tcl_ok)
	    if test $tcl_ok = usable; then
		AC_DEFINE(USE_SYS_EXEC_AOUT_H)
	    else
		DL_OBJS=""
	    fi
	fi
    fi
fi

if test "x$DL_OBJS" != "x" ; then
    BUILD_DLTEST="\$(DLTEST_TARGETS)"
else
    echo "Can't figure out how to do dynamic loading or shared libraries"
    echo "on this system."
    SHLIB_CFLAGS=""
    SHLIB_LD=""
    SHLIB_SUFFIX=""
    DL_OBJS="tclLoadNone.o"
    DL_LIBS=""
    LD_FLAGS=""
    LD_SEARCH_FLAGS=""
    BUILD_DLTEST=""
fi

# If we're running gcc, then change the C flags for compiling shared
# libraries to the right flags for gcc, instead of those for the
# standard manufacturer compiler.

if test "$DL_OBJS" != "tclLoadNone.o" ; then
    if test "$CC" = "gcc" -o `$CC -v 2>&1 | grep -c gcc` != "0" ; then
	SHLIB_CFLAGS="-fPIC"
	SHLIB_LD="$CC -shared"
    fi
fi

#--------------------------------------------------------------------
#	The statements below define a collection of symbols related to
#	building a shared library instead of a static library.
#--------------------------------------------------------------------

realRanlib=$RANLIB
if test "$SHARED_LIB_SUFFIX" = "" ; then
    SHARED_LIB_SUFFIX='${VERSION}${SHLIB_SUFFIX}'
    SHARED_LINK_SUFFIX='${SHLIB_SUFFIX}'
fi
if test "$UNSHARED_LIB_SUFFIX" = "" ; then
    UNSHARED_LIB_SUFFIX='${VERSION}.a'
    UNSHARED_LINK_SUFFIX='.a'
fi
AC_ARG_ENABLE(shared,
    [  --enable-shared         build a shared library],
    [tcl_ok=$enableval], [tcl_ok=no])
if test "$tcl_ok" = "yes" -a "${SHLIB_SUFFIX}" != "" \
	-a "${DL_OBJS}" != "tclLoadAout.o" ; then
    SHLIB_CFLAGS="${SHLIB_CFLAGS}"
    LD_SEARCH_FLAGS="${LD_SEARCH_FLAGS}"
    eval "LIB_FILE=lib\\\${LIBMIDDLE}${SHARED_LIB_SUFFIX}"
    eval "LINK_FILE=lib\\\${LIBMIDDLE}${SHARED_LINK_SUFFIX}"
    eval "LIB_FILE1=lib\\\${LIBMIDDLE1}${SHARED_LIB_SUFFIX}"
    eval "LINK_FILE1=\\\${LIBMIDDLE1}${SHARED_LINK_SUFFIX}"
    eval "LIB_FILE2=lib\\\${LIBMIDDLE2}${SHARED_LIB_SUFFIX}"
    eval "LINK_FILE2=\\\${LIBMIDDLE2}${SHARED_LINK_SUFFIX}"
    eval "LIB_FILE3=lib\\\${LIBMIDDLE3}${SHARED_LIB_SUFFIX}"
    eval "LINK_FILE3=\\\${LIBMIDDLE3}${SHARED_LINK_SUFFIX}"
    MAKE_LIB="\${SHLIB_LD} \${MAKELIB_FLAGS} -o \${LIB_FILE} \${OBJS} ${SHLIB_LD_LIBS}"
    MAKE_LIB1="\${SHLIB_LD} \${MAKELIB_FLAGS} -o \${LIB_FILE1} \${OBJS1} ${SHLIB_LD_LIBS}"
    MAKE_LIB2="\${SHLIB_LD} \${MAKELIB_FLAGS} -o \${LIB_FILE2} \${OBJS2} ${SHLIB_LD_LIBS}"
    MAKE_LIB3="\${SHLIB_LD} \${MAKELIB_FLAGS} -o \${LIB_FILE3} \${OBJS3} ${SHLIB_LD_LIBS}"
    RANLIB=":"
else
    if test "$AIX" = "no" ; then
	SHLIB_LD_LIBS=""
    fi
    SHLIB_CFLAGS=""
    LD_SEARCH_FLAGS=""
    eval "LIB_FILE=lib\\\${LIBMIDDLE}${UNSHARED_LIB_SUFFIX}"
    eval "LINK_FILE=lib\\\${LIBMIDDLE}${UNSHARED_LINK_SUFFIX}"
    eval "LIB_FILE1=lib\\\${LIBMIDDLE1}${UNSHARED_LIB_SUFFIX}"
    eval "LINK_FILE1=\\\${LIBMIDDLE1}${UNSHARED_LINK_SUFFIX}"
    eval "LIB_FILE2=lib\\\${LIBMIDDLE2}${UNSHARED_LIB_SUFFIX}"
    eval "LINK_FILE2=\\\${LIBMIDDLE2}${UNSHARED_LINK_SUFFIX}"
    eval "LIB_FILE3=lib\\\${LIBMIDDLE3}${UNSHARED_LIB_SUFFIX}"
    eval "LINK_FILE3=\\\${LIBMIDDLE3}${UNSHARED_LINK_SUFFIX}"
    MAKE_LIB="ar cr \${LIB_FILE} \${OBJS}"
    MAKE_LIB1="ar cr \${LIB_FILE} \${OBJS1}"
    MAKE_LIB2="ar cr \${LIB_FILE} \${OBJS2}"
    MAKE_LIB3="ar cr \${LIB_FILE} \${OBJS3}"
fi

if test "${LIB_VERSIONS_OK}" = "ok"; then
    VERSION_SUFFIX="${VERSION}"
    TCL_VERSION_SUFFIX="${TCL_VERSION}"
    TK_VERSION_SUFFIX="${TK_VERSION}"
    SCHEME_VERSION_SUFFIX="${SCHEME_VERSION}"
else
    VERSION_SUFFIX="`echo ${VERSION} | tr -d .`"
    TCL_VERSION_SUFFIX="`echo ${TCL_VERSION} | tr -d .`"
    TK_VERSION_SUFFIX="`echo ${TK_VERSION} | tr -d .`"
    SCHEME_VERSION_SUFFIX="`echo ${SCHEME_VERSION} | tr -d .`"
fi

LIBS="$CXX_LIBS $BSD_LIBS $LIBS -lc"

AC_SUBST(VERSION)
AC_SUBST(PGP_FLAGS)
AC_SUBST(LIB_VERSIONS_OK)
AC_SUBST(VERSION_SUFFIX)
AC_SUBST(TCL_VERSION_SUFFIX) 
AC_SUBST(TK_VERSION_SUFFIX)
AC_SUBST(SCHEME_VERSION_SUFFIX)
AC_SUBST(BUILD_DLTEST)
AC_SUBST(DL_LIBS)
AC_SUBST(DL_OBJS)
AC_SUBST(LD_FLAGS)
AC_SUBST(MAKE_LIB)
AC_SUBST(MAKE_LIB1)
AC_SUBST(MAKE_LIB2)
AC_SUBST(MAKE_LIB3)
AC_SUBST(MATH_LIBS)
AC_SUBST(SHLIB_CFLAGS)
AC_SUBST(SHLIB_LD)
AC_SUBST(SHLIB_LD_LIBS)
AC_SUBST(SHLIB_SUFFIX)
AC_SUBST(LD_SEARCH_FLAGS)
AC_SUBST(LIB_FILE)
AC_SUBST(LIB_FILE1)
AC_SUBST(LIB_FILE2)
AC_SUBST(LIB_FILE3)
AC_SUBST(LINK_FILE)
AC_SUBST(LINK_FILE1)
AC_SUBST(LINK_FILE2)
AC_SUBST(LINK_FILE3)
AC_SUBST(LIB_VERSIONS_OK)
AC_SUBST(SHARED_LIB_SUFFIX)
AC_SUBST(UNSHARED_LIB_SUFFIX)

#--------------------------------------------------------------------
#   Output the Makefile
#--------------------------------------------------------------------

if test "x${outputfile}" = "x"; then
    echo ""
    echo "ERROR:"
    echo ""
    echo "must set environment variable \"outputfile\" when running configure"
    echo "outside the makefile"
    echo ""
    exit 1
fi
AC_OUTPUT(${outputfile})
