#! /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)

PACKAGE_NAME=snack

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

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

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

TEA_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=${exec_prefix}/lib
SNACK_HINSTALL_PATH=${exec_prefix}/include
SNACK_LIB_SPEC="-L${exec_prefix}/lib -lsnack"
# 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
CFLAGS=$TCL_SHLIB_CFLAGS
LD_SEARCH_FLAGS=$TCL_LD_SEARCH_FLAGS
SHLIB_LD=$TCL_SHLIB_LD
SHLIB_SUFFIX=$TCL_SHLIB_SUFFIX
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

#--------------------------------------------------------------------
#	Set audio related variables for the supported systems
#--------------------------------------------------------------------

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

AINC=""
ALIB=""

case $system in
    BSD/OS-4.*)
	AFLAG="-DOSS"
	ALIB="-lossaudio"
	AOBJ="jkAudIO_oss.o"
        ;;
    HP-UX-*.1*)
	if test "$CC" = "gcc" -o `$CC -v 2>&1 | grep -c gcc` != "0" ; then
	    CFLAGS=$CFLAGS
	else
	    CFLAGS="-Ae +z"
	fi
	AINC="-I/opt/audio/include"
	AFLAG="-DHPUX"
	ALIB="-L/opt/audio/lib -lAlib"
	AOBJ="jkAudIO_hp.o"
        if test "$SHLIB_LD" = "ld -b" ; then
            # this will not work if gcc is used as "linker"
            SHLIB_LD="$SHLIB_LD +s"
        else
            # gcc requires the prefix -Xlinker for each linker option
            SHLIB_LD="$SHLIB_LD -Xlinker +s"
        fi
	;;
    IRIX*)
	AFLAG="-DIRIX"
        ALIB="-laudio"
	AOBJ="jkAudIO_sgi.o"
	;;
    IRIX64-6.*)
	AFLAG="-DIRIX"
        ALIB="-laudio"
	AOBJ="jkAudIO_sgi.o"
	;;
    Linux*)
	AFLAG="-DOSS"
	AOBJ="jkAudIO_oss.o"
	;;
    NetBSD*|OpenBSD-*)
	AFLAG="-DOSS"
	ALIB="-lossaudio"
	AOBJ="jkAudIO_oss.o"
        ;;
    FreeBSD-*)
	AFLAG="-DOSS"
	ALIB=""
	AOBJ="jkAudIO_oss.o"
        ;;
    SunOS*)
	AFLAG="-DSolaris"
	AOBJ="jkAudIO_sun.o"
	;;
    Rhapsody-*|Darwin-*)
	HACK=""
	AFLAG="-DOS_X_CORE_AUDIO -DMA${HACK}C_OSX_TCL -DMA${HACK}C_OSX_TK"
	ALIB="-framework CoreFoundation -framework CoreAudio"
	AOBJ="jkAudIO_osx.o"
	CFLAGS="-Os -fno-common"
        ;;
    *)
	AFLAG="-DOTHER"
	AOBJ="jkAudIO_skel.o"
	;;
esac


#--------------------------------------------------------------------
#	Get the path to the NIST/SPHERE distribution. This is
#	only necessary if you want to build the NIST package.
#--------------------------------------------------------------------

AC_ARG_WITH(nist-include,[  --with-nist-include=DIR use NIST/SPHERE includes in DIR],
        NIST_INC_DIR=$withval, NIST_INC_DIR="")
NISTINC="-I$NIST_INC_DIR"
if test "$NISTINC" = "-I"; then
  NISTINC=""
fi

AC_ARG_WITH(nist-lib,[  --with-nist-lib=DIR     use NIST/SPHERE libraries in DIR],
        NIST_LIB_DIR=$withval, NIST_LIB_DIR="")
NISTLIBS="$NIST_LIB_DIR/libsp.a $NIST_LIB_DIR/libutil.a"
LIBNIST=""
if test ! "$NIST_LIB_DIR" = ""; then
  LIBNIST="libsnacksphere${SHLIB_SUFFIX}"
fi


#--------------------------------------------------------------------
#	Get the path to the Ogg/Vorbis installation. This is
#	only necessary if you want to build the snackogg package.
#--------------------------------------------------------------------

LIBOGG=""
AC_ARG_WITH(ogg-include,[  --with-ogg-include=DIR  use Ogg/Vorbis includes in DIR],
        OGG_INC_DIR=$withval, OGG_INC_DIR="")
AC_ARG_WITH(ogg-lib,[  --with-ogg-lib=DIR      use Ogg/Vorbis libraries in DIR],
        OGG_LIB_DIR=$withval, OGG_LIB_DIR="")
OGGINC="-I$OGG_INC_DIR"
OGGLIBS="-L$OGG_LIB_DIR -lvorbisenc -lvorbis -logg"
if test ! "$OGG_LIB_DIR" = ""; then
  LIBOGG="libsnackogg${SHLIB_SUFFIX}"
fi

#--------------------------------------------------------------------
#	Disable stub support. This is necessary if you
#	want to run Snack with Tcl/Tk versions 8.0 through 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}"
    STUBINITOBJ="snackStubInit.o"
    DOSTUBLIB="stublib"
    SNACK_STUB_LIB_FLAG="-lsnackstub$SNACK_VERSION"
    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)
    if test "$TCLVER" != "8.0"; then
	STUBINITOBJ="snackStubInit.o"
    else
	STUBINITOBJ=""
    fi
    DOSTUBLIB=""
    SNIST_LIB_SPEC="-lsnack"
fi

#--------------------------------------------------------------------
#	Enable ALSA sound support.
#--------------------------------------------------------------------

AC_ARG_ENABLE(alsa,[  --enable-alsa           enable ALSA support],,enableval3="no")

if test "$enableval3" != "no"; then
    AC_MSG_RESULT(will use ALSA)
    AFLAG="-DALSA"
    ALIB="-lasound"
    AOBJ="jkAudIO_alsa.o"
else
    AC_MSG_RESULT(will use OSS)
fi
#--------------------------------------------------------------------

# Checks for header files.
_AC_INCLUDES_DEFAULT_REQUIREMENTS

AC_SUBST(CC)
AC_SUBST(CFLAGS)
AC_SUBST(SHLIB_LD)
AC_SUBST(SHLIB_SUFFIX)
AC_SUBST(XINCLUDES)
AC_SUBST(TCL_INCLUDE_SPEC)
AC_SUBST(TCL_LIB_SPEC)
AC_SUBST(TK_LIB_SPEC)
AC_SUBST(TCL_SRC_DIR)
AC_SUBST(TK_SRC_DIR)
AC_SUBST(TK_LIBS)
AC_SUBST(SNACK_INSTALL_PATH)
AC_SUBST(SNACK_HINSTALL_PATH)
AC_SUBST(SNACK_LIB_SPEC)
AC_SUBST(AINC)
AC_SUBST(AFLAG)
AC_SUBST(ALIB)
AC_SUBST(AOBJ)
AC_SUBST(NISTINC)
AC_SUBST(NISTLIBS)
AC_SUBST(LIBNIST)
AC_SUBST(OGGINC)
AC_SUBST(OGGLIBS)
AC_SUBST(LIBOGG)
AC_SUBST(TCLAPI)
AC_SUBST(LD_SEARCH_FLAGS)
AC_SUBST(TCLVER)
AC_SUBST(STUBINITOBJ)
AC_SUBST(DOSTUBLIB)
AC_SUBST(SNACK_STUB_LIB_FLAG)

AC_SUBST(SNACK_VERSION)
AC_SUBST(SNACK_PATCH_LEVEL)
AC_SUBST(SNACK_NODOT_VERSION)

AC_OUTPUT(Makefile snackConfig.sh)
