dnl	This file is an input file used by the GNU "autoconf" program to
dnl	generate the file "configure", which is run during [incr Tcl]
dnl installation to configure the system for the local environment.

AC_INIT(../generic/itcl.h)
# RCS: $Id: configure.in,v 1.4 1999/06/26 01:59:22 wart Exp $

ITCL_VERSION=3.1
ITCL_MAJOR_VERSION=3
ITCL_MINOR_VERSION=1
ITCL_RELEASE_LEVEL=0
VERSION=${ITCL_VERSION}

AC_CONFIG_AUX_DIR(../../config)
AC_PREREQ(2.0)

# -----------------------------------------------------------------------
#   Set up a new default --prefix.  If a previous installation of
#   [incr Tcl] can be found searching $PATH use that directory.
# -----------------------------------------------------------------------

AC_PREFIX_DEFAULT(/usr/local)
AC_PREFIX_PROGRAM(tclsh)

if test "${prefix}" = "NONE"; then
    prefix=/usr/local
fi
if test "${exec_prefix}" = "NONE"; then
    exec_prefix=$prefix
fi

AC_PROG_INSTALL
AC_PROG_RANLIB

# -----------------------------------------------------------------------
BUILD_DIR=`pwd`
ITCL_SRC_DIR=`cd $srcdir/..; pwd`
cd ${BUILD_DIR}

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

#--------------------------------------------------------------------
#   See if there was a command-line option for where Tcl is;  if
#   not, search for Tcl.
#--------------------------------------------------------------------

AC_ARG_WITH(tcl, [  --with-tcl=DIR          use Tcl 8.0 binaries from DIR],
        itcl_search=$withval, itcl_search=`cd ../../..; ls -d \`pwd\`/tcl8.*/unix`)

TCL_LIB_DIR=""
for dir in $itcl_search $exec_prefix/lib ; do
    if test -r $dir/tclConfig.sh; then
        TCL_LIB_DIR=$dir
        break
    fi
done

if test -z "$TCL_LIB_DIR"; then
    AC_MSG_ERROR(Can't find Tcl libraries.  Use --with-tcl to specify the directory containing tclConfig.sh on your system.)
fi

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

file=$TCL_LIB_DIR/tclConfig.sh
. $file
CFLAGS=$TCL_CFLAGS
SHLIB_CFLAGS=$TCL_SHLIB_CFLAGS
SHLIB_LD=$TCL_SHLIB_LD
SHLIB_LD_LIBS=$TCL_SHLIB_LD_LIBS
SHLIB_SUFFIX=$TCL_SHLIB_SUFFIX
DL_LIBS=$TCL_DL_LIBS
LD_FLAGS=$TCL_LD_FLAGS
LD_SEARCH_FLAGS=$TCL_LD_SEARCH_FLAGS

#--------------------------------------------------------------------
#   Make sure that we can find the Tcl sources, so we can include
#   the "tclInt.h" file.
#--------------------------------------------------------------------

if test ! -d "$TCL_SRC_DIR"; then
   echo $TCL_LIB_DIR
    AC_MSG_ERROR(Can't find Tcl source directory "$TCL_SRC_DIR".  Itcl can't be built without this directory.)
fi

#--------------------------------------------------------------------
#   If this is gcc, add some extra compile flags.
#--------------------------------------------------------------------

AC_MSG_CHECKING([whether C compiler is gcc])
AC_CACHE_VAL(itcl_cv_prog_gcc,
    AC_EGREP_CPP(_cc_is_gcc_, [
#ifdef __GNUC__
_cc_is_gcc_
#endif
],      [itcl_cv_prog_gcc=yes], [itcl_cv_prog_gcc=no]))
AC_MSG_RESULT([$itcl_cv_prog_gcc])

if test -z "$CFLAGS" ; then
    CFLAGS="-O"
fi
if test "$itcl_cv_prog_gcc" = "yes" ; then
    CFLAGS="$CFLAGS -Wall -Wconversion -Wno-implicit-int"
fi

AC_MSG_CHECKING([default compiler flags])
AC_ARG_WITH(cflags, [  --with-cflags=FLAGS     set compiler flags to FLAGS],
    [CFLAGS="$with_cflags"])

AC_MSG_RESULT([$CFLAGS])

if test "$TCL_CC" != "$CC" ; then
    echo ""
    echo "WARNING:  Compiler is $CC but Tcl was compiled with $TCL_CC"
    echo ""
fi

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

AC_ARG_ENABLE(shared,
    [  --enable-shared         build libitcl as a shared library],
    [ok=$enableval], [ok=yes])
if test "$ok" = "yes"; then
    if test ${TCL_SHARED_BUILD} = 0; then
        AC_MSG_ERROR(Tcl was not built with --enable-shared, so you can't use shared libraries.)
    fi
    SHLIB_CFLAGS="${SHLIB_CFLAGS}"
    TCL_STUB_FLAGS=-DUSE_TCL_STUBS
    eval "ITCL_LIB_FILE=libitcl${VERSION}${SHLIB_SUFFIX}"
    ITCL_PKG_FILE="[[file join [file dirname \$dir] ${ITCL_LIB_FILE}]]"
    MAKE_LIB="\$(SHLIB_LD) -o ${ITCL_LIB_FILE} \$(OBJS) ${SHLIB_LD_LIBS}"
    RANLIB=":"
else
    SHLIB_CFLAGS=""
    TCL_STUB_FLAGS=""
    eval "ITCL_LIB_FILE=libitcl${VERSION}.a"
    ITCL_PKG_FILE=""
    MAKE_LIB="ar cr ${ITCL_LIB_FILE} \${OBJS}"
fi

eval "STUB_LIB_FILE=libitclstub${TCL_UNSHARED_LIB_SUFFIX}"
MAKE_STUB_LIB="ar cr \${ITCL_STUB_LIB_FILE} \${ITCL_STUB_LIB_OBJS}"
ITCL_STUB_LIB_FILE=${STUB_LIB_FILE}

# 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
    ITCL_BUILD_LIB_SPEC="-L`pwd` -litcl${VERSION}"
    ITCL_LIB_SPEC="-L${exec_prefix}/lib -litcl${VERSION}"
else
    ITCL_BUILD_LIB_SPEC="-L`pwd` -litcl`echo ${VERSION} | tr -d .`"
    ITCL_LIB_SPEC="-L${exec_prefix}/lib -litcl`echo ${VERSION} | tr -d .`"
fi

ITCL_BUILD_STUB_LIB_SPEC="-L`pwd` -litclstub${VERSION}"
ITCL_STUB_LIB_SPEC="-L${exec_prefix}/lib -litclstub${VERSION}"

AC_SUBST(CFLAGS)
AC_SUBST(DL_LIBS)
AC_SUBST(LD_FLAGS)
AC_SUBST(MAKE_LIB)
AC_SUBST(MAKE_STUB_LIB)
AC_SUBST(SHLIB_CFLAGS)
AC_SUBST(SHLIB_LD)
AC_SUBST(SHLIB_LD_LIBS)
AC_SUBST(SHLIB_SUFFIX)
AC_SUBST(LD_SEARCH_FLAGS)

AC_SUBST(TCL_VERSION)
AC_SUBST(TCL_SRC_DIR)
AC_SUBST(TCL_LIB_DIR)
AC_SUBST(TCL_LIB_SPEC)
AC_SUBST(TCL_BUILD_STUB_LIB_SPEC)
AC_SUBST(TCL_BUILD_LIB_SPEC)
AC_SUBST(TCL_LIB_FLAG)
AC_SUBST(TCL_STUB_FLAGS)
AC_SUBST(TCL_DBGX)
AC_SUBST(TCL_DEFS)
AC_SUBST(TCL_LIBS)
AC_SUBST(TCL_SHLIB_LD_LIBS)
AC_SUBST(TCL_SHLIB_SUFFIX)
AC_SUBST(TCL_COMPAT_OBJS)

AC_SUBST(ITCL_VERSION)
AC_SUBST(ITCL_MAJOR_VERSION)
AC_SUBST(ITCL_MINOR_VERSION)
AC_SUBST(ITCL_RELEASE_LEVEL)

AC_SUBST(ITCL_BUILD_LIB_SPEC)
AC_SUBST(ITCL_BUILD_STUB_LIB_SPEC)
AC_SUBST(ITCL_LIB_FILE)
AC_SUBST(ITCL_STUB_LIB_FILE)
AC_SUBST(ITCL_LIB_SPEC)
AC_SUBST(ITCL_STUB_LIB_SPEC)
AC_SUBST(ITCL_PKG_FILE)
AC_SUBST(ITCL_SRC_DIR)

AC_OUTPUT(Makefile pkgIndex.tcl itclConfig.sh)
