<?xml version="1.0"?>

<!-- FILE. . . . . /home/hak/ilt/src/ilog/rif/versions/bld-v0.1/Build.xml -->
<!-- EDIT BY . . . Hassan Ait-Kaci -->
<!-- ON MACHINE. . 4j4zn71 -->
<!-- STARTED ON. . Tue Oct 07 11:27:42 2008 -->

<!-- Last modified on Wed Nov 25 04:12:08 2009 by hak -->

<!-- This is an "ant build-file" for running or building a
     RIF BLD -> RIF XML compiler. Type "ant" with no args
     for a list of options.
-->

<!-- DEFINITIONS -->

<project name="rif" default="usage">

<!-- DEFINITIONS -->

  <property name="RELEASE_DATE" value="2008.10.07"/>
  <property name="RIF_VERSION" value="0.1"/>
  <property name="SOURCES_DIR" value="sources"/>
  <property name="DOCS_DIR" value="docs"/>
  <property name="CLASSES_DIR" value="classes"/>
  <property name="RESOURCES_DIR" value="${CLASSES_DIR}/resources"/>
  <property name="EXAMPLES_DIR" value="examples"/>
  <property name="JDOM_PATH" value="${CLASSES_DIR}/jdom.jar"/>
  <property name="RIF_PATH" value="ilog/rif/bld"/>
  <property name="JACC_JAR" value="${CLASSES_DIR}/ilog.language.${RELEASE_DATE}.jar"/>
  <property name="ZIP_FILE" value="ilog.rif.bld-v${RIF_VERSION}.zip"/>
  <property name="ZIP_DIR" value=".."/>

  <path id="CLASSPATH">
    <pathelement location="${CLASSES_DIR}"/>
    <pathelement location="${JACC_JAR}"/>
    <pathelement location="${JDOM_PATH}"/>
  </path>

<!-- TARGETS -->

  <!--
  usage:
  -->

  <target name="usage" depends="banner">
    <echo message=""/>
    <echo message="Known targets:"/>
    <echo message="   ant all     --> generation + compilation + documentation"/>
    <echo message="   ant bld     --> generation + compilation of RIF BLD"/>
    <echo message="   ant classes --> compilation of generated java files"/>
    <echo message="   ant doc     --> generation of BLD grammar documentation"/>
    <echo message="   ant tidy    --> remove old *.class and generated BLD documentation files"/>
    <echo message="   ant test    --> parse a test file (${EXAMPLES_DIR}/Test1.bld)"/>
    <echo message="   ant zip     --> create a zip file containing all this directory"/>
  </target>

  <!--
  all:
  -->

  <target name="all"
          depends="banner,bld,classes,doc"
          description="Generate all parsers and compile them"/>
 
  <!--
  banner:
  -->

  <target name="banner"
          description="Prints the version of this RIF Jacc specification">
  <echo>This is a Jacc metacompiler specification for a RIF BLD -> RIF XML compiler</echo>
  <echo>Version: ${RIF_VERSION} - Release of: ${RELEASE_DATE} - Author: hak@ilog.com </echo>
  </target>
 
  <!--
  bld:
  -->

  <target name="bld"
          depends="genbld,classes"
          description="Generate the BLD parser"/>

  <!--
  doc:
  -->

  <target name="doc"
          depends="docbld"
          description="Generate the HTML grammar documentation">
    <echo>Done generating HTML grammar documentation - see: ${DOCS_DIR}/BLDDoc/ROOT.html</echo>
  </target>

  <!--
  genbld:
  -->

  <target name="genbld" depends="banner" description="Generate the BLD parser">
    <echo>Generating the BLD parser</echo>
    <java classname="ilog.language.syntax.Jacc" dir="${SOURCES_DIR}" fork="true">
      <classpath refid="CLASSPATH"/>
      <arg line="-p Parser BLD"/>
    </java>
  </target>

  <!--
  docbld:
  -->

  <target name="docbld" depends="banner" description="Generate the HTML documentation for BLD">
    <echo>Generating the BLD grammar documentation</echo>
    <java classname="ilog.language.syntax.Jacc" dir="${SOURCES_DIR}" fork="true">
      <classpath refid="CLASSPATH"/>
      <arg line="-doc BLD"/>
    </java>
    <move file="${SOURCES_DIR}/BLDDoc/index.html" tofile="${SOURCES_DIR}/BLDDoc/ROOT.html"/>
    <move todir="${DOCS_DIR}/BLDDoc">
      <fileset dir="${SOURCES_DIR}/BLDDoc"/>
    </move>
    <echo>Copying documentation resources (image files)</echo>
    <copy todir="${DOCS_DIR}/BLDDoc/images/ilog">
      <fileset dir="${RESOURCES_DIR}/images/ilog"/>
    </copy>
    <copy todir="${DOCS_DIR}/BLDDoc/images/arrows/misc">
      <fileset dir="${RESOURCES_DIR}/images/arrows/misc"/>
    </copy>
    <java classname="ilog.language.tools.HiliteCommand" dir="${SOURCES_DIR}" fork="true">
      <classpath refid="CLASSPATH"/>
      <arg line="-c ../${RESOURCES_DIR}/Hilite.Configuration"/>
      <arg line="*.grm"/>
      <arg line="*.java"/>
    </java>
    <move todir="${DOCS_DIR}/BLDDoc">
      <fileset dir="${SOURCES_DIR}">
        <include name="*.html"/>
      </fileset>
  </move>
  </target>

  <!--
  classes:
  -->

  <target name="classes" depends="banner" description="Compile the parser classes">
    <echo>Compiling java files...</echo>
    <javac srcdir="${SOURCES_DIR}" destdir="${CLASSES_DIR}" debug="on" fork="true">
      <classpath refid="CLASSPATH"/>
    </javac>
  </target>

  <!--
  test:
  -->

  <target name="test" depends="banner" description="parse a test file">
    <echo>Parsing ${EXAMPLES_DIR}/Test1.bld</echo>
    <java classname="ilog.rif.bld.Main" dir="${EXAMPLES_DIR}" fork="true">
      <classpath refid="CLASSPATH"/>
      <arg line="../${EXAMPLES_DIR}/Test1.bld"/>
    </java>
  </target>

  <!--
  tidy:
  -->

  <target name="tidy" description="delete the compiled classes">
    <delete>
      <fileset dir="${DOCS_DIR}" includes="BLDDoc/* BLDDoc/*/* BLDDoc"/>
      <fileset dir="${CLASSES_DIR}/${RIF_PATH}" includes="*.class"/>
    </delete>
  </target>

  <!--
  zip:
  -->

  <target name="zip"
          depends="banner"
          description="creates a zip distribution file for this directory">
    <echo>Deleting previous zip archive file "${ZIP_DIR}/${ZIP_FILE}"</echo>
    <delete file="${ZIP_DIR}/${ZIP_FILE}"/>
    <echo>Creating new zip archive file "${ZIP_DIR}/${ZIP_FILE}"</echo>
    <zip update="true" basedir="." destfile="${ZIP_DIR}/${ZIP_FILE}"/>
    <echo>Wrote zip archive file "${ZIP_DIR}/${ZIP_FILE}"</echo>

  </target>

</project>
