<!--
 Copyright Mathieu Champlon 2008.

 Distributed under the Boost Software License, Version 1.0.
    (See accompanying file LICENSE_1_0.txt or copy at
          http://www.boost.org/LICENSE_1_0.txt)
-->
<project name="turtle" default="all">

  <property environment="env"/>
  <fail unless="env.BOOST_ROOT" message="missing BOOST_ROOT environment variable"/>
  <property name="boost.dir" value="${env.BOOST_ROOT}"/>
  <property name="src.dir" value="${root.dir}"/>
  <property name="doc.dir" value="${src.dir}/doc"/>
  <property name="libraries.dir" value="${src.dir}/include"/>
  <property name="out.dir" value="${root.dir}/bin/poney/${platform}"/>
  <property name="boost-mock.dir" value="${out.dir}/boost-mock"/>

  <property name="version" value="unreleased"/>

  <target name="package" depends="build" description="produce release packages">
    <fail unless="version" message="missing version property"/>
    <copy file="version.hpp" tofile="${out.dir}/version.hpp" overwrite="true">
      <filterset>
        <filter token="MOCK_VERSION" value="${version}"/>
      </filterset>
    </copy>
    <mkdir dir="${dist.dir}"/>
    <zip destfile="${dist.dir}/${ant.project.name}-${version}.zip">
      <fileset dir="${src.dir}" includes="include/**"/>
      <zipfileset dir="${doc.dir}/html" prefix="doc"/>
      <zipfileset dir="${out.dir}" includes="version.hpp" prefix="include/turtle"/>
    </zip>
    <tar destfile="${dist.dir}/${ant.project.name}-${version}.tar.bz2" compression="bzip2">
      <fileset dir="${src.dir}" includes="include/**"/>
      <zipfileset dir="${doc.dir}/html" prefix="doc"/>
      <zipfileset dir="${out.dir}" includes="version.hpp" prefix="include/turtle"/>
    </tar>
  </target>

  <target name="all" depends="build,reports,package" description="build documentation, run tests and package distribution"/>

  <target name="boost.convert" description="convert Boost.Mock">
    <delete dir="${boost-mock.dir}"/>
    <copy todir="${boost-mock.dir}">
      <fileset dir="${root.dir}" excludes="bin/**"/>
    </copy>
    <move file="${boost-mock.dir}/include/turtle" tofile="${boost-mock.dir}/include/boost/mock"/>
    <delete dir="${boost-mock.dir}/doc/html/turtle"/>
    <replaceregexp match="MOCK" replace="BOOST_MOCK" flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/*.cpp,**/*.hpp,**/*.qbk"/>
    </replaceregexp>
    <replaceregexp match="BOOST_MOCK_BOOST_MOCK" replace="BOOST_MOCK" flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/*.cpp,**/*.hpp,**/*.qbk"/>
    </replaceregexp>
    <replaceregexp match='"([^"]+\.hpp)"' replace="&lt;boost/mock/\1&gt;" flags="g">
      <fileset dir="${boost-mock.dir}/include" includes="**/*.hpp" excludes="**/detail/*.hpp"/>
    </replaceregexp>
    <replaceregexp match='"\.\./([^"]+\.hpp)"' replace="&lt;boost/mock/\1&gt;" flags="g">
      <fileset dir="${boost-mock.dir}/include" includes="**/*.hpp"/>
    </replaceregexp>
    <replaceregexp match='"([^"]+\.hpp)"' replace="&lt;boost/mock/detail/\1&gt;" flags="g">
      <fileset dir="${boost-mock.dir}/include" includes="**/detail/*.hpp"/>
    </replaceregexp>
    <replaceregexp match="&lt;turtle/([^&gt;]+)" replace="&lt;boost/mock/\1" flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/*.cpp,**/*.hpp,**/*.qbk"/>
    </replaceregexp>
    <replaceregexp match="(namespace mock)" replace="namespace boost${line.separator}{${line.separator}\1" flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/*.cpp,**/*.hpp,**/*.qbk"/>
    </replaceregexp>
    <replaceregexp match="} // mock" replace="}${line.separator}}" flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/*.cpp,**/*.hpp"/>
    </replaceregexp>
    <replaceregexp match=" mock::" replace=" boost::mock::" flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/*.cpp,**/*.hpp,**/*.qbk"/>
    </replaceregexp>
    <replaceregexp match="^mock::" replace="boost::mock::" flags="m">
      <fileset dir="${boost-mock.dir}" includes="**/*.cpp,**/*.hpp,**/*.qbk"/>
    </replaceregexp>
    <replaceregexp match="http://turtle.sourceforge.net" replace="Boost.Mock" flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/*.cpp,**/*.hpp"/>
    </replaceregexp>
    <replaceregexp match="reference.helpers." replace="reference.helpers.boost_" flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/*.qbk"/>
    </replaceregexp>
    <replaceregexp match="turtle." replace="boost_mock." flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/*.qbk"/>
    </replaceregexp>
    <replaceregexp match="Turtle" replace="Boost.Mock" flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/*.qbk"/>
    </replaceregexp>
    <replaceregexp match="\[include changelog.qbk\]" replace="" flags="g">
      <fileset dir="${boost-mock.dir}" includes="**/mock.qbk"/>
    </replaceregexp>
  </target>

  <target name="boost.build" depends="boost.convert" description="build Boost.Mock tests and documentation">
    <run dir="${boost-mock.dir}/build" script="build"/>
  </target>

  <target name="boost.package" depends="boost.build" description="package Boost.Mock">
    <fail unless="version" message="missing version property"/>
    <zip destfile="${dist.dir}/boost-mock-${version}.zip">
      <fileset dir="${boost-mock.dir}" includes="include/**,test/**,doc/**" excludes="**/bin/**"/>
      <fileset dir="${boost-mock.dir}" includes="LICENSE_1_0.txt,index.html"/>
    </zip>
    <tar destfile="${dist.dir}/boost-mock-${version}.tar.bz2" compression="bzip2">
      <fileset dir="${boost-mock.dir}" includes="include/**,test/**,doc/**" excludes="**/bin/**"/>
      <fileset dir="${boost-mock.dir}" includes="LICENSE_1_0.txt,index.html"/>
    </tar>
  </target>

  <target name="boost" depends="boost.convert,boost.build,boost.package" description="convert and package to boost with documentation and tests"/>

</project>
