<?xml version="1.0"?>
<!-- A build file for use by Ant to build Kawa. -->
<project name="Kawa" default="all" basedir=".">
  <!-- Give the user a chance to override the defaults. -->
  <property file="build.properties"/>
  
  <property name="version.release" value="1.7"/>
  <property name="version.local" value=""/>
  <property name="version" value="${version.release}${version.local}"/>

  <property name="debug"        value="true" />
  <property name="deprecation"  value="false" />
  <property name="optimize"     value="true" />
  
  <!--
    There was some discussion of using user.dir as a default here.
    The most promising use being for dist.dir (and maybe build.dir).
    But I decided against that for several reasons:
      1) Consistency (don't make a special case).
      2) The user.dir property isn't reliable (some bad JVMs out there).
      3) Ant is not able to handle both absolute and relative paths
         for commandline arguments based on user.dir.  Ant automatically
         handles relative paths relative to basedir, not user.dir.
         As a result, if dist.dir defaulted to user.dir,
         "ant -buildfile ../kawa/build.xml" and
         "ant -buildfile ../kawa/build.xml -Ddist.dir=." 
         would produce different results.
      4) The value of user.dir is not useful when using a Java IDE
         (like NetBeans or JBuilder) since it is the directory that 
         happened to be current when the IDE started.
    So, the only way to use Ant where the current directory (user.dir)
    is not the directory containing the buildfile, you *must* supply
    absolute paths as arguments.  That is:
    "ant -buildfile ../kawa/build.xml -Ddist.dir=`pwd`/."
    The exception is Ant's arguments themselves, which are processed
    as plain Java files and so are relative to the current directory.
  -->
  <property name="src.dir"      value="${basedir}"/>
  <property name="build.dir"    value="${basedir}"/>
  <property name="dist.dir"     value="${build.dir}"/>
  
  <property name="build.tools"        value="${build.dir}/tools"/>
  <property name="build.tmp"          value="${build.dir}/tmp"/>
  <property name="build.preprocessed" value="${build.dir}"/>
  <property name="build.classes"      value="${build.dir}"/>
  
  <property name="dist.kawa.jar"    value="${dist.dir}/kawa-${version}.jar"/>
  
  <!-- 
     Set preprocess.overwrite true to force preprocessing.
     Eventually this will be dependency checked.
     For now use "ant clean" if anything changes.
  -->
  <property name="preprocess.overwrite" value="false"/>

  <target name="all" depends="classes, jar"/>

  <target name="classes" 
          depends="java-classes, lib-scm-classes
          , slib-scm-classes, commonlisp-scm-classes
          , xml-classes, servlet-classes, jemacs-classes" />
  
  <!-- 
     These are the files that are Kawa.    
     They go in the classpath, jar, and are deleted by clean.
     If additional files (resources like properties and the
     like) are added, something will need to be done so that
     clean will still work when build.classes=src.dir.
  -->
  <fileset id="build.classes" dir="${build.classes}">
     <include name="gnu/**/*.class"/>
     <include name="kawa/**/*.class"/>
  </fileset>
  
  <!-- 
     These are the files that are preprocessed before compiling.    
     In order to allow them to be mixed with the original source,
     we must list them each here.
  -->
  <fileset id="build.preprocessed" dir="${build.preprocessed}">
     <include name="gnu/xml/ParsedXMLHandler.java"/>
     <include name="gnu/xml/ParsedXMLHandlerByte.java"/>
     <include name="gnu/xml/XMLParserChar.java"/>
     <include name="gnu/xml/XMLParserByte.java"/>
     <include name="kawa/Version.java"/>
  </fileset>
  
  <patternset id="build.selectjava">
     <include name="gnu/bytecode/ObjectType.java"/>
     <include name="gnu/lists/AbstractSequence.java"/>
     <include name="gnu/lists/Convert.java"/>
     <include name="gnu/lists/SeqPosition.java"/>
     <include name="gnu/lists/Sequence.java"/>
     <include name="gnu/lists/SimpleVector.java"/>
     <include name="gnu/mapping/CallContext.java"/>
     <include name="gnu/kawa/xml/Focus.java"/>
     <include name="gnu/kawa/xml/ListItems.java"/>
     <include name="gnu/kawa/xml/IteratorItems.java"/>
  </patternset>

  <target name="run" depends="classes">
     <java taskname="kawa" classname="kawa.repl" classpath="${build.classes}" />
  </target>
  
  <target name="runw" depends="classes">
     <java taskname="kawa" fork="true"
           classname="kawa.repl" classpath="${build.classes}">
       <arg value="-w"/>
     </java>
  </target>
  
  <!--
    This is part of an "if" trick.  Do not change me.
    The "if" attribute for tasks is not true if the property is not
    set at all, not whether the value is "true" or "false".
    So here we use the value of the with- or enable- properties
    and rely on true being "true" with this property defined,
    and false being "false" with that property not defined.
  -->
  <property name="true" value="true"/>

  <target name="build-settings" depends="build-tools">
    <!--
       In the following you'll see that each conditional property is set
       twice.  That is because available will not set the property at
       all if the condition is false.  We need the explicit "false" value
       so that we can work consistently with "-D" and build.properties.
       Ant only sets a property once (within a given task chain) and so
       the second setting is ignored if "available" set it to "true".
    -->
    
    <!-- 
       If java.awt.Component is in the classpath, then we'll compile the
       AWT UI, unless you override the setting of with-awt.
    -->
    <available property="with-awt" classname="java.awt.Component"/>
    <property name="with-awt" value="false"/>
    
    <!-- 
       If org.xml.sax.ContentHandler is in the classpath, then we'll compile
       in SAX2 support, unless you override the setting of with-sax2.
    -->
    <available property="with-sax2" classname="org.xml.sax.ContentHandler"/>
    <property name="with-sax2" value="false"/>
    
    <!-- 
       If java.awt.Component is in the classpath, then we'll compile the
       JEmacs Swing UI, unless you override the setting of with-swing.
    -->
    <available property="with-swing" classname="javax.swing.JComponent"/>
    <property name="with-swing" value="false"/>

    <!--
       JEmacs stuff is compiled if Swing is used, unless enable-jemacs is false.
    -->
    <property name="enable-jemacs" value="${with-swing}"/>

    <property name="enable-xml" value="true"/>

    <!--
       If javax.servlet.http.HttpServlet is in the classpath, then we'll
       compile Kawa' servlet interface, unless you override enable-servlet.
    -->
    <!-- The servlet code uses methods from the 2.3 specification now.
         So test for a class that is new for the 2.3 API.
    -->
    <available property="enable-servlet" classname="javax.servlet.Filter"/>
    <property name="enable-servlet" value="false"/>
  
    <echo>
        version=${version}
        dist.kawa.jar=${dist.kawa.jar}
        build.dir=${build.dir}
        with-awt=${with-awt}
        with-swing=${with-swing}
        with-sax2=${with-sax2}
        enable-jemacs=${enable-jemacs}
        enable-xml=${enable-xml}
        enable-servlet=${enable-servlet}
    </echo>

    <!-- 
       This dummy copy is just so we can reference the sets by id.
       This is needed because we are not able to put linestrippersets
       in a task or project the way we can with filtersets.
       Ant gives "Overriding previous definition of reference to..."
       warnings.  Can't seem to avoid that.
    -->

    <xcopy dataOnly="true">
      <linestripperset id="strip-byte-subs">
        <linestripper first="if CHAR is char" last="endif CHAR is char" />
      </linestripperset>

      <linestripperset id="strip-char-subs">
        <linestripper first="if CHAR is byte" last="endif CHAR is byte" />
      </linestripperset>

    </xcopy>
  </target>
  
  <target name="build-tools">
    <mkdir dir="${build.tools}"/>
    <mkdir dir="${build.tmp}"/>
    <!-- 
      This didn't work in NetBeans for some reason. 
      (Even the includejavaruntime/includeantruntime attributes do no good.
      The really weird thing is that NetBeans has access to the classes
      for autocomplete and the scripting window.  Oh well.)
      The workaround is to link to ant.jar.
    -->
    <javac srcdir="${src.dir}"
           destdir="${build.tools}"
           classpath="lib/ext/ant.jar"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}">
      <include name="gnu/kawa/ant/*"/>
    </javac>

    <taskdef name="xcopy"
             classname="gnu.kawa.ant.XCopy"
             classpath="${build.tools}"/>

    <!-- 
       This doesn't really help us because user data 
       definitions don't seem to be possible.
    <typedef name="linestripperset" 
             classname="gnu.kawa.ant.LineStripperSet"
             classpath="${build.tools}"/>
    -->

  </target>
  
  <target name="select-java1" depends="build-tools">
    <xcopy todir="${build.tmp}" overwrite="true">
 	   <fileset dir="${src.dir}">
       	 <patternset refid="build.selectjava"/>
		 <!--
			 <or>
				 <contains text="BEGIN JAVA1"/>
				 <contains text="BEGIN JAVA2"/>
			 </or>
	     -->
      </fileset>
      <linecommenterset begintoken="/* " endtoken=" */" >
        <linecommenter first="BEGIN JAVA2" last="END JAVA2" comment="true"/>
        <linecommenter first="BEGIN JAVA1" last="END JAVA1" comment="false"/>
      </linecommenterset>
    </xcopy>
    <copy todir="${build.preprocessed}">
       <fileset dir="${build.tmp}">
       	 <patternset refid="build.selectjava"/>
       </fileset>          
    </copy>
  </target>
  
  <target name="select-java2" depends="build-tools">
    <mkdir dir="${build.tmp}"/>
    <xcopy todir="${build.tmp}" overwrite="true">
 	   <fileset dir="${src.dir}">
       	 <patternset refid="build.selectjava"/>
		 <!--
			 <or>
				 <contains text="BEGIN JAVA1"/>
				 <contains text="BEGIN JAVA2"/>
			 </or>
	     -->
      </fileset>
      <linecommenterset begintoken="/* " endtoken=" */" >
        <linecommenter first="BEGIN JAVA2" last="END JAVA2" comment="false"/>
        <linecommenter first="BEGIN JAVA1" last="END JAVA1" comment="true"/>
      </linecommenterset>
    </xcopy>
    <copy todir="${build.preprocessed}">
       <fileset dir="${build.tmp}">
       	 <patternset refid="build.selectjava"/>
       </fileset>          
    </copy>
  </target>
    
  <target name="check-for-java2">
     <available property="has-java2" classname="java.lang.ThreadLocal"/>
  </target>
  
  <target name="select-java1-auto" depends="check-for-java2" unless="has-java2">
     <antcall target="select-java1"/>
  </target>
  
  <target name="select-java2-auto" depends="check-for-java2" if="has-java2">
     <antcall target="select-java2"/>
  </target>
  
  <target name="select-java-auto" depends="select-java1-auto, select-java2-auto"/>
  
  <!-- 
     This preprocessing jazz is rather involved and verbose,
     but it is entirely compatible with the makefile code 
     and actually _isn't_ as complicated as I could have made 
     it (as there are still unrolled patterns here that could 
     have been wrapped up but I demurred in consideration of 
     those who may try and grok it).
  -->

      <filterset id="filter-do-not-edit" begintoken="-*-" endtoken="-*-">
        <filter token="Java" 
          value="Automatically generated file - DO NOT EDIT!.  -*- buffer-read-only: t -*-" />
      </filterset>
      
      <filterset id="filter-byte-subs">
        <filter token="CHAR" value="byte" />
        <filter token="XMLParser" value="XMLParserByte" />
        <filter token="ParsedXMLHandler" value="ParsedXMLHandlerByte" />
        <filter token="if CHAR is byte" value="" />
        <filter token="endif CHAR is byte" value="" />
      </filterset>

      <filterset id="filter-char-subs">
        <filter token="CHAR" value="char" />
        <filter token="XMLParser" value="XMLParserChar" />
        <filter token="ParsedXMLHandler" value="ParsedXMLHandler" />
        <filter token="if CHAR is char" value="" />
        <filter token="endif CHAR is char" value="" />
      </filterset>

  <target name="preprocess" depends="build-tools, build-settings">
    <mkdir dir="${build.preprocessed}"/>

    <xcopy todir="${build.preprocessed}/kawa" 
           overwrite="${preprocess.overwrite}">
      <fileset dir="${src.dir}/kawa" includes="*.java.in"/>
      <mapper type="glob" from="*Version.java.in" to="*Version.java"/>
      <filterset refid="filter-do-not-edit"/>
      <filterset begintoken="&quot;" endtoken="&quot;">
        <filter token="VERSION" value="&quot;${version}&quot;" />
      </filterset>
    </xcopy>

    <xcopy todir="${build.preprocessed}/gnu/xml" 
           overwrite="${preprocess.overwrite}">
      <fileset dir="${src.dir}/gnu/xml" />
      <mapper type="glob" from="*XMLParser.java.in" to="*XMLParserChar.java"/>
      <filterset refid="filter-do-not-edit"/>
      <filterset refid="filter-char-subs"/>
      <linestripperset refid="strip-char-subs"/>
    </xcopy>

    <xcopy todir="${build.preprocessed}/gnu/xml" 
           overwrite="${preprocess.overwrite}">
      <fileset dir="${src.dir}/gnu/xml" />
      <mapper type="glob" from="*ParsedXMLHandler.java.in" to="*ParsedXMLHandler.java"/>
      <filterset refid="filter-do-not-edit"/>
      <filterset refid="filter-char-subs"/>
      <linestripperset refid="strip-char-subs"/>
    </xcopy>

    <xcopy todir="${build.preprocessed}/gnu/xml" 
           overwrite="${preprocess.overwrite}">
      <fileset dir="${src.dir}/gnu/xml" />
      <mapper type="glob" from="*XMLParser.java.in" to="*XMLParserByte.java"/>
      <filterset refid="filter-do-not-edit"/>
      <filterset refid="filter-byte-subs"/>
      <linestripperset refid="strip-byte-subs"/>
    </xcopy>

    <xcopy todir="${build.preprocessed}/gnu/xml" 
           overwrite="${preprocess.overwrite}">
      <fileset dir="${src.dir}/gnu/xml" />
      <mapper type="glob" from="*ParsedXMLHandler.java.in" to="*ParsedXMLHandlerByte.java"/>
      <filterset refid="filter-do-not-edit"/>
      <filterset refid="filter-byte-subs"/>
      <linestripperset refid="strip-byte-subs"/>
    </xcopy>

  </target>
  
  <patternset id="with-sax2-false">
  </patternset>

  <patternset id="with-sax2-true">
    <include name="gnu/kawa/sax/"/>
  </patternset>

  <patternset id="with-awt-true"/>
  
  <patternset id="with-awt-false">
    <exclude name="kawa/GuiConsole.java"/>
    <exclude name="kawa/MessageArea.java"/>
    <exclude name="kawa/TextAreaWriter.java"/>
    <exclude name="kawa/GuiInPort.java"/>
  </patternset>
  
  <target name="java-classes" depends="preprocess">
    <mkdir dir="${build.classes}"/>
    <!-- 
       Javac doesn't "shadow" directories, so there may not be duplicates.
       That means that if you're building other than in the source directory,
       then the source directory must be clean.
    -->
    <javac srcdir="${build.preprocessed}:${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}" >
      <include name="gnu/bytecode/"/>
      <include name="gnu/commonlisp/lang/"/>
      <include name="gnu/ecmascript/"/>
      <include name="gnu/expr/"/>
      <include name="gnu/kawa/functions/"/>
      <include name="gnu/kawa/lispexpr/"/>
      <include name="gnu/kawa/reflect/"/>
      <include name="gnu/kawa/util/"/>
      <include name="gnu/lists/"/>
      <include name="gnu/mapping/"/>
      <include name="gnu/math/"/>
      <include name="gnu/text/"/>
      <include name="kawa/lang/"/>
      <include name="kawa/standard/"/>
      <include name="kawa/"/>
      <include name="gnu/kawa/xml/"/>
      <include name="gnu/xml/"/>
      <patternset refid="with-awt-${with-awt}"/>
    </javac>
  </target>
   
  <!-- 
    Can't use apply's dependency checking because
    Kawa can't handle a "-C" with no files listed.
    Also that is probably the wrong thing because
    Kawa needs all the files listed for its scanning.
  -->

  <!--
    These files are in two filesets so that the first
    set is listed before the second in the command 
    line (otherwise they just go in directory order
    and the compile fails).
  -->
      <fileset id="lib-scm-1st" dir="${src.dir}/kawa/lib"> 
        <include name="std_syntax.scm"/>
        <include name="syntax.scm"/>
        <include name="reflection.scm"/>
      </fileset>
      <fileset id="lib-scm-2nd" dir="${src.dir}/kawa/lib">
        <include name="lists.scm"/>
        <include name="thread.scm"/>
        <include name="characters.scm"/>
        <include name="files.scm"/>
        <include name="keywords.scm"/>
        <include name="ports.scm"/>
        <include name="misc.scm"/>
        <include name="numbers.scm"/>
        <include name="strings.scm"/>
        <include name="vectors.scm"/>
        <include name="uniform.scm"/>
        <include name="arrays.scm"/>
        <include name="trace.scm"/>
        <include name="windows.scm"/>
      </fileset>
      <fileset id="lib-scm-3rd" dir="${src.dir}/kawa/lib">
        <include name="system.scm"/>
      </fileset>

  <target name="check-lib-scm-classes">
    <uptodate property="lib-scm-classes-uptodate">
      <mapper type="glob" from="*.scm" to="*.class"/>
      <srcfiles refid="lib-scm-1st"/> 
      <srcfiles refid="lib-scm-2nd"/>
      <srcfiles refid="lib-scm-3rd"/>
    </uptodate>
  </target>

  <target name="lib-scm-classes" 
          depends="java-classes, check-lib-scm-classes" 
          unless="lib-scm-classes-uptodate">
    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <arg value="-classpath"/> <arg path="${build.classes}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P kawa.lib. --module-static -C"/>
      <fileset refid="lib-scm-1st"/>
      <fileset refid="lib-scm-2nd"/>
      <fileset refid="lib-scm-3rd"/>
    </apply>
  </target>
  
      <fileset id="commonlisp-scm" dir="${src.dir}/gnu/commonlisp/lisp"> 
        <include name="PrimOps.scm"/>
      </fileset>

  <target name="check-commonlisp-scm-classes">
    <uptodate property="commonlisp-scm-classes-uptodate">
      <mapper type="glob" from="*.scm" to="*.class"/>
      <srcfiles refid="commonlisp-scm"/>
    </uptodate>
  </target>

  <target name="commonlisp-scm-classes"
          depends="java-classes, check-commonlisp-scm-classes" 
          unless="commonlisp-scm-classes-uptodate">
    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <arg value="-classpath"/> <arg path="${build.classes}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.commonlisp.lisp. --module-static -C"/>
      <fileset refid="commonlisp-scm"/>
    </apply>
  </target>

      <fileset id="slib-scm" dir="${src.dir}/gnu/kawa/slib"> 
        <include name="genwrite.scm"/>
        <include name="pp.scm"/>
        <include name="ppfile.scm"/>
        <include name="printf.scm"/>
        <include name="srfi1.scm"/>
        <include name="readtable.scm"/>
        <include name="DefineRecordType.scm"/>
        <include name="cut.scm"/>
      </fileset>

  <target name="check-slib-scm-classes">
    <uptodate property="slib-scm-classes-uptodate">
      <mapper type="glob" from="*.scm" to="*.class"/>
      <srcfiles refid="slib-scm"/>
    </uptodate>
  </target>

  <target name="slib-scm-classes"
          depends="java-classes, check-slib-scm-classes" 
          unless="slib-scm-classes-uptodate">
    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <arg value="-classpath"/> <arg path="${build.classes}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.kawa.slib. --module-static -C"/>
      <fileset refid="slib-scm"/>
    </apply>
  </target>
  
  <target name="xml-classes" 
          depends="build-settings, java-classes" 
          if="${enable-xml}">
    <javac srcdir="${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}" >
      <include name="gnu/xml/"/>
      <include name="gnu/kawa/xml/"/>
      <include name="gnu/kawa/xslt/"/>
      <include name="gnu/xquery/lang/"/>
      <include name="gnu/xquery/util/"/>
      <include name="gnu/brl/"/>
      <include name="gnu/kawa/brl/"/>
      <patternset refid="with-sax2-${with-sax2}"/>
    </javac>
    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <arg value="-classpath"/> <arg path="${build.classes}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.brl. --module-static -C"/>
      <fileset dir="${src.dir}/gnu/brl"> 
        <include name="stringfun.scm"/>
      </fileset>
    </apply>
    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <arg value="-classpath"/> <arg path="${build.classes}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.kawa.brl. --module-static -C"/>
      <fileset dir="${src.dir}/gnu/kawa/brl"> 
        <include name="progfun.scm"/>
      </fileset>
    </apply>
    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <arg value="-classpath"/> <arg path="${build.classes}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.kawa.slib. --module-static -C"/>
      <fileset dir="${src.dir}/gnu/kawa/slib"> 
        <include name="XML.scm"/>
        <include name="XStrings.scm"/>
      </fileset>
    </apply>
  </target>

  <target name="servlet-classes" 
          depends="build-settings, java-classes" 
          if="${enable-servlet}">
    <javac srcdir="${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}" >
      <include name="gnu/kawa/servlet/"/>
    </javac>
    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <!-- I don't quite get why the Java classpath has to be tacked on here, but it does. -->
      <arg value="-classpath"/> <arg path="${build.classes}:${java.class.path}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.kawa.slib. --module-static -C"/>
      <fileset dir="${src.dir}/gnu/kawa/slib"> 
        <include name="HTTP.scm"/>
      </fileset>
    </apply>
  </target>
   
      <fileset id="jemacs-lang-scm" dir="${src.dir}/gnu/jemacs/lang"> 
        <include name="MiscOps.scm"/>
        <include name="NumberOps.scm"/>
      </fileset>
      <fileset id="jemacs-buffer-scm" dir="${src.dir}/gnu/jemacs/buffer"> 
        <include name="emacs.scm"/>
      </fileset>
      <fileset id="jemacs-slib-scm" dir="${src.dir}/gnu/kawa/slib"> 
        <include name="gui.scm"/>
      </fileset>
      <fileset id="jemacs-el" dir="${src.dir}/gnu/jemacs/lisp"> 
        <include name="primitives.el"/>
        <include name="alist.el"/>
        <include name="simple.el"/>
        <include name="alist.el"/>
        <include name="keymap.el"/>
        <include name="keydefs.el"/>
        <include name="hanoi.el"/>
        <include name="rect.el"/>
        <include name="editfns.el"/>
        <include name="subr.el"/>
        <include name="autoloads.el"/>
      </fileset>

  <target name="check-jemacs-lisp-classes">
    <condition property="jemacs-lisp-classes-uptodate"> 
      <and>
        <uptodate>
          <mapper type="glob" from="*.scm" to="*.class"/>
          <srcfiles refid="jemacs-lang-scm"/>
        </uptodate>
        <uptodate>
          <mapper type="glob" from="*.scm" to="*.class"/>
          <srcfiles refid="jemacs-buffer-scm"/>
        </uptodate>
        <uptodate>
          <mapper type="glob" from="*.scm" to="*.class"/>
          <srcfiles refid="jemacs-slib-scm"/>
        </uptodate>
        <uptodate>
          <mapper type="glob" from="*.el" to="*.class"/>
          <srcfiles refid="jemacs-el"/>
        </uptodate>
      </and>
    </condition>
  </target>

  <target name="jemacs-java-classes" 
          depends="build-settings, java-classes" 
          if="${enable-jemacs}">
    <javac srcdir="${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}" >
      <include name="gnu/jemacs/buffer/"/>
      <include name="gnu/jemacs/lang/"/>
      <include name="gnu/jemacs/swing/"/>
    </javac>
  </target>
   
  <target name="jemacs-classes" 
          depends="build-settings, java-classes
            , jemacs-java-classes
            , check-jemacs-lisp-classes" 
          if="${enable-jemacs}" 
          unless="jemacs-lisp-classes-uptodate">
    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <arg value="-classpath"/> <arg path="${build.classes}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.jemacs.lang. --module-static -C"/>
      <fileset refid="jemacs-lang-scm"/>
    </apply>

    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <arg value="-classpath"/> <arg path="${build.classes}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.jemacs.buffer. --module-static -C"/>
      <fileset refid="jemacs-buffer-scm"/>
    </apply>

    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <arg value="-classpath"/> <arg path="${build.classes}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.kawa.slib. --module-static -C"/>
      <fileset refid="jemacs-slib-scm"/>
    </apply>

    <apply taskname="elisp" executable="java" 
           failonerror="true" parallel="true">
      <arg value="-classpath"/> <arg path="${build.classes}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.jemacs.lisp. --elisp -C"/>
      <fileset refid="jemacs-el"/>
    </apply>
  </target>
  
  <target name="jar">
    <jar jarfile="${dist.kawa.jar}"
         manifest="${src.dir}/jar-manifest">
       <fileset refid="build.classes"/>
    </jar>
  </target>

  <!--
    These clean targets are split up for when
    get build-tools doesn't work in NetBeans.
    (There is a workaround now, see build-tools.)
    For this to work, build.tools must be a different
    directory than build.classes uses.
  -->
  <target name="clean-build">
    <delete>
       <fileset refid="build.classes"/>
       <fileset refid="build.preprocessed"/>
       <fileset dir="${build.tmp}">
          <patternset refid="build.selectjava"/>
       </fileset>
    </delete>
  </target>

  <target name="clean-tools">
    <delete dir="${build.tools}"/>
  </target>

  <target name="clean-dist">
    <delete file="${dist.kawa.jar}"/>
  </target>

  <target name="clean" depends="clean-build, clean-tools, clean-dist"/>

</project>
