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

<project name="installation-guide" default="build" basedir=".">

  <property file="${basedir}/build.properties" />

  <taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
      <pathelement location="${basedir}/src/lib/ant-contrib-1.0b2.jar" />
    </classpath>
  </taskdef>
  <taskdef name="xdoc2tex" classname="jp.sf.fess.ant.taskdefs.XdocToTex">
    <classpath>
      <pathelement location="${xdoc2tex.jar.file}" />
    </classpath>
  </taskdef>

  <target name="clean"
          description="--> Clean Build Files">
    <delete dir="${build.dir}"/>
  </target>

  <target name="convert-image">
    <basename file="${param}" property="image.name" suffix=".png"/>
    <echo>${convert.cmd} ${image.name}.png ${image.name}.eps</echo>
    <exec
      executable="${convert.cmd}"
      failonerror="true"
      dir="${build.dir}"
      >
      <arg line="${build.img.dir}/${image.name}.png ${build.eps.dir}/${image.name}.eps"/>
    </exec>
  </target>

  <target name="build"
          description="--> Build Files">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.tex.dir}"/>
    <mkdir dir="${build.img.dir}"/>
    <mkdir dir="${build.eps.dir}"/>

    <echo>Generating Tex files...</echo>

    <copy todir="${build.tex.dir}" overwrite="true">
      <fileset dir="${src.tex.dir}">
        <include name="**"/>
      </fileset>
    </copy>

    <xdoc2tex todir="${build.tex.dir}" encoding="EUC-JP">
      <fileset dir="${orig.src.tex.dir}">
        <include name="**"/>
      </fileset>
    </xdoc2tex>

    <echo>Generating Image files...</echo>

    <copy todir="${build.img.dir}" overwrite="true">
      <fileset dir="${src.img.dir}">
        <include name="**"/>
      </fileset>
    </copy>

    <copy todir="${build.img.dir}" overwrite="true">
      <fileset dir="${orig.src.img.dir}">
        <include name="**"/>
      </fileset>
    </copy>

    <foreach target="convert-image" param="param">
      <fileset dir="${build.img.dir}"/>
    </foreach>

    <echo>Compiling Tex files...</echo>

    <exec
      executable="${tex.cmd}"
      failonerror="true"
      dir="${build.tex.dir}"
      >
      <arg line="${document.name}"/>
    </exec>
    <exec
      executable="${tex.cmd}"
      failonerror="true"
      dir="${build.tex.dir}"
      >
      <arg line="${document.name}"/>
    </exec>
    <exec
      executable="${tex.cmd}"
      failonerror="true"
      dir="${build.tex.dir}"
      >
      <arg line="${document.name}"/>
    </exec>

    <exec
      executable="${dvi2ps.cmd}"
      failonerror="true"
      dir="${build.tex.dir}"
      >
      <arg line="-q -f ${document.name}.dvi -o ${document.name}.ps"/>
    </exec>

    <exec
      executable="${gs.cmd}"
      failonerror="true"
      dir="${build.tex.dir}"
      >
      <arg line="-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=${document.name}-${document.version}.pdf -f ${document.name}.ps"/>
    </exec>

  </target>


</project>
