<project name="CopyFile" default="CheckFileExists">
  <!-- PARAMETERS
    file - The file to copy.
    tofile - The file to copy to.
  -->
  <target name="CopyFile" if="copy.file">
    <echo>COPYING ${file} to ${tofile}</echo>
    <copy file="${file}" tofile="${tofile}"/>
  </target>

  <target name="CheckFileExists" description="Checks if the file to be copied exists">
    <!-- Check if file exists and if it more uptodate than the file-->
    <condition property="copy.file">
      <and>
        <available file="${file}" property="file.exists"/>
        <or>
          <!-- Make sure it's either not available or if it is, it is uptodate.-->
          <not><available file="${tofile}"/></not>
          <uptodate targetfile="${file}" srcfile="${tofile}"/>
        </or>
      </and>
    </condition>
    <!-- Call copy file target -->
    <antcall target="CopyFile"/>
  </target>
</project>

