<?xml version="1.0" encoding="UTF-8"?>

<!-- ********************************************************** -->
<!-- *                                                        * -->
<!-- * Apache Ant build file used to build the FreeTTS demos. * -->
<!-- * To build the demos, just type the following:           * -->
<!-- *                                                        * -->
<!-- *     ant -buildfile demo.xml                            * -->
<!-- *                                                        * -->
<!-- * For more information:  http://ant.apache.org/          * -->
<!-- *                                                        * -->
<!-- ********************************************************** -->
<project basedir="." default="all" name="FreeTTS">

    <!-- ********************************************************** -->
    <!-- *                                                        * -->
    <!-- * Where to find things...                                * -->
    <!-- *                                                        * -->
    <!-- ********************************************************** -->
    <path id="libs">
        <fileset dir="lib" includes="**/*.jar"/>
    </path>
    <property name="src_dir"		value="."/>
    <property name="build_dir"		value="bld"/>
    <property name="classes_dir"	value="${build_dir}/classes"/>
    <property name="demo_classes_dir"	value="${build_dir}/demo_classes"/>
    <property name="lib_dir"            value="lib"/>
    <property name="bin_dir"            value="bin"/>
    <property name="webstart_bld_dir"	value="${build_dir}/webstart"/>
    <property name="webstart_dir"	value="demo/JSAPI/WebStartClock"/>
    <property name="deploy_dir"		value="deploy"/>


    <!-- ********************************************************** -->
    <!-- *                                                        * -->
    <!-- * Handle JSAPI:                                          * -->
    <!-- *                                                        * -->
    <!-- *    1) If a jsapi.jar file can be found, use it and     * --> 
    <!-- *       compile all the sources.                         * -->
    <!-- *                                                        * -->
    <!-- *    2) If a jsapi.jar file cannot be found, issue a     * -->
    <!-- *       message and just compile the sources that do     * -->
    <!-- *       not depend upon jsapi.jar.                       * -->
    <!-- *                                                        * -->
    <!-- ********************************************************** -->
    <target name="-check_jsapi_jar.isPresent">
        <available file="lib/jsapi.jar" property="jsapi_jar.isPresent"/>
    </target>

    <target name="issue_jsapi_warning"
            unless="jsapi_jar.isPresent">
        <echo>
Cannot find lib/jsapi.jar needed to build Java Speech API
(JSAPI) support for FreeTTS.  Will not build any sources
that require jsapi.jar.  If you'd like to enable JSAPI
support, please extract jsapi.jar by running jsapi.sh or 
jsapi.exe from the lib directory.
        </echo>
    </target>


    <!-- ********************************************************** -->
    <!-- *                                                        * -->
    <!-- * Builds just the demos (using package names for the     * -->
    <!-- * demos would have made this easier).                    * -->
    <!-- *                                                        * -->
    <!-- ********************************************************** -->
    <target name="all"
	    depends="make_lib_dir,
	             compile_demo_util,
	             compile_freetts_demos,
	             compile_jsapi_demos"
	    description="Compiles and jars the demos"/>

    <target name="make_lib_dir">
	<mkdir dir="${lib_dir}"/>
    </target>

    <target name="compile_demo_util"
	    description="Compiles utilities used by some of the demos">
	<mkdir dir="${demo_classes_dir}/util"/>
	<javac debug="true"
	       source="1.4"
	       deprecation="true"
	       srcdir="demo/util"
	       destdir="${demo_classes_dir}/util">
	    <classpath>
		<path refid="libs"/>
	    </classpath>
        </javac>
    </target>


    <!-- freetts (non-JSAPI) demos -->
    <target name="compile_freetts_demos"
	    depends="compile_freetts_clientserver,
	             compile_freetts_emacspeak,
	             compile_freetts_helloworld"
	    description="Compiles freetts demos that do not use JSAPI"/>

    <target name="compile_freetts_clientserver"
	    depends="compile_demo_util">
	<mkdir dir="${demo_classes_dir}/freetts/ClientServer"/>
	<javac debug="true"
	       source="1.4"
	       deprecation="true"
	       srcdir="demo/freetts/ClientServer"
	       destdir="${demo_classes_dir}/freetts/ClientServer">
	    <classpath>
		<path refid="libs"/>
		<pathelement location="${demo_classes_dir}/util"/>
	    </classpath>
	</javac>
	<mkdir dir="${bin_dir}"/>
        <jar destfile="${bin_dir}/Client.jar" 
	     manifest="demo/freetts/ClientServer/client.Manifest"
	     basedir="${demo_classes_dir}/freetts/ClientServer"
	     includes="Client.class"
	     filesonly="true"
	     compress="true"/>
        <jar destfile="${bin_dir}/Server.jar" 
	     manifest="demo/freetts/ClientServer/server.Manifest"
	     filesonly="true"
	     compress="true">
            <fileset dir="${demo_classes_dir}/freetts/ClientServer"
	             excludes="Client.class"/>
            <fileset dir="${demo_classes_dir}/util"
	             includes="TTSServer.class"/>
        </jar>
    </target>

    <target name="compile_freetts_emacspeak"
	    depends="compile_demo_util">
	<mkdir dir="${demo_classes_dir}/freetts/Emacspeak"/>
	<javac debug="true"
	       source="1.4"
	       deprecation="true"
	       srcdir="demo/freetts/Emacspeak"
	       destdir="${demo_classes_dir}/freetts/Emacspeak">
	    <classpath>
		<path refid="libs"/>
		<pathelement location="${demo_classes_dir}/util"/>
	    </classpath>
	</javac>
	<mkdir dir="${bin_dir}"/>
        <jar destfile="${bin_dir}/FreeTTSEmacspeakServer.jar" 
	     manifest="demo/freetts/Emacspeak/Manifest"
	     filesonly="true"
	     compress="true">
            <fileset dir="${demo_classes_dir}/freetts/Emacspeak"/>
            <fileset dir="${demo_classes_dir}/util"
	             includes="EmacspeakProtocolHandler.class,
		               TTSServer.class"/>
        </jar>
    </target>

    <target name="compile_freetts_helloworld"
	    depends="compile_demo_util">
	<mkdir dir="${demo_classes_dir}/freetts/HelloWorld"/>
	<javac debug="true"
	       source="1.4"
	       deprecation="true"
	       srcdir="demo/freetts/HelloWorld"
	       destdir="${demo_classes_dir}/freetts/HelloWorld">
	    <classpath>
		<path refid="libs"/>
		<pathelement location="${demo_classes_dir}/util"/>
	    </classpath>
	</javac>
	<mkdir dir="${bin_dir}"/>
        <jar destfile="${bin_dir}/FreeTTSHelloWorld.jar" 
	     manifest="demo/freetts/HelloWorld/Manifest"
	     basedir="${demo_classes_dir}/freetts/HelloWorld"
	     includes="*.class"
	     filesonly="true"
	     compress="true"/>
    </target>


    <!-- JSAPI demos -->
    <target name="compile_jsapi_demos"
	    depends="-check_jsapi_jar.isPresent,
	             issue_jsapi_warning,
	             compile_jsapi_emacspeak,
	             compile_jsapi_helloworld,
	             compile_jsapi_jtime,
	             compile_jsapi_mixedvoices,
	             compile_jsapi_player,
	             compile_jsapi_webstartclock"
	    description="Compiles freetts demos that use JSAPI"/>

    <target name="compile_jsapi_emacspeak"
	    depends="compile_demo_util"
	    if="jsapi_jar.isPresent">
	<mkdir dir="${demo_classes_dir}/JSAPI/Emacspeak"/>
	<javac debug="true"
	       source="1.4"
	       deprecation="true"
	       srcdir="demo/JSAPI/Emacspeak"
	       destdir="${demo_classes_dir}/JSAPI/Emacspeak">
	    <classpath>
		<path refid="libs"/>
		<pathelement location="${freetts_jar}"/>
		<pathelement location="${demo_classes_dir}/util"/>
	    </classpath>
	</javac>
	<mkdir dir="${bin_dir}"/>
        <jar destfile="${bin_dir}/EmacspeakServer.jar" 
	     filesonly="true"
	     compress="true">
            <fileset dir="${demo_classes_dir}/JSAPI/Emacspeak"/>
            <fileset dir="${demo_classes_dir}/util"
	             includes="EmacspeakProtocolHandler.class,
		               TTSServer.class"/>
            <manifest>
                <attribute name="Built-By" value="${user.name}" />
                <attribute name="Main-Class" value="EmacspeakServer" />
                <attribute name="Class-Path"
                    value="../lib/freetts.jar ../lib/freetts-jsapi10.jar ../lib/jsapi.jar" />
                <section name="common">
                  <attribute name="Implementation-Title"
                      value="Emacsspeak server" />
                </section>
            </manifest>
        </jar>
    </target>

    <target name="compile_jsapi_helloworld"
	    depends="compile_demo_util"
	    if="jsapi_jar.isPresent">
	<mkdir dir="${demo_classes_dir}/JSAPI/HelloWorld"/>
	<javac debug="true"
	       source="1.4"
	       deprecation="true"
	       srcdir="demo/JSAPI/HelloWorld"
	       destdir="${demo_classes_dir}/JSAPI/HelloWorld">
	    <classpath>
		<path refid="libs"/>
	    </classpath>
	</javac>
	<mkdir dir="${bin_dir}"/>
        <jar destfile="${bin_dir}/HelloWorld.jar" 
	     basedir="${demo_classes_dir}/JSAPI/HelloWorld"
	     includes="*.class"
	     filesonly="true"
	     compress="true">
            <manifest>
                <attribute name="Built-By" value="${user.name}" />
                <attribute name="Main-Class" value="HelloWorld" />
                <attribute name="Class-Path"
                    value="../lib/freetts.jar ../lib/freetts-jsapi10.jar ../lib/jsapi.jar" />
                <section name="common">
                  <attribute name="Implementation-Title"
                      value="FreeTTS JSAPI 1.0 hello world demo" />
                </section>
            </manifest>
         </jar>
    </target>

    <target name="compile_jsapi_jtime"
	    depends="compile_demo_util"
	    if="jsapi_jar.isPresent">
	<mkdir dir="${demo_classes_dir}/JSAPI/JTime"/>
	<javac debug="true"
	       source="1.4"
	       deprecation="true"
	       srcdir="demo/JSAPI/JTime"
	       destdir="${demo_classes_dir}/JSAPI/JTime">
	    <classpath>
		<path refid="libs"/>
		<pathelement location="${demo_classes_dir}/util"/>
	    </classpath>
	</javac>
	<mkdir dir="${bin_dir}"/>
        <jar destfile="${bin_dir}/JTime.jar" 
	     filesonly="true"
	     compress="true">
            <fileset dir="${demo_classes_dir}/JSAPI/JTime"/>
            <fileset dir="${demo_classes_dir}/util"
	             includes="TimeUtils.class"/>
            <manifest>
                <attribute name="Built-By" value="${user.name}" />
                <attribute name="Main-Class" value="JTime" />
                <attribute name="Class-Path"
                    value="../lib/freetts.jar ../lib/freetts-jsapi10.jar ../lib/jsapi.jar" />
                <section name="common">
                  <attribute name="Implementation-Title"
                      value="FreeTTS JSAPI 1.0 JTime demo" />
                </section>
            </manifest>
        </jar>
    </target>

    <target name="compile_jsapi_mixedvoices"
	    depends="compile_demo_util"
	    if="jsapi_jar.isPresent">
	<mkdir dir="${demo_classes_dir}/JSAPI/MixedVoices"/>
	<javac debug="true"
	       source="1.4"
	       deprecation="true"
	       srcdir="demo/JSAPI/MixedVoices"
	       destdir="${demo_classes_dir}/JSAPI/MixedVoices">
	    <classpath>
		<path refid="libs"/>
	    </classpath>
	</javac>
	<mkdir dir="${bin_dir}"/>
        <jar destfile="${bin_dir}/MixedVoices.jar" 
	     basedir="${demo_classes_dir}/JSAPI/MixedVoices"
	     includes="*.class"
	     filesonly="true"
	     compress="true">
            <manifest>
                <attribute name="Built-By" value="${user.name}" />
                <attribute name="Main-Class" value="MixedVoices" />
                <attribute name="Class-Path"
                    value="../lib/freetts.jar ../lib/freetts-jsapi10.jar ../lib/jsapi.jar" />
                <section name="common">
                  <attribute name="Implementation-Title"
                      value="FreeTTS JSAPI 1.0 mixed voices demo" />
                </section>
            </manifest>
        </jar>
    </target>

    <target name="compile_jsapi_player"
	    depends="compile_demo_util"
	    if="jsapi_jar.isPresent">
	<mkdir dir="${demo_classes_dir}/JSAPI/Player"/>
	<javac debug="true"
	       source="1.4"
	       deprecation="true"
	       srcdir="demo/JSAPI/Player"
	       destdir="${demo_classes_dir}/JSAPI/Player">
	    <classpath>
		<path refid="libs"/>
	    </classpath>
	</javac>
	<mkdir dir="${bin_dir}"/>
        <jar destfile="${bin_dir}/Player.jar" 
	     basedir="${demo_classes_dir}/JSAPI/Player"
	     includes="*.class"
	     filesonly="true"
	     compress="true">
            <manifest>
                <attribute name="Built-By" value="${user.name}" />
                <attribute name="Main-Class" value="Player" />
                <attribute name="Class-Path"
                    value="../lib/freetts.jar ../lib/freetts-jsapi10.jar ../lib/jsapi.jar" />
                <section name="common">
                  <attribute name="Implementation-Title"
                      value="FreeTTS JSAPI 1.0 player demo" />
                </section>
            </manifest>
       </jar>
    </target>

    <target name="compile_jsapi_webstartclock"
	    depends="compile_demo_util"
	    if="jsapi_jar.isPresent">
	<mkdir dir="${demo_classes_dir}/JSAPI/WebStartClock"/>
	<javac debug="true"
	       source="1.4"
	       deprecation="true"
	       srcdir="demo/JSAPI/WebStartClock"
	       destdir="${demo_classes_dir}/JSAPI/WebStartClock">
	    <classpath>
		<path refid="libs"/>
		<pathelement location="${demo_classes_dir}/util"/>
	    </classpath>
	</javac>
	<mkdir dir="${bin_dir}"/>
        <jar destfile="${bin_dir}/WebStartClock.jar" 
	     filesonly="true"
	     compress="true">
            <fileset dir="${demo_classes_dir}/JSAPI/WebStartClock"/>
            <fileset dir="${demo_classes_dir}/util"
	             includes="TimeUtils.class"/>
               
            <manifest>
                <attribute name="Built-By" value="${user.name}" />
                <attribute name="Main-Class" value="JSAPIClock" />
                <attribute name="Class-Path"
                    value="../lib/freetts.jar ../lib/freetts-jsapi10.jar ../lib/jsapi.jar" />
                <section name="common">
                  <attribute name="Implementation-Title"
                      value="FreeTTS JSAPI 1.0 webstart clock demo" />
                </section>
            </manifest>
        </jar>
    </target>


    <!-- ********************************************************** --> 
    <!-- *                                                        * -->
    <!-- * Make the WebStartClock.tar package for deployment.     * -->
    <!-- *                                                        * -->
    <!-- ********************************************************** --> 
    <property name="keystore" value="${webstart_bld_dir}/keystore"/>
    <property name="keypass" value="freetts"/>
    <target name="check_keystore.isPresent">
        <available file="${keystore}" property="keystore.isPresent"/>
    </target>
    <target name="genkey" 
	    depends="check_keystore.isPresent"
	    if="jsapi_jar.isPresent"
	    unless="keystore.isPresent">
	<mkdir dir="${webstart_bld_dir}"/>
        <genkey alias="freetts"
		storepass="${keypass}"
		keypass="${keypass}"
		keystore="${keystore}">
            <dname>
                <param name="CN" value="Sun Labs"/>
                <param name="OU" value="Sun Microsystems"/>
                <param name="O"  value="Sun Microsystems"/>
                <param name="L"  value="Burlington"/>
                <param name="ST" value="MA"/>
                <param name="C"  value="US"/>
            </dname>
        </genkey>
    </target>

    <target name="deploy_webstartclock"
	    depends="all,compile_jsapi_webstartclock,genkey"
	    if="jsapi_jar.isPresent">
        <copy file="lib/jsapi.jar" todir="${webstart_bld_dir}"/>
        <signjar jar="${webstart_bld_dir}/jsapi.jar"
		 alias="freetts"
		 storepass="${keypass}"
		 keypass="${keypass}"
		 keystore="${keystore}"/>
	<copy file="${webstart_bld_dir}/jsapi.jar" todir="${webstart_dir}"/>

        <copy file="${lib_dir}/freetts.jar" todir="${webstart_bld_dir}"/>
        <signjar jar="${webstart_bld_dir}/freetts.jar"
		 alias="freetts"
		 storepass="${keypass}"
		 keypass="${keypass}"
		 keystore="${keystore}"/>
        <copy file="${webstart_bld_dir}/freetts.jar" todir="${webstart_dir}"/>

        <copy file="${lib_dir}/freetts-jsapi10.jar" todir="${webstart_bld_dir}"/>
        <signjar jar="${webstart_bld_dir}/freetts-jsapi10.jar"
          alias="freetts"
          storepass="${keypass}"
          keypass="${keypass}"
          keystore="${keystore}"/>
        <copy file="${webstart_bld_dir}/freetts-jsapi10.jar" todir="${webstart_dir}"/>

        <copy file="${lib_dir}/en_us.jar" todir="${webstart_bld_dir}"/>
        <signjar jar="${webstart_bld_dir}/en_us.jar"
		 alias="freetts"
		 storepass="${keypass}"
		 keypass="${keypass}"
		 keystore="${keystore}"/>
	<copy file="${webstart_bld_dir}/en_us.jar" todir="${webstart_dir}"/>

        <copy file="${lib_dir}/cmutimelex.jar" todir="${webstart_bld_dir}"/>
        <signjar jar="${webstart_bld_dir}/cmutimelex.jar"
		 alias="freetts"
		 storepass="${keypass}"
		 keypass="${keypass}"
		 keystore="${keystore}"/>
	<copy file="${webstart_bld_dir}/cmutimelex.jar" 
	      todir="${webstart_dir}"/>

        <copy file="${lib_dir}/cmu_time_awb.jar" todir="${webstart_bld_dir}"/>
        <signjar jar="${webstart_bld_dir}/cmu_time_awb.jar"
		 alias="freetts"
		 storepass="${keypass}"
		 keypass="${keypass}"
		 keystore="${keystore}"/>
	<copy file="${webstart_bld_dir}/cmu_time_awb.jar" 
	      todir="${webstart_dir}"/>

        <copy file="${bin_dir}/WebStartClock.jar" todir="${webstart_bld_dir}"/>
        <signjar jar="${webstart_bld_dir}/WebStartClock.jar"
		 alias="freetts"
		 storepass="${keypass}"
		 keypass="${keypass}"
		 keystore="${keystore}"/>
	<copy file="${webstart_bld_dir}/WebStartClock.jar" 
	      todir="${webstart_dir}"/>

	<mkdir dir="${deploy_dir}"/>
        <tar destfile="${deploy_dir}/WebStartClock.tar">
	     <tarfileset dir="${webstart_bld_dir}" includes="*.jar"/>
             <tarfileset dir="demo/JSAPI/WebStartClock"
			 includes="clock.jnlp"/>
        </tar>
        <echo message="${deploy_dir}/WebStartClock.tar created."/>
        <echo message=
            "scp it to the following directory on freetts.sourceforge.net:"/>
        <echo message=
            "    /home/groups/f/fr/freetts/htdocs/WebStartClock"/>
        <echo message="Then ssh to freetts.sourceforge.net and untar it."/>
    </target>


    <!-- ********************************************************** --> 
    <!-- *                                                        * -->
    <!-- * Makes a standalone emacspeak server (non-JSAPI) jar    * -->
    <!-- * that can be run using java -jar.                       * -->
    <!-- *                                                        * -->
    <!-- * NOTE: This requires an "ant" to have been run so that  * -->
    <!-- * the classes directory will be fully populated.         * -->
    <!-- *                                                        * -->
    <!-- ********************************************************** --> 
    <target name="emacspeak-server"
	    depends="compile_freetts_emacspeak">
	<mkdir dir="${build_dir}/tmp/com/sun/speech/freetts"/>
        <copy file="lib/voices.txt" 
	      tofile="${build_dir}/tmp/com/sun/speech/freetts/internal_voices.txt"/>
        <replace
            file="${build_dir}/tmp/com/sun/speech/freetts/internal_voices.txt"
	    token="com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory"
	    value="#com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory"/>
        <replace
            file="${build_dir}/tmp/com/sun/speech/freetts/internal_voices.txt"
	    token="#de.dfki.lt.freetts.en.us.MbrolaVoiceDirectory"
	    value="de.dfki.lt.freetts.en.us.MbrolaVoiceDirectory"/>

        <jar destfile="emacspeak-server.jar"
             compress="true">
            <fileset dir="${classes_dir}"
                     excludes="com/sun/speech/engine/**,
		               com/sun/speech/freetts/jsapi/**,
		               com/sun/speech/freetts/en/us/CMUTime**,
		               com/sun/speech/freetts/en/us/cmutime**,
		               com/sun/speech/freetts/en/us/cmu_time**"/>
            <fileset
	        dir="${src_dir}"
	        includes="com/sun/speech/freetts/en/us/*.txt"
	        excludes="**/cmu*lex*.txt"/>
            <fileset dir="${demo_classes_dir}/util"
		     excludes="Time**"/>
            <fileset dir="${demo_classes_dir}/freetts/Emacspeak"/>
            <fileset dir="${build_dir}/tmp"/>
            <manifest>
	        <attribute name="Main-Class"
			   value="FreeTTSEmacspeakServer"/>
            </manifest>
        </jar>
	<delete dir="${build_dir}/tmp"/>
    </target>


    <!-- ********************************************************** --> 
    <!-- *                                                        * -->
    <!-- * Deletes all build output and *~ file droppings         * -->
    <!-- *                                                        * -->
    <!-- ********************************************************** --> 
    <target name="clean" description="Delete all build output">
	<delete quiet="true" includeEmptyDirs="true">
	    <fileset defaultexcludes="no" dir="." includes="**/*~"/>
	</delete>
	<delete dir="${bin_dir}"/>
	<delete dir="${build_dir}"/>
	<delete dir="${deploy_dir}"/>
    </target>

</project>
