#! /bin/bash -norc
dnl	This file is an input file used by the GNU "autoconf" program to
dnl	generate the file "configure", which is run during Snack installation
dnl	to configure the system for the local environment.
AC_INIT(../generic/snack.h)

SNACK_VERSION=`sh $srcdir/sver.sh $srcdir/../generic/snack.h`
SNACK_NODOT_VERSION=`echo $SNACK_VERSION | tr -d .`

AC_CHECK_HEADER(stdint.h)

#--------------------------------------------------------------------
#       See if there was a command-line option for where Tcl is;  if
#       not, assume that its top-level directory is a sibling of ours.
#--------------------------------------------------------------------

SC_PATH_TCLCONFIG

#--------------------------------------------------------------------
#       See if there was a command-line option for where Tk is;  if
#       not, assume that its top-level directory is a sibling of ours.
#--------------------------------------------------------------------

SC_PATH_TKCONFIG

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

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

SNACK_INSTALL_PATH=${libdir}
SNACK_HINSTALL_PATH=${includedir}
SNACK_LIB_SPEC="-L${libdir} -lsnack"

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

file=$TCL_BIN_DIR/tclConfig.sh
. $file

if test "$TCL_SHARED_BUILD" = 0; then
    AC_MSG_ERROR(Tcl and Tk must be configured with the --enable-shared flag)
fi

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

file=$TK_BIN_DIR/tkConfig.sh
. $file


SNACK_STUB_LIB_FILE="libsnackstub${SNACK_NODOT_VERSION}.a"
SNACK_STUB_LIB_FLAG="-lsnackstub${SNACK_NODOT_VERSION}"

if test "$TCL_DBGX" = ""; then
    CFLAGS="$CFLAGS $TCL_CFLAGS_OPTIMIZE"
else
    CFLAGS="$CFLAGS $TCL_CFLAGS_DEBUG"
fi

# If TCL_MEM_DEBUG is defined, add it to the CFLAGS
if (echo "$TCL_DEFS" | grep TCL_MEM_DEBUG > /dev/null) ; then
    CFLAGS="$CFLAGS -DTCL_MEM_DEBUG"
fi

# If HAVE_STDINT_H was detected, pass it to the CFLAGS
if test "$ac_cv_header_stdint_h" = "yes" ; then
    CFLAGS="$CFLAGS -DHAVE_STDINT_H"
fi


# Include files from Tcl src/build location
TCL_INCLUDE_SPEC="-I$TCL_SRC_DIR/generic"
TK_INCLUDE_SPEC="-I$TK_SRC_DIR/generic -I$TK_SRC_DIR/xlib"
TCL_LIB_SPEC=$TCL_BUILD_STUB_LIB_SPEC
TK_LIB_SPEC=$TK_BUILD_STUB_LIB_SPEC

AC_SUBST(srcdir)
AC_SUBST(CFLAGS)

AC_SUBST(SNACK_VERSION)
AC_SUBST(SNACK_NODOT_VERSION)

AC_SUBST(TCL_INCLUDE_SPEC)
AC_SUBST(TK_INCLUDE_SPEC)
AC_SUBST(TCL_LIB_SPEC)
AC_SUBST(TK_LIB_SPEC)

AC_SUBST(SNACK_INSTALL_PATH)
AC_SUBST(SNACK_HINSTALL_PATH)
AC_SUBST(SNACK_LIB_SPEC)

AC_SUBST(SNACK_STUB_LIB_FILE)
AC_SUBST(SNACK_STUB_LIB_FLAG)

AC_OUTPUT(Makefile snackConfig.sh)

