dnl
dnl Process this file with autoconf to produce a configure script.
dnl
AC_REVISION($Id: configure.in,v 1.23 2001/08/21 05:51:33 tcl Exp $)

#--------------------------------------------------------------------
# Configure script for package 'trf', as distributed at August 20, 2001.
# TEA compliant.
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# This very first macro is used to verify that the configure script can 
# find the sources.  The argument to AC_INIT is a unique filename for
# this package.
#--------------------------------------------------------------------

AC_INIT(./generic/transform.h)

#--------------------------------------------------------------------
# Setting our package name and version numbers.  The NODOT_VERSION is
# required for constructing the library name on systems that don't like
# dots in library names (Windows).  The VERSION variable is used on the
# other systems.
#--------------------------------------------------------------------

PACKAGE=Trf

MAJOR_VERSION=2
MINOR_VERSION=1
PATCHLEVEL=

VERSION=${MAJOR_VERSION}.${MINOR_VERSION}${PATCHLEVEL}
NODOT_VERSION=${MAJOR_VERSION}${MINOR_VERSION}
TRF_VERSION=${MAJOR_VERSION}.${MINOR_VERSION}

AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
AC_SUBST(TRF_VERSION)

#--------------------------------------------------------------------
# This was placed here so that we can compile with -DVERSION="1.2" to
# encode the package version directly into the source files.
#--------------------------------------------------------------------

eval AC_DEFINE_UNQUOTED(VERSION, "${VERSION}")
eval AC_DEFINE_UNQUOTED(TRF_VERSION, "${TRF_VERSION}")

#--------------------------------------------------------------------
# Checks whether --enable-gcc or --disable-gcc was given.  This is done
# before AC_CYGWIN is called so the compiler can be fully tested by
# built-in autoconf tools. This macro also calls AC_PROG_CC to set
# the compiler if --enable-gcc was not used.
#--------------------------------------------------------------------

SC_ENABLE_GCC
AC_PROG_INSTALL

#--------------------------------------------------------------------
# Checks to see if the make program sets the $MAKE variable.
#--------------------------------------------------------------------

AC_PROG_MAKE_SET

#--------------------------------------------------------------------
# Find ranlib (sometimes required to postprocess library archives)
#--------------------------------------------------------------------

AC_PROG_RANLIB

#--------------------------------------------------------------------
# This macro performs additional compiler tests.
#--------------------------------------------------------------------

AC_CYGWIN

#--------------------------------------------------------------------
# Determines the correct binary file extension (.o, .obj, .exe etc.)
#--------------------------------------------------------------------

AC_OBJEXT
AC_EXEEXT
AC_C_BIGENDIAN

#--------------------------------------------------------------------
# If ltoa is present, use it to convert integer values into strings.
# If not, sprintf is used, which is slower and requires more code.
#--------------------------------------------------------------------

AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long int)
AC_CHECK_FUNCS(ltoa)
AC_CHECK_LIB(crypt, main,         HAS_LIBCRYPT=1,     HAS_LIBCRYPT=0)
AC_CHECK_LIB(crypt, md5_init_ctx, HAS_LIBCRYPT_MD5=1, HAS_LIBCRYPT_MD5=0)

#--------------------------------------------------------------------
# "cygpath" is used on windows to generate native path names for include
# files. These variables should only be used with the compiler and linker
# since they generate native path names.
#
# Unix tclConfig.sh points SRC_DIR at the top-level directory of
# the Tcl sources, while the Windows tclConfig.sh points SRC_DIR at
# the win subdirectory.  Hence the different usages of SRC_DIR below.
#
# This must be done before calling SC_PUBLIC_TCL_HEADERS
#--------------------------------------------------------------------

case "`uname -s`" in
    *win32* | *WIN32* | *CYGWIN_NT* | *CYGWIN_98* | *CYGWIN_95*)
	CYGPATH="cygpath -w"
    ;;
    *)
	CYGPATH=echo
    ;;
esac

AC_SUBST(CYGPATH)

#--------------------------------------------------------------------
# This extensions currently relies only on the Tcl public header files.
# This MUST be called before SC_PATH_TCLCONFIG/SC_LOAD_TCLCONFIG
#--------------------------------------------------------------------

case "`uname -s`" in
    *win32* | *WIN32* | *CYGWIN_NT* | *CYGWIN_98* | *CYGWIN_95*)
	# On windows tclLoadWin.c depends on internal headers. Darn.
	SC_PRIVATE_TCL_HEADERS
    ;;
    *)
	# Everywhere else we can stick with the public ones.
	SC_PUBLIC_TCL_HEADERS
    ;;
esac


#--------------------------------------------------------------------
# Load the tclConfig.sh file
#--------------------------------------------------------------------

SC_PATH_TCLCONFIG
SC_LOAD_TCLCONFIG

#--------------------------------------------------------------------
# A few miscellaneous platform-specific items:
#
# We have to define a special symbol for Windows (BUILD_Trf in this
# case) so that we create the export library with the dll.
#
# Windows creates a few extra files that need to be cleaned up.
# We can add more files to clean if our extension creates any extra
# files in the future.
#
# Define any extra compiler flags in the PACKAGE_CFLAGS variable.
# These will be appended to the current set of compiler flags for
# your system.
#--------------------------------------------------------------------

case "`uname -s`" in
    *win32* | *WIN32* | *CYGWIN_NT* | *CYGWIN_98* | *CYGWIN_95*)
	AC_DEFINE(BUILD_Trf)
	CLEANFILES="*.lib *.dll *.exp *.ilk *.pdb vc50.pch"
	AC_SUBST(CLEANFILES)
    ;;
    *)
	CLEANFILES=
    ;;
esac

#CLEANFILES="${CLEANFILES} <<...>>"

#--------------------------------------------------------------------
# Check whether --enable-threads or --disable-threads was given.
# So far only Tcl responds to this one.
#--------------------------------------------------------------------

SC_ENABLE_THREADS

#--------------------------------------------------------------------
# The statement below defines a collection of symbols related to
# building as a shared library instead of a static library.
#--------------------------------------------------------------------

SC_ENABLE_SHARED

#--------------------------------------------------------------------
# This macro figures out what flags to use with the compiler/linker
# when building shared/static debug/optimized objects.  This information
# is all taken from the tclConfig.sh file.
#--------------------------------------------------------------------

CFLAGS_DEBUG=${TCL_CFLAGS_DEBUG}
CFLAGS_OPTIMIZE=${TCL_CFLAGS_OPTIMIZE}
LDFLAGS_DEBUG=${TCL_LDFLAGS_DEBUG}
LDFLAGS_OPTIMIZE=${TCL_LDFLAGS_OPTIMIZE}
SHLIB_LD=${TCL_SHLIB_LD}
STLIB_LD=${TCL_STLIB_LD}
SHLIB_CFLAGS=${TCL_SHLIB_CFLAGS}

AC_SUBST(CFLAGS_DEBUG)
AC_SUBST(CFLAGS_OPTIMIZE)
AC_SUBST(STLIB_LD)
AC_SUBST(SHLIB_LD)
AC_SUBST(SHLIB_CFLAGS)
AC_SUBST(SHLIB_LDFLAGS)

#--------------------------------------------------------------------
# Set the default compiler switches based on the --enable-symbols 
# option.
#--------------------------------------------------------------------

SC_ENABLE_SYMBOLS

if test "${SHARED_BUILD}" = "1" ; then
    CFLAGS='${CFLAGS_DEFAULT} ${CFLAGS_WARNING} ${SHLIB_CFLAGS}'
else
    CFLAGS='${CFLAGS_DEFAULT} ${CFLAGS_WARNING}'
fi

#--------------------------------------------------------------------
# Everyone should be linking against the Tcl stub library.  If you
# can't for some reason, remove this definition.  If you aren't using
# stubs, you also need to modify the SHLIB_LD_LIBS setting below to
# link against the non-stubbed Tcl library.
#--------------------------------------------------------------------

AC_DEFINE(USE_TCL_STUBS)

#--------------------------------------------------------------------
# This macro generates a line to use when building a library.  It
# depends on values set by the SC_ENABLE_SHARED, SC_ENABLE_SYMBOLS,
# and SC_LOAD_TCLCONFIG macros above.
#--------------------------------------------------------------------

SC_MAKE_LIB

#--------------------------------------------------------------------
# eval these two values to dereference the ${DBGX} variable.
#--------------------------------------------------------------------

eval "SHARED_LIB_SUFFIX=${TCL_SHARED_LIB_SUFFIX}"
eval "UNSHARED_LIB_SUFFIX=${TCL_UNSHARED_LIB_SUFFIX}"

#--------------------------------------------------------------------
# Shared libraries and static libraries have different names.
#--------------------------------------------------------------------

case "`uname -s`" in
    *win32* | *WIN32* | *CYGWIN_NT* | *CYGWIN_98* | *CYGWIN_95*)
	if test "${SHARED_BUILD}" = "1" ; then
	    SHLIB_LD_LIBS="\"`cygpath -w ${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}`\" ${TCL_SHLIB_LD_LIBS}"
	    eval "${PACKAGE}_LIB_FILE=${PACKAGE}${SHARED_LIB_SUFFIX}"
	    eval "${PACKAGE}_STUB_LIB_FILE=${PACKAGE}stub${UNSHARED_LIB_SUFFIX}"
	    RANLIB=:
	else
	    eval "${PACKAGE}_LIB_FILE=${PACKAGE}${UNSHARED_LIB_SUFFIX}"
	    eval "${PACKAGE}_STUB_LIB_FILE=${PACKAGE}stub${UNSHARED_LIB_SUFFIX}"
	fi
	;;
    *)
	if test "${SHARED_BUILD}" = "1" ; then
	    SHLIB_LD_LIBS="${TCL_STUB_LIB_SPEC}"
	    eval "${PACKAGE}_LIB_FILE=lib${PACKAGE}${SHARED_LIB_SUFFIX}"
	    eval "${PACKAGE}_STUB_LIB_FILE=lib${PACKAGE}stub${UNSHARED_LIB_SUFFIX}"
	    RANLIB=:
	else
	    eval "${PACKAGE}_LIB_FILE=lib${PACKAGE}${UNSHARED_LIB_SUFFIX}"
	    eval "${PACKAGE}_STUB_LIB_FILE=lib${PACKAGE}stub${UNSHARED_LIB_SUFFIX}"
	fi
	;;
esac

#--------------------------------------------------------------------
# Define the variable to hold the name of the built shared library.
#--------------------------------------------------------------------

AC_SUBST(Trf_LIB_FILE)
AC_SUBST(Trf_STUB_LIB_FILE)
AC_SUBST(SHLIB_LD_LIBS)

#--------------------------------------------------------------------
# Find tclsh so that we can run pkg_mkIndex to generate the pkgIndex.tcl
# file during the install process.  Don't run the TCLSH_PROG through
# ${CYGPATH} because it's being used directly by make. Require that we
# use a tclsh shell version 8.2 or later since earlier versions have
# bugs in the pkg_mkIndex routine.
#--------------------------------------------------------------------

SC_PROG_TCLSH

#--------------------------------------------------------------------
# Check which of the loader modules we need to get at shared libraries dynamically

SHARED_LIBS=""
TEST_SUFFIX="${SHLIB_SUFFIX}"
if test "$DL_LIBS" = "-ldl"; then
    DL_OBJS=""
    dirs="/lib/libdl${TEST_SUFFIX}* /usr/lib/libdl${TEST_SUFFIX}*"
    for i in $dirs ; do
	if test -f $i; then
	    SHARED_LIBS="${SHARED_LIBS} -ldl"
	    break;
	fi
    done
elif test "$DL_LIBS" = "-ldld"; then
    if test "$SHLIB_SUFFIX" = ".sl"; then
	DL_OBJS="tclLoadShl.o"
    else
	DL_OBJS="tclLoadDld.o"
    fi
    dirs="/lib/libdld${TEST_SUFFIX}* /usr/lib/libdld${TEST_SUFFIX}*"
    for i in $dirs ; do
	if test -f $i; then
	    SHARED_LIBS="${SHARED_LIBS} -ldld"
	    break;
	fi
    done
elif test "$DL_LIBS" = "-lld"; then
    DL_OBJS="tclLoadAix.o"
    SHARED_LIBS="${TCL_LIB_SPEC} -lld"
    TEST_SUFFIX=".a"
elif test "$SHLIB_SUFFIX" = "..o" -o "$SHLIB_SUFFIX" = ".a"; then
    DL_OBJS="tclLoadAout.o"
    if test "x${SHLIB_CFLAGS}" = "x-G 0"; then
	TEST_SUFFIX="_G0.a"
    else
	TEST_SUFFIX=".a"
    fi
else
    DL_OBJS=""
fi

case "`uname -s`" in
    *win32* | *WIN32* | *CYGWIN_NT* | *CYGWIN_98* | *CYGWIN_95*)
	DL_OBJS="tclLoadWin.o"
    ;;
    *)
    ;;
esac

AC_SUBST(DL_OBJS)

TRF_FIND_ZLIB_SSL

#--------------------------------------------------------------------
# MD5 handling...
# Cases:
#	(1) libcrypt not present		=> compile, use that name.
#	(2) libcrypt present, contains Md5	=> nothing to do
#	(3) libcrypt present, no Md5		=> compile, name = libmd5crypt
#--------------------------------------------------------------------

MD5_LIB_FILE=""
if test \( $HAS_LIBCRYPT -eq 0 \)
then
	# (1)
	MD5_LIB_FILE=libcrypt$TCL_SHLIB_SUFFIX
	TRF_DEFS="$TRF_DEFS -DCRYPT_LIB_NAME=\\\"libcrypt$TCL_SHLIB_SUFFIX\\\""

	eval AC_DEFINE_UNQUOTED(CRYPT_LIB_NAME, "libcrypt$TCL_SHLIB_SUFFIX")
else
	# (2,3)
	if test \( $HAS_LIBCRYPT_MD5 -eq 0 \)
	then
		# (3)
		MD5_LIB_FILE=libmd5crypt$TCL_SHLIB_SUFFIX
		TRF_DEFS="$TRF_DEFS -DCRYPT_LIB_NAME=\\\"libmd5crypt$TCL_SHLIB_SUFFIX\\\""

		# Sun Solaris is special, we may not use -lcrypt !
		# Verified for: SunOS 5.5.1 (Solaris 2.5)
		#		SunOS 5.6   (Solaris 2.6)

		case "`uname -s`" in
		SunOS*)	;;
		*)	LIBS="-lcrypt $LIBS"
			SHLIB_LD_LIBS="-lcrypt $SHLIB_LD_LIBS"
			;;
		esac

		eval AC_DEFINE_UNQUOTED(CRYPT_LIB_NAME, "libmd5crypt$TCL_SHLIB_SUFFIX")
	fi
fi

AC_SUBST(MD5_LIB_FILE)

#--------------------------------------------------------------------
# Finally, substitute all of the various values into the Makefile.
#--------------------------------------------------------------------

AC_OUTPUT([Makefile mkIndex.tcl test.setup])

#--------------------------------------------------------------------

