AC_INIT(ChangeLog)

GNOME_SPEECH_MAJOR_VERSION=0
GNOME_SPEECH_MINOR_VERSION=3
GNOME_SPEECH_MICRO_VERSION=6
GNOME_SPEECH_INTERFACE_AGE=0
GNOME_SPEECH_BINARY_AGE=0
GNOME_SPEECH_VERSION="$GNOME_SPEECH_MAJOR_VERSION.$GNOME_SPEECH_MINOR_VERSION.$GNOME_SPEECH_MICRO_VERSION"
AM_INIT_AUTOMAKE(gnome-speech, $GNOME_SPEECH_VERSION)
AC_SUBST(GNOME_SPEECH_MAJOR_VERSION)
AC_SUBST(GNOME_SPEECH_MINOR_VERSION)
AC_SUBST(GNOME_SPEECH_MICRO_VERSION)
AC_SUBST(GNOME_SPEECH_INTERFACE_AGE)
AC_SUBST(GNOME_SPEECH_BINARY_AGE)

# libtool versioning
LT_CURRENT=7
LT_REVISION=1
LT_AGE=0
LT_VERSION_INFO='-version-info ${LT_CURRENT}:${LT_REVISION}:${LT_AGE}'
AC_SUBST(LT_VERSION_INFO)
AC_SUBST(LT_RELEASE)
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)

dnl Specify a header configuration file
AM_CONFIG_HEADER(config.h)

dnl Initialize maintainer mode
AM_MAINTAINER_MODE


dnl Checks for programs
AC_PROG_CC
AC_PROG_INSTALL
AC_ISC_POSIX

GNOME_COMMON_INIT
GNOME_COMPILE_WARNINGS(maximum)
AC_SUBST(CFLAGS)


dnl Initialize libtool
AM_DISABLE_STATIC
AM_PROG_LIBTOOL

dnl Checks for libraries
PKG_CHECK_MODULES(gnome_speech, bonobo-activation-2.0 >= 0.9.1 libbonobo-2.0 >= 1.97.0 ORBit-2.0 >= 2.3.94)
AC_SUBST(gnome_speech_LIBS)
AC_SUBST(gnome_speech_CFLAGS)

dnl orbit-idl.
ORBIT_IDL="`$PKG_CONFIG --variable=orbit_idl ORBit-2.0`"
AC_SUBST(ORBIT_IDL)

dnl Bonobo and Bonobo-Activation idl files
BONOBO_ACTIVATION_IDL_DIR="`$PKG_CONFIG --variable=idldir bonobo-activation-2.0`"
LIBBONOBO_IDL_DIR="`$PKG_CONFIG --variable=idldir libbonobo-2.0`"
AC_SUBST(BONOBO_ACTIVATION_IDL_DIR)
AC_SUBST(LIBBONOBO_IDL_DIR)

AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)

# The various speech drivers can only be built if the appropriate libs for each are installed

# Check to see if we should build the Viavoice driver

AC_ARG_WITH(viavoice_dir, {   --with-viavoice-dir=PATH	Specify path to Viavoice})
if test x$with_viavoice_dir != x ; then
        viavoice_LIBS="-L$with_viavoice_dir/lib -libmeci"
        viavoice_INCLUDES="-I$with_viavoice_dir/inc"
else
	AC_CHECK_LIB(ibmeci, eciNew, viavoice_LIBS=-libmeci)
	viavoice_INCLUDES="-I/opt/IBM/ibmtts/inc"
fi
AC_SUBST(viavoice_LIBS)
AC_SUBST(viavoice_INCLUDES)
AM_CONDITIONAL(BUILD_VIAVOICE_DRIVER, test "x$viavoice_LIBS" != "x")

# Check to see if we should build the Dectalk driver
AC_ARG_WITH(dectalk_dir, {   --with-dectalk-dir=PATH	Specify path to DECTalk})
if test x$with_dectalk_dir != x ; then
        dectalk_LIBS="-L$with_dectalk_dir/lib -ltts"
        dectalk_INCLUDES="-I$with_dectalk_dir/include"
else
	AC_CHECK_LIB(tts, TextToSpeechSync, dectalk_LIBS=-ltts)
	dectalk_INCLUDES=""
fi
AC_SUBST(dectalk_LIBS)
AC_SUBST(dectalk_INCLUDES)
AM_CONDITIONAL(BUILD_DECTALK_DRIVER, test "x$dectalk_LIBS" != "x")

# Check to see if we should build the Theta driver
AC_ARG_WITH(theta_dir, {   --with-theta-dir=PATH	Specify path to Theta})
if test x$with_theta_dir == x ; then
   # Check default location /opt/theta

   with_theta_dir="/opt/theta"
fi

AC_CHECK_FILE("$with_theta_dir/bin/theta-config", theta_config="$with_theta_dir/bin/theta-config")
if test x$theta_config != x ; then
   theta_LIBS=`$theta_config --libs`
   theta_INCLUDES=`$theta_config --cflags`/swift
fi

AC_SUBST(theta_LIBS)
AC_SUBST(theta_INCLUDES)
AM_CONDITIONAL(BUILD_THETA_DRIVER, test "x$theta_LIBS" != "x")

# Eloquence driver  Setup

AC_ARG_WITH(eloquence_dir, {   --with-eloquence-dir=PATH	Specify path to Eloquence})

if test x$with_eloquence_dir != x ; then
   eloquence_INCLUDEDIR="$with_eloquence_dir/include"
   eloquence_LIBDIR="$with_eloquence_dir/redist/common_module"
   AC_SUBST(eloquence_INCLUDEDIR)
   AC_SUBST(eloquence_LIBDIR)
fi
AM_CONDITIONAL(BUILD_ELOQUENCE_DRIVER, test "x$with_eloquence_dir" != "x")

# Java support

AC_ARG_WITH(java_home, {   --with-java-home=PATH  	Use the jdk at PATH})
if test "x$with_java_home" != "x" ; then
   JAVA_HOME=$with_java_home
else
    JAVA_HOME=`type javah | sed -e "s/^javah is //" -e "s/\/bin\/javah//"`
fi

# Find the java executeable

if test "x$JAVA_HOME" != "x" ; then
  AC_CHECK_FILE("$JAVA_HOME/bin/java", JAVA="$JAVA_HOME/bin/java",
	[JAVA="no"
	 AC_MSG_NOTICE([Java executeable not found])])
else
  AC_CHECK_PROG(JAVA, java, java, no)
fi

# Find the java compiler

if test "x$JAVA_HOME" != "x" ; then
  AC_CHECK_FILE("$JAVA_HOME/bin/javac", JAVAC="$JAVA_HOME/bin/javac",
	[JAVAC="no"
	 AC_MSG_NOTICE([Java Compiler not found])])
else
  AC_CHECK_PROG(JAVAC, javac, javac, no)
fi

# Find the Java Header Generator

if test "x$JAVA_HOME" != "x" ; then
  AC_CHECK_FILE("$JAVA_HOME/bin/javah", JAVAH="$JAVA_HOME/bin/javah",
	[JAVAH="no"
	 AC_MSG_NOTICE([Java Header Generator not found])])
else
  AC_CHECK_PROG(JAVAH, javah, javah, no)
fi

# Find Java's IDL compiler

if test "x$JAVA_HOME" != "x" ; then
  AC_CHECK_FILE("$JAVA_HOME/bin/idlj", IDLJ="$JAVA_HOME/bin/idlj",
	[IDLJ="no"
	 AC_MSG_NOTICE([Java IDL Code Generator not found])])
else
  AC_CHECK_PROG(IDLJ, idlj, idlj, no)
fi

# Find the jar utiility

if test "x$JAVA_HOME" != "x" ; then
  AC_CHECK_FILE("$JAVA_HOME/bin/jar", JAR="$JAVA_HOME/bin/jar",
	[JAR="no"
	 AC_MSG_NOTICE([Jar utility not found])])
else
  AC_CHECK_PROG(JAR, jar, jar, no)
fi

# Find the Java Access Bridge

AC_ARG_WITH(jab_dir, {   --with-jab-dir=PATH	Specify path to Java Access Bridge})
if test "x$with_jab_dir" != "x" ; then
  AC_CHECK_FILE("$with_jab_dir/gnome-java-bridge.jar", JAB="$with_jab_dir/gnome-java-bridge.jar",
	[AC_MSG_NOTICE([Java Access Bridge not found])])
else
  AC_CHECK_FILE("$prefix/share/jar/gnome-java-bridge.jar", JAB="$prefix/share/jar/gnome-java-bridge.jar",
	[AC_MSG_NOTICE([Java Access Bridge not found])])
fi

AC_SUBST(JAVA_HOME)
AC_SUBST(JAVA)
AC_SUBST(JAVAC)
AC_SUBST(JAVAH)
AC_SUBST(IDLJ)
AC_SUBST(JAR)
AC_SUBST(JAB)

# conditional to build java package

if test "x$JAVAC" = "xno" || \
   test "x$JAVA" = "xno" || \
   test "x$IDLJ" = "xno" || \
   test "x$JAB" = "xno" ; then
   JAVA_SUPPORT="false"
else
   JAVA_SUPPORT="true"
fi
AC_SUBST(JAVA_SUPPORT)
AM_CONDITIONAL(BUILD_JAVA_PACKAGE, test "x$JAVA_SUPPORT" = "xtrue")

AC_SUBST(BUILD_JAVA_PACKAGE)

# GNOME Speech Java Package location

GNOME_SPEECH_JAR_DIR="$prefix/share/jar"
GNOME_SPEECH_INSTALLED_CLASSPATH="$GNOME_SPEECH_JAR_DIR/gnome-speech.jar:$JAB"
GNOME_SPEECH_CLASSPATH="$GNOME_SPEECH_JAR_DIR/java/gnome-speech.jar:$JAB"
AC_SUBST(GNOME_SPEECH_JAR_DIR)
AC_SUBST(GNOME_SPEECH_INSTALLED_CLASSPATH)
AC_SUBST(GNOME_SPEECH_CLASSPATH)

# FreeTTS Setup

AC_ARG_WITH(freetts_dir, {   --with-freetts-dir=PATH	Specify path to FreeTTS})

if test x$with_freetts_dir != x ; then
   if test x$JAVA_SUPPORT != xtrue; then
      AC_MSG_ERROR([Java support is required to build the FreeTTS driver])
   fi
   FREETTS_JAR_DIR="$with_freetts_dir"
   AC_SUBST(FREETTS_JAR_DIR)
   FREETTS_CLASSPATH="$FREETTS_JAR_DIR/freetts.jar:$FREETTS_JAR_DIR/en_us.jar:$FREETTS_JAR_DIR/cmulex.jar:$FREETTS_JAR_DIR/cmu_us_kal.jar"
   AC_SUBST(FREETTS_CLASSPATH)
   case "$host" in
   *-solaris*)
   freetts_driver_type_solaris=true;;
   *)
   freetts_driver_type_linux=true;;
   esac
fi
AM_CONDITIONAL(BUILD_FREETTS_DRIVER_LINUX, test x$freetts_driver_type_linux = xtrue)
AM_CONDITIONAL(BUILD_FREETTS_DRIVER_SOLARIS, test x$freetts_driver_type_solaris = xtrue)
AM_CONDITIONAL(BUILD_FREETTS_DRIVER, test "x$FREETTS_JAR_DIR" != "x")

# FreeTTS Driver

FREETTS_DRIVER_JAR_DIR="$prefix/share/jar"
FREETTS_DRIVER_CLASSPATH="$FREETTS_DRIVER_JAR_DIR/freetts-synthesis-driver.jar"
AC_SUBST(FREETTS_DRIVER_JAR_DIR)
AC_SUBST(FREETTS_DRIVER_CLASSPATH)
AC_OUTPUT([
Makefile
gnome-speech-1.0.pc
gnome-speech.spec
INSTALL
gnome-speech/Makefile
idl/Makefile
java/Makefile
drivers/Makefile
drivers/dectalk/Makefile
drivers/dectalk/GNOME_Speech_SynthesisDriver_Dectalk.server
drivers/theta/Makefile
drivers/theta/GNOME_Speech_SynthesisDriver_Theta.server
drivers/eloquence/Makefile
drivers/eloquence/GNOME_Speech_SynthesisDriver_Eloquence.server
drivers/festival/Makefile
drivers/festival/GNOME_Speech_SynthesisDriver_Festival.server
drivers/freetts/Makefile
drivers/freetts/native/Makefile
drivers/freetts/java/Makefile
drivers/freetts/java/org/Makefile
drivers/freetts/java/org/GNOME/Makefile
drivers/freetts/java/org/GNOME/Speech/Makefile
drivers/freetts/freetts-synthesis-driver
drivers/freetts/GNOME_Speech_SynthesisDriver_FreeTTS.server
drivers/viavoice/Makefile
drivers/viavoice/GNOME_Speech_SynthesisDriver_Viavoice.server
test/Makefile
doc/Makefile
])


echo "

GNOME Speech $GNOME_SPEECH_VERSION Build Setup:"


echo "
Build Festival Driver:	yes"

echo ""
if test x$dectalk_LIBS != x ; then
echo "Build DECTalk Driver:	yes"
echo "DECTalk libs:		$dectalk_LIBS"
else
echo "Build DECTalk Driver:	no"
fi

echo ""
if test "x$theta_LIBS" != "x" ; then
echo "Build Theta Driver:	yes"
echo "Theta libs:		$theta_LIBS"
else
echo "Build Theta Driver:	no"
fi

echo ""
if test x$eloquence_LIBS != x ; then
echo "Build Eloquence Driver:	yes"
echo "Eloquence libs:		$eloquence_LIBS"
else
echo "Build Eloquence Driver:	no"
fi

echo ""
if test "x$viavoice_LIBS" != "x" ; then
echo "Build Viavoice Driver:	yes"
echo "Viavoice libs:		$viavoice_LIBS"
else
echo "Build Viavoice Driver:	no"
fi

echo ""
if test "x$JAVA_SUPPORT" = "xtrue"; then
echo "Java Support:		yes"
echo "Java:			$JAVA"
echo "Javac:			$JAVAC"
echo "Idlj:			$IDLJ"
echo "Jar:			$JAR"
echo "Access Bridge Location:	$JAB"
else
echo "Java Support:		no"
fi

echo ""
if test x$FREETTS_JAR_DIR != x ; then
echo "Build FreeTTS Driver:	yes"
if test x$freetts_driver_type_linux != x ; then
echo "FreeTTS Driver Type:	    Linux"
fi
if test x$freetts_driver_type_solaris != x ; then
echo "FreeTTS Driver Type:	    Solaris"
fi
echo "FreeTTS Jar Directory:	$FREETTS_JAR_DIR"
else
echo "Build FreeTTS Driver:	no"
fi

echo ""
