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

# Name a file autoconf should find in the source directory
AC_INIT(trans.c)

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

AC_ARG_WITH(tcl, 
        [  --with-tcl=directory containing tcl configuration (tclConfig.sh)],
        TCL_BIN_DIR=$withval, TCL_BIN_DIR=/usr/lib)
if test ! -e $TCL_BIN_DIR/tclConfig.sh; then
    AC_MSG_ERROR(Tcl configuration $TCL_BIN_DIR/tclConfig.sh not found)
fi

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

AC_ARG_WITH(tk, 
        [  --with-tk=directory containing tk configuration (tkConfig.sh)],
        TK_BIN_DIR=$withval, TK_BIN_DIR=/usr/lib)
if test ! -e $TK_BIN_DIR/tkConfig.sh; then
    AC_MSG_ERROR(Tk configuration $TK_BIN_DIR/tkConfig.sh not found)
fi

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

#AC_ARG_WITH(snack, 
#        [  --with-snack=DIR use Snack from DIR],
#        SNACK_DIR=$withval, SNACK_DIR="../../snack1.6.5")
#if test ! -d $SNACK_DIR; then
#    AC_MSG_ERROR(SNACK directory $SNACK_DIR does not exist)
#fi
#SNACK_INC="-I$SNACK_DIR/src"

#--------------------------------------------------------------------
# Initialise installation path from prefix
#--------------------------------------------------------------------

test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix=$prefix
TRANS_LIB=${exec_prefix}/lib
TRANS_BIN=${exec_prefix}/bin
TRANS_DIR=transcriber1.5

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

file=$TCL_BIN_DIR/tclConfig.sh
. $file

CFLAGS=$TCL_SHLIB_CFLAGS
SHLIB_LD=$TCL_SHLIB_LD
SHLIB_LD_LIBS=$TCL_SHLIB_LD_LIBS
SHLIB_VERSION=$TCL_SHLIB_VERSION
SHLIB_SUFFIX=$TCL_SHLIB_SUFFIX
TCL_LIBS=$TCL_LIBS
CC=$TCL_CC
TCLVER=$TCL_VERSION
TCLAPI=""
if test "$TCLVER" != "8.0"; then
    TCLAPI="-DTCL_81_API"
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

XINCLUDES=$TK_XINCLUDES

SUFFIX=""
if test -e $TK_EXEC_PREFIX/wish$TK_VERSION; then
  SUFFIX=$TK_VERSION
fi

#--------------------------------------------------------------------
#       Set byte order for the  systems
#--------------------------------------------------------------------
 
#system=`uname -s`
# 
#ORDER=""
#case $system in
#    Linux*)
#        ORDER="-DLinux"
#        ;;
#    NetBSD*)
#        ORDER="-DLinux"
#        ;;
#esac

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

#file=$SNACK_DIR/src/snackConfig.sh
#. $file

#--------------------------------------------------------------------
#       Set machine-dependent variables
#--------------------------------------------------------------------

system=`uname -s`-`uname -r`

case $system in
    IRIX*)
        ;;
    Linux*)
        ;;
    SunOS-5*)
	SHLIB_LD="ld -G"
        ;;
    *)
        ;;
esac



#--------------------------------------------------------------------
#       Disable stub support. This is necessary if you
#       want to run Snack with Tcl/Tk 8.0 up to 8.0.5
#--------------------------------------------------------------------

AC_ARG_ENABLE(stubs,
	[  --disable-stubs         disable stub support],
	,enableval2="no")

if test "$enableval2" = "no"; then
    AC_MSG_RESULT(will use stubs (normal))
    CFLAGS="$CFLAGS -DUSE_TCL_STUBS -DUSE_TK_STUBS"
    TCL_LIB_SPEC="${TCL_STUB_LIB_SPEC}"
    TK_LIB_SPEC="${TK_STUB_LIB_SPEC}"
    #SNACK_LIB_SPEC="-L${SNACK_INSTALL_PATH} -lsnackstub1.6"
    if test "$TCLVER" = "8.0"; then
        AC_MSG_WARN("You probably forgot to specify --disable-stubs")
    fi
else
    AC_MSG_RESULT(will not use stubs)
    # when linked with -lsnack, $prefix/snack1.6 must be in $LD_LIBRARY_PATH
    #SNACK_LIB_SPEC="-L${SNACK_INSTALL_PATH}/snack1.6 -lsnack"
    #SNACK_LIB_SPEC=""
fi

#--------------------------------------------------------------------
#       Set machine-dependent variables needed for compilation
#--------------------------------------------------------------------

OpSys=`uname -s`
OS=""
LIB_SUFFIX=""

case $OpSys in
    MINGW*)
	OS=Windows
	LIBS="${TCL_LIB_SPEC} ${TK_LIB_SPEC} -ltkstub84"
	INCLUDES="${XINCLUDES} -I${TCL_PREFIX}/include -I{$TK_PREFIX}/include"
	OUTPUT_FILES="Makefile"
	LIB_SUFFIX=.dll
        ;;
    *)
	OS=UnixLike
	LIBS="-lc $TK_LIBS $TCL_LIB_SPEC $TK_LIB_SPEC"
	INCLUDES="$XINCLUDES -I$TCL_SRC_DIR/generic -I$TK_SRC_DIR/generic -I$TCL_PREFIX/include -I$TK_PREFIX/include"
    	OUTPUT_FILES="trans Makefile"
	LIB_SUFFIX="${SHLIB_SUFFIX}"
        ;;
esac


#--------------------------------------------------------------------
# Expand @references@ to autoconf variables in Makefile.in
#--------------------------------------------------------------------

AC_SUBST(CC)
AC_SUBST(SHLIB_CFLAGS)
AC_SUBST(SHLIB_LD)
AC_SUBST(SHLIB_LD_LIBS)
AC_SUBST(SHLIB_VERSION)
AC_SUBST(SHLIB_SUFFIX)

AC_SUBST(XINCLUDES)

AC_SUBST(TCL_LIB_SPEC)
AC_SUBST(TCL_DEFS)
AC_SUBST(TCL_LIBS)
AC_SUBST(TCL_PREFIX)
AC_SUBST(TCL_EXEC_PREFIX)

AC_SUBST(TK_VERSION)
AC_SUBST(TK_LIB_SPEC)
AC_SUBST(TCL_SRC_DIR)
AC_SUBST(TK_SRC_DIR)
AC_SUBST(TK_LIBS)
AC_SUBST(TK_DEFS)
AC_SUBST(TK_PREFIX)
AC_SUBST(TK_EXEC_PREFIX)

#AC_SUBST(SNACK_INC)
AC_SUBST(TRANS_LIB)
AC_SUBST(TRANS_DIR)
AC_SUBST(TRANS_BIN)
AC_SUBST(SUFFIX)

#AC_SUBST(SNACK_INSTALL_PATH)
#AC_SUBST(SNACK_LIB_SPEC)
#AC_SUBST(AINC)
#AC_SUBST(AFLAG)
#AC_SUBST(ALIB)

AC_SUBST(TCLAPI)
#AC_SUBST(ORDER)

####
AC_SUBST(LIBS)
AC_SUBST(OS)
AC_SUBST(INCLUDES)
AC_SUBST(LIB_SUFFIX)

AC_OUTPUT("$OUTPUT_FILES")
