AC_INIT(square.c)

#--------------------------------------------------------------------
#       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 files from DIR],
        SNACK_DIR=$withval, SNACK_DIR=`cd ..; pwd`)

if test "x$SNACK_DIR" = "x"; then
    AC_MSG_ERROR(Could not find Snack directory)
fi
if test ! -d $SNACK_DIR; then
    AC_MSG_ERROR(Snack directory $SNACK_DIR doesn't exist)
fi

SNACK_INC_DIR="${SNACK_DIR}/generic"
SNACK_OBJ_DIR="${SNACK_DIR}/unix"
file=$SNACK_OBJ_DIR/snackConfig.sh
. $file
SNACK_STUB_LIB_FLAG=$SNACK_STUB_LIB_FLAG


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

SQUARE_INSTALL_PATH=${prefix}/lib

#--------------------------------------------------------------------
#       Read in configuration information generated by Tcl 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_SUFFIX=$TCL_SHLIB_SUFFIX
CC=$TCL_CC

#--------------------------------------------------------------------
#       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
    HP-UX-*.10.*)
	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"
	;;
    IRIX*)
	AFLAG="-DIRIX"
        ALIB="-laudio"
	;;
    IRIX64-6.*)
	AFLAG="-DIRIX"
        ALIB="-laudio"
	;;
    Linux*)
	AFLAG="-DLinux"
	;;
    SunOS*)
	AFLAG="-DSolaris"
	;;
    *)
	AFLAG="-DOTHER"
	;;
esac

#--------------------------------------------------------------------
#	Get plug-in install path if needed
#--------------------------------------------------------------------

AC_ARG_ENABLE(plugin,[  --enable-plugin         Enable Plugin],,enableval="no")

if test "$enableval" = "yes"; then
  AC_MSG_CHECKING(Mozilla Home)
# Check for Mozilla home (install directory of netscape (plugins))
  AC_ARG_WITH(mozilla, [  --with-mozilla=DIR      will install in DIR/plugins and DIR/tclplug],
	MOZILLA_DIR=$withval, MOZILLA_DIR="$MOZILLA_HOME")
  if test -z "$MOZILLA_DIR"; then
    MOZILLA_DIR=/usr/local/lib/netscape
  fi
  if test ! -d "$MOZILLA_DIR"; then
    AC_MSG_ERROR(Mozilla home directory \"$MOZILLA_DIR\" doesn't exist: use configure --with-mozilla=MOZILLA_HOME - ie. --with-mozilla=$HOME/.netscape for a personal install)
  fi
  AC_MSG_RESULT(found. Will install plugin in \"$MOZILLA_DIR\")
  AC_SUBST(MOZILLA_DIR)
else
  AC_MSG_RESULT(will not install as plugin (normal))
fi

#--------------------------------------------------------------------
#	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_SNACK_STUBS -DUSE_TCL_STUBS"
    TCL_LIB_SPEC="${TCL_STUB_LIB_SPEC}"
    TK_LIB_SPEC="${TK_STUB_LIB_SPEC}"
    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)
fi
#--------------------------------------------------------------------

AC_SUBST(CC)
AC_SUBST(CFLAGS)
AC_SUBST(SHLIB_LD)
AC_SUBST(SHLIB_SUFFIX)
AC_SUBST(XINCLUDES)
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(SQUARE_INSTALL_PATH)
AC_SUBST(AINC)
AC_SUBST(AFLAG)
AC_SUBST(ALIB)
AC_SUBST(SNACK_INC_DIR)
AC_SUBST(SNACK_OBJ_DIR)
AC_SUBST(SNACK_STUB_LIB_FLAG)

AC_OUTPUT(Makefile)
