dnl Process this file with autoconf to produce a configure script.

AC_INIT(tcldbg.h)

DBG_MAJOR_VERSION=1
DBG_MINOR_VERSION=9
DBG_MICRO_VERSION=1
DBG_VERSION=$DBG_MAJOR_VERSION.$DBG_MINOR_VERSION
DBG_VERSION_FULL=$DBG_VERSION.$DBG_MICRO_VERSION
# Tcl's handling of shared_lib_suffix requires this symbol exist
VERSION=$DBG_MAJOR_VERSION.$DBG_MINOR_VERSION

AC_CONFIG_HEADER(tcldbgcf.h)

OLD_CFLAGS=$CFLAGS
AC_PROG_CC
CFLAGS=$OLD_CFLAGS

CY_AC_PATH_TCLCONFIG
CY_AC_LOAD_TCLCONFIG
CC=$TCL_CC
CY_AC_C_WORKS

# this'll use a BSD compatible install or our included install-sh
AC_PROG_INSTALL

# Tcl sets TCL_RANLIB appropriately for shared library if --enable-shared
AC_PROG_RANLIB
UNSHARED_RANLIB=$RANLIB

# This is for LynxOS, which needs a flag to force true POSIX when
# building. It's weirder than that, cause the flag varies depending
# how old the compiler is. So...
# -X is for the old "cc" and "gcc" (based on 1.42)
# -mposix is for the new gcc (at least 2.5.8)
# This modifies the value of $CC to have the POSIX flag added
# so it'll configure correctly
CY_AC_TCL_LYNX_POSIX

# we really only need the header files
CY_AC_PATH_TCLH
if test x"$no_tcl" = x"true" ; then
    echo "      ERROR: Can't find Tcl directory"
    echo "      See README for information on how to obtain Tcl."
    echo "      If Tcl is installed, see INSTALL on how to tell"
    echo "      configure where Tcl is installed."
    exit 1
fi

# Use -g on all systems but Linux where it upsets the dynamic X libraries.
AC_MSG_CHECKING([if we are running Linux])
if test "x`(uname) 2>/dev/null`" = xLinux; then
  AC_MSG_RESULT(yes)
  linux=1
  DBG_CFLAGS=
else
  AC_MSG_RESULT(no)
  linux=0
  DBG_CFLAGS=-g
fi

#
# Look for functions that may be missing
#
AC_FUNC_CHECK(strchr, AC_DEFINE(HAVE_STRCHR))

#
# Look for various header files
#
AC_HEADER_CHECK(stdlib.h, ,AC_DEFINE(NO_STDLIB_H))

# consume these flags so that user can invoke tcl-debug's configure with
# the same command as Tcl's configure
AC_ARG_ENABLE(load,
	[  --disable-load     disallow dynamic loading],
	[disable_dl=yes], [disable_dl=no])

AC_ARG_ENABLE(gcc,
	[  --enable-gcc        allow use of gcc if available],
	[enable_gcc=yes], [enable_gcc=no])

DBG_UNSHARED_LIB_FILE=libtcldbg.a

AC_MSG_CHECKING([type of library to build])
AC_ARG_ENABLE(shared,
	[  --enable-shared     build libtcldbg as a shared library],
	[enable_shared=yes], [enable_shared=no])
if test "$enable_shared" = "yes" -a "x${TCL_SHLIB_SUFFIX}" != "x" ; then
  DBG_SHLIB_CFLAGS=$TCL_SHLIB_CFLAGS
#  DBG_SHARED_LIB_FILE=libtcldbg$DBG_VERSION$TCL_SHLIB_SUFFIX
  eval "DBG_SHARED_LIB_FILE=libtcldbg${TCL_SHARED_LIB_SUFFIX}"
  DBG_LIB_FILE=$DBG_SHARED_LIB_FILE
  DBG_LIB_FILES="$DBG_SHARED_LIB_FILE $DBG_UNSHARED_LIB_FILE"
  AC_MSG_RESULT(both shared and unshared)
else
  DBG_SHLIB_CFLAGS=
  DBG_SHARED_LIB_FILE="reconfigure_Tcl_for_shared_library"
  DBG_LIB_FILE=$DBG_UNSHARED_LIB_FILE
  DBG_LIB_FILES="$DBG_UNSHARED_LIB_FILE"
  AC_MSG_RESULT(unshared)
fi

#
# Set up makefile substitutions
#
AC_SUBST(DBG_MAJOR_VERSION)
AC_SUBST(DBG_MINOR_VERSION)
AC_SUBST(DBG_MICRO_VERSION)
AC_SUBST(DBG_VERSION_FULL)
AC_SUBST(DBG_VERSION)
AC_SUBST(CC)
AC_SUBST(DBG_SHARED_LIB_FILE)
AC_SUBST(DBG_UNSHARED_LIB_FILE)
AC_SUBST(DBG_SHLIB_CFLAGS)
AC_SUBST(DBG_LIB_FILE)
AC_SUBST(DBG_LIB_FILES)
AC_SUBST(DBG_CFLAGS)
AC_SUBST(UNSHARED_RANLIB)
AC_OUTPUT(Makefile pkgIndex)

