dnl $Id: configure.in,v 1.1.2.1 2002/12/02 04:02:53 idiscovery Exp $
dnl	This file is an input file used by the GNU "autoconf" program to
dnl	generate the file "configure", which is run to configure the
dnl	Makefile in this directory.

AC_INIT(../../generic/tixInit.c)

#--------------------------------------------------------------------
#	Remove the ./config.cache file and rerun configure if
#	the cache file belong to a different architecture
#
#	This doesn't seem to work in the Cygnus environment,
#	it causes an error message about having more than
#	one target, so I disabled it.	meissner@cygnus.com
#----------------------------------------------------------------------
#AC_CHECK_PROG(UNAME, uname -a, [uname -a], "")
#if test "$UNAME" = ""; then
#    AC_CHECK_PROG(UNAME, uname, [uname], "")
#fi
#
#if test "$UNAME" != ""; then
#    uname=`$UNAME`
#    AC_MSG_CHECKING([cached value of \$uname])
#    AC_CACHE_VAL(ac_cv_prog_uname, [nocached=1 ac_cv_prog_uname=`$UNAME`])
#    if test "$nocached" = "1"; then
#	AC_MSG_RESULT(no)
#    else
#	AC_MSG_RESULT(yes)
#    fi
#
#    if test "$uname" != "$ac_cv_prog_uname"; then
#        echo "Running on a different machine/architecture. Can't use cached values"
#	echo "Removing config.cache and running configure again ..."
#	rm -f config.cache
#        CMDLINE="$0 $*"
#	exec $CMDLINE
#    fi
#fi

#----------------------------------------------------------------------
# We don't want to use any relative path because we need to generate
# Makefile's in subdirectories
#----------------------------------------------------------------------
if test "$INSTALL" = "./install.sh"; then
    INSTALL=`pwd`/install.sh
fi

#--------------------------------------------------------------------
#	Version information about this TIX release.
#--------------------------------------------------------------------

TIX_VERSION=8.1
TIX_MAJOR_VERSION=8
TIX_MINOR_VERSION=1

#--------------------------------------------------------------------
#	See if user wants to use gcc to compile Tix. This option must
#	be used before any checking that uses the C compiler.
#--------------------------------------------------------------------

AC_ARG_ENABLE(gcc, [  --enable-gcc            allow use of gcc if available],
    [tix_ok=$enableval], [tix_ok=no])
if test "$tix_ok" = "yes"; then
    AC_PROG_CC
else
    CC=${CC-cc}
AC_SUBST(CC)
fi

AC_PROG_INSTALL
AC_PROG_RANLIB
AC_HAVE_HEADERS(unistd.h limits.h)
AC_PROG_MAKE_SET

#--------------------------------------------------------------------
#	unsigned char is not supported by some non-ANSI compilers.
#--------------------------------------------------------------------

AC_MSG_CHECKING([unsigned char])
AC_TRY_COMPILE([#include <stdio.h>],[
     unsigned char c = 'c';
], tcl_ok=supported, tcl_ok=notsupported)

AC_MSG_RESULT($tcl_ok)
if test $tcl_ok = supported; then
    AC_DEFINE(UCHAR_SUPPORTED)
fi

#--------------------------------------------------------------------
#	Check whether there is an strcasecmp function on this system.
#	This is a bit tricky because under SCO it's in -lsocket and
#	under Sequent Dynix it's in -linet.
#--------------------------------------------------------------------

AC_CHECK_FUNC(strcasecmp, tcl_ok=1, tcl_ok=0)
if test "$tcl_ok" = 0; then
    AC_CHECK_LIB(socket, strcasecmp, tcl_ok=1, tcl_ok=0)
fi
if test "$tcl_ok" = 0; then
    AC_CHECK_LIB(inet, strcasecmp, tcl_ok=1, tcl_ok=0)
fi
if test "$tcl_ok" = 0; then
    AC_DEFINE(NO_STRCASECMP)
fi

# Check for Tcl and Tk.
CYG_AC_PATH_TCLCONFIG
CYG_AC_LOAD_TCLCONFIG
CYG_AC_PATH_TKCONFIG
CYG_AC_LOAD_TKCONFIG
CYG_AC_PATH_TCLH
# FIXME: consider only doing this if --with-x given.
CYG_AC_PATH_TKH

#--------------------------------------------------------------------
#	Find out the top level source directory of the Tix package.
#--------------------------------------------------------------------
TIX_SRC_DIR=`cd ${srcdir}/../..; pwd`

#--------------------------------------------------------------------
#	See if we should compile SAM
#--------------------------------------------------------------------

AC_ARG_ENABLE(sam,
    [  --enable-sam            build stand-alone modules],
    [ok=$enableval], [ok=no])

if test "$ok" = "yes"; then
    TIX_BUILD_SAM="yes"
    TIX_SAM_TARGETS='$(SAM_TARGETS)'
else
    TIX_BUILD_SAM="no"
fi

	    TIX_SAM_INSTALL=_install_sam_lib_

IS_ITCL=0
ITCL_BUILD_LIB_SPEC=""
ITK_BUILD_LIB_SPEC=""
TIX_EXE_FILE=tixwish
TCL_SAMEXE_FILE=satclsh
TK_SAMEXE_FILE=sawish
TIX_SAMEXE_FILE=satixwish

#--------------------------------------------------------------------
#	Read in configuration information generated by Tcl for shared
#	libraries, and arrange for it to be substituted into our
#	Makefile.
#--------------------------------------------------------------------

CC=$TCL_CC
SHLIB_CFLAGS=$TCL_SHLIB_CFLAGS
SHLIB_LD=$TCL_SHLIB_LD
SHLIB_LD_LIBS=$TCL_SHLIB_LD_LIBS
SHLIB_SUFFIX=$TCL_SHLIB_SUFFIX
SHLIB_VERSION=$TCL_SHLIB_VERSION

DL_LIBS=$TCL_DL_LIBS
LD_FLAGS=$TCL_LD_FLAGS
TIX_LD_SEARCH_FLAGS=$TK_LD_SEARCH_FLAGS

BIN_VERSION=${TIX_VERSION}.${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}
VERSION=${BIN_VERSION}

#--------------------------------------------------------------------
#	Read in configuration information generated by Tk and arrange
#	for it to be substituted into our Makefile.
#--------------------------------------------------------------------

TIX_DEFS="$TK_DEFS $TCL_DEFS"

# Note:  in the following variable, it's important to use the absolute
# path name of the Tcl directory rather than "..":  this is because
# AIX remembers this path and will attempt to use it at run-time to look
# up the Tcl library.

if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
    TIX_BUILD_LIB_SPEC="-L`pwd` -ltix${VERSION}"
    TIX_BUILD_SAM_SPEC="-L`pwd` -ltixsam${VERSION}"
    TCL_BUILD_SAM_SPEC="-L`pwd` -ltclsam${TCL_VERSION}"
    TK_BUILD_SAM_SPEC="-L`pwd` -ltksam${TK_VERSION}"
    TIX_LIB_SPEC="-L${exec_prefix}/lib -ltix${VERSION}"
else
    TIX_BUILD_LIB_SPEC="-L`pwd` -ltix`echo ${VERSION} | tr -d .`"
    TIX_BUILD_SAM_SPEC="-L`pwd` -ltixsam`echo ${VERSION} | tr -d .`"
    TCL_BUILD_SAM_SPEC="-L`pwd` -ltclsam`echo ${TCL_VERSION} | tr -d .`"
    TK_BUILD_SAM_SPEC="-L`pwd` -ltksam`echo ${TK_VERSION} | tr -d .`"
    TIX_LIB_SPEC="-L${exec_prefix}/lib -ltix`echo ${VERSION} | tr -d .`"
fi

#--------------------------------------------------------------------
#	See if we should compile shared library.
#--------------------------------------------------------------------

AC_ARG_ENABLE(shared,
    [  --enable-shared         build libtix as a shared library],
    [ok=$enableval], [ok=no])

if test "$ok" = "yes" -a "${SHLIB_SUFFIX}" != ""; then
    TIX_SHLIB_CFLAGS="${SHLIB_CFLAGS}"
    TIX_RANLIB=":"

    # The main Tix library
    #
    eval "TIX_LIB_FILE=libtix${TCL_SHARED_LIB_SUFFIX}"
    TIX_MAKE_LIB="\${SHLIB_LD} -o ${TIX_LIB_FILE} \${OBJS} ${SHLIB_LD_LIBS}"

    # The Tcl SAM library
    #
    eval "TCL_SAM_FILE=libtclsam${TCL_SHARED_LIB_SUFFIX}"
    TCL_MAKE_SAM="\${SHLIB_LD} -o ${TCL_SAM_FILE} \${TCL_SAM_OBJS} ${SHLIB_LD_LIBS}"
    
    # The Tk SAM library
    #
    eval "TK_SAM_FILE=libtksam${TCL_SHARED_LIB_SUFFIX}"
    TK_MAKE_SAM="\${SHLIB_LD} -o ${TK_SAM_FILE} \${TK_SAM_OBJS} ${SHLIB_LD_LIBS}"
    
    # The Tix SAM library
    #
    eval "TIX_SAM_FILE=libtixsam${TCL_SHARED_LIB_SUFFIX}"
    TIX_MAKE_SAM="\${SHLIB_LD} -o ${TIX_SAM_FILE} \${TIX_SAM_OBJS} ${SHLIB_LD_LIBS}"

else
    TIX_SHLIB_CFLAGS=""
    TIX_RANLIB='$(RANLIB)'

    # The main Tix library
    #
    eval "TIX_LIB_FILE=libtix${TCL_UNSHARED_LIB_SUFFIX}"
    TIX_MAKE_LIB="ar cr ${TIX_LIB_FILE} \${OBJS}"

    # The Tcl SAM library
    
    eval "TCL_SAM_FILE=libtclsam${TCL_UNSHARED_LIB_SUFFIX}"
    TCL_MAKE_SAM="ar cr ${TCL_SAM_FILE} \${TCL_SAM_OBJS}"
    
    # The Tk SAM library
    #
    eval "TK_SAM_FILE=libtksam${TCL_UNSHARED_LIB_SUFFIX}"
    TK_MAKE_SAM="ar cr ${TK_SAM_FILE} \${TK_SAM_OBJS}"
    
    # The Tix SAM library
    #
    eval "TIX_SAM_FILE=libtixsam${TCL_UNSHARED_LIB_SUFFIX}"
    TIX_MAKE_SAM="ar cr ${TIX_SAM_FILE} \${TIX_SAM_OBJS}"
fi


#--------------------------------------------------------------------
#	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.
#--------------------------------------------------------------------

checked=0
for i in $TK_LIBS; do
    if test "$i" = "-lsocket"; then
	checked=1
    fi
done

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

AC_SUBST(datadir)
#----------------------------------------------------------------------
#	Substitution strings exported by TIX
#----------------------------------------------------------------------
AC_SUBST(SHELL)
AC_SUBST(CC)
AC_SUBST(RANLIB)
AC_SUBST(TIX_RANLIB)
AC_SUBST(SHLIB_CFLAGS)
AC_SUBST(SHLIB_LD)
AC_SUBST(SHLIB_LD_LIBS)
AC_SUBST(SHLIB_SUFFIX)
AC_SUBST(SHLIB_VERSION)
AC_SUBST(DL_LIBS)
AC_SUBST(LD_FLAGS)
AC_SUBST(TCL_BUILD_LIB_SPEC)
AC_SUBST(TCL_LIBS)
AC_SUBST(TCL_VERSION)
AC_SUBST(TCL_SRC_DIR)
AC_SUBST(TCL_BIN_DIR)
AC_SUBST(TK_BUILD_LIB_SPEC)
AC_SUBST(TK_LIBS)
AC_SUBST(TK_VERSION)
AC_SUBST(TK_SRC_DIR)
AC_SUBST(TK_BIN_DIR)
AC_SUBST(TK_XINCLUDES)
AC_SUBST(TIX_LD_SEARCH_FLAGS)
AC_SUBST(TIX_MAJOR_VERSION)
AC_SUBST(TIX_MINOR_VERSION)
AC_SUBST(TIX_VERSION)
AC_SUBST(TIX_SRC_DIR)
AC_SUBST(TIX_SHLIB_CFLAGS)
AC_SUBST(TIX_MAKE_LIB)
AC_SUBST(TIX_LIB_FILE)
AC_SUBST(TIX_BUILD_LIB_SPEC)
AC_SUBST(TIX_LIB_SPEC)
AC_SUBST(TIX_EXE_FILE)
AC_SUBST(TIX_SAM_TARGETS)
AC_SUBST(TIX_SAM_INSTALL)
AC_SUBST(TCL_SAM_FILE)
AC_SUBST(TCL_MAKE_SAM)
AC_SUBST(TK_SAM_FILE)
AC_SUBST(TK_MAKE_SAM)
AC_SUBST(TIX_SAM_FILE)
AC_SUBST(TIX_MAKE_SAM)
AC_SUBST(TIX_DEFS)
AC_SUBST(ITCL_BUILD_LIB_SPEC)
AC_SUBST(ITK_BUILD_LIB_SPEC)
AC_SUBST(TCL_SAMEXE_FILE)
AC_SUBST(TK_SAMEXE_FILE)
AC_SUBST(TIX_SAMEXE_FILE)
AC_SUBST(TCL_BUILD_SAM_SPEC)
AC_SUBST(TK_BUILD_SAM_SPEC)
AC_SUBST(TIX_BUILD_SAM_SPEC)
AC_SUBST(TCL_PACKAGE_PATH)

# The "binary version" of Tix (see docs/Pkg.txt)
TIX_VERSION_PKG=${BIN_VERSION}
AC_SUBST(TIX_VERSION_PKG)

TIXSAM_PKG_FILE="[[file join [file dirname \$dir] ${TIX_SAM_FILE}]]"
# if test "$TIX_BUILD_SAM" = "yes"; then
    TIX_SAM_PACKAGE_IFNEEDED="package ifneeded Tixsam ${TIX_VERSION_PKG} [[list load \"${TIXSAM_PKG_FILE}\" Tixsam]]"
# fi

# The package file, usually a shared library
TIX_PKG_FILE="[[file join [file dirname \$dir] ${TIX_LIB_FILE}]]"
AC_SUBST(TIX_PKG_FILE)
AC_SUBST(TIX_SAM_PACKAGE_IFNEEDED)

AC_OUTPUT(Makefile pkgIndex.tcl ../../tixConfig.sh)

