<?xml version="1.0" encoding="utf-8" ?>
<!--
		.......................................................... 
		April 2009
		Documented Example Release Kit (derk)
		Sept 2022 - Updated for gs3
		..........................................................
-->

<project name="derk-build" default="derk">

	<!-- IMPORT OTHER ANT SCRIPTS -->
	<import file="${rk.home}/shared/core/ant-scripts/shared.xml"/>

	<!-- THE MAIN TARGET -->
	<target name="derk" depends="init">
		<!-- export the documented examples -->
		<if><bool><not><available file="documented-examples"/></not></bool>
			<exec executable="svn">
			  <arg line="${global-svn-args}"/>
			  <arg value="export"/>
			  <arg value="${svn.root}/documented-examples/${branch.path}"/>
			  <arg value="documented-examples"/>
			</exec>
		</if>

		<!-- clean up -->
		<delete file="documented-examples/text-for-translation.txt"/>

		<!-- prepare-gs2build -->
		<if>
			<bool><not><available file="gs2build"/></not></bool>
			<exec executable="svn">
			  <arg line="${global-svn-args}"/>
			  <arg value="export"/>
			  <arg value="${svn.root}/main/${branch.path}/gs2build"/>
			  <arg value="gs2build"/>
			</exec>
		</if>
		<!-- kjdon -->
		<condition property="specific.os.type" value="${os.shell}-Lion" else="${os.shell}">
                  <and>
                    <contains string="${os.shell}" substring="darwin" casesensitive="false"/>
		    <matches pattern="^(10\.7\.[4-9]|10\.[8-9]|1[1-9]|[2-9])" string="${os.version}"/>
                  </and>
                </condition>


		<if>
		  <bool><not><available file="gs2build/ext/gnome-lib-minimal"/></not></bool>
		<echo>EXPORTING GNOME LIB EXTENSION</echo>
<echo>${svn.gs2.extensions}/gnome-lib/gnome-\
lib-minimal-${specific.os.type}${arch}${extension-x64}.tar.gz</echo>
		<exec executable="svn">
                  <arg line="${global-svn-args}"/>
                  <arg value="export"/>
                  <arg value="${svn.gs2.extensions}/gnome-lib/gnome-lib-minimal-${specific.os.type}${arch}${extension-x64}.tar.gz"/>
                  <arg value="gs2build/ext/gnome-lib-${specific.os.type}.tar.gz"/>
                </exec>
		
                <exec executable="tar" dir="gs2build/ext">
                  <arg value="xvzf"/>
                  <arg value="gnome-lib-${specific.os.type}.tar.gz"/>
                </exec>

                <exec executable="/bin/bash" dir="gs2build/ext/gnome-lib-minimal">
                  <arg value="-c"/>
                  <arg value="source setup.bash_old &amp;&amp; source devel.bash"/>
                </exec>
                <echo>DONE COMPILING GNOME LIB EXTENSION</echo>
                </if>
		
		<!-- to here-->
		<!-- Nowadays need to get and compile gnome-lib in order for wvware to compile 
		     So use the makegs2.sh script to get gnome-lib and compile gs2 -->
		<if><bool><not><available file="gs2build/Makefile"/></not></bool>
		  <exec dir="gs2build" executable="./makegs2.sh" failonerror="true">
		    <arg value="gnome-lib" />
		  </exec>
<!--			<exec dir="gs2build" executable="/bin/bash" failonerror="true"><arg value="./configure"/></exec>
			<exec dir="gs2build" executable="make" failonerror="true"/>
			<exec dir="gs2build" executable="make" failonerror="true"><arg value="install"/></exec>
-->
		</if>

        <!-- Before we can build GS colls we need to insert our custom 
             perl-with-cpan from now on, as it contains extra perl
             modules needed to build the collections -->
        <!-- We're building DEC (derk) on linux, but checking for gs2build/bin/windows|darwin folder
             for if we ever build DEC on Windows/darwin, in which case we need to insert windows/mac perl -->
        <if>
          <bool><available file="gs2build/bin/windows"/></bool>
		  <property name="win.bin" value="gs2build/bin/windows"/>
		  <property name="win.perl.version" value="strawberry-perl-5.32.1.1"/>
		  <property name="win.perl.zip" value="${win.perl.version}-MSWin32-x86-multi-thread.zip"/>			
		  <exec executable="svn" dir="${win.bin}">
		    <arg line="${global-svn-args}"/>
			<arg value="export"/>
			<arg value="${svn.gs2.extensions}/perl-with-cpan/${win.perl.zip}"/>
		  </exec>
		  <unzip src="${win.bin}/${win.perl.zip}" dest="${win.bin}"/>
		  <move file="${win.bin}/${win.perl.version}" tofile="${win.bin}/strawberry-perl" />
		  <delete failonerror="false" file="${win.bin}/${win.perl.zip}" />
	  <else><!-- UNIX -->
	    <property name="unix.perl.version" value="perl-5.32.1"/>        
	    <if><bool><contains string="${os.shell}" substring="darwin" casesensitive="false"/></bool><!--<available file="gs2build/bin/darwin"/></bool>-->
                  <property name="mac.bin" value="gs2build/bin/darwin"/>
                  <property name="mac.perl.tarball" value="${unix.perl.version}-darwin-thread-multi-2level.tar.gz"/>
                  <exec executable="svn" dir="${mac.bin}">
                    <arg line="${global-svn-args}"/>
                    <arg value="export"/>
                    <arg value="${svn.gs2.extensions}/perl-with-cpan/${mac.perl.tarball}"/>
                  </exec>
		  <exec executable="tar" dir="${mac.bin}">
		    <arg value="xvzf"/>
		    <arg value="${mac.perl.tarball}"/>
		  </exec>
		  <move file="${mac.bin}/${unix.perl.version}" tofile="${mac.bin}/perl" />
          <delete failonerror="false" file="${mac.bin}/${mac.perl.tarball}" />		    
          <else><!-- insert linux perl-with-cpan -->
	    <property name="lin.bin" value="gs2build/bin/linux"/>	    
            <property name="lin.perl.tarball" value="${unix.perl.version}-x86_64-linux-thread-multi.tar.gz"/>
            <!--
		    <if>
		      <bool><equals arg1="${bitness}" arg2="32"/></bool>
			  <property name="lin.perl.tarball" value="${unix.perl.version}-i686-linux-gnu-thread-multi.tar.gz"/>
		      <else><if><bool><equals arg1="${bitness}" arg2="64"/></bool>
			  <property name="lin.perl.tarball" value="${unix.perl.version}-x86_64-linux-thread-multi.tar.gz"/>
		      </if></else>
		    </if>
            -->
		    <exec executable="svn">
              <arg line="${global-svn-args}"/>
		      <arg value="export"/>
		      <arg value="${svn.gs2.extensions}/perl-with-cpan/${lin.perl.tarball}"/>
		      <arg value="${lin.bin}/${lin.perl.tarball}"/>
		    </exec>
		    <exec executable="tar" dir="${lin.bin}">
		      <arg value="xvzf"/>
		      <arg value="${lin.perl.tarball}"/>
		    </exec>
            <delete file="${lin.bin}/${lin.perl.tarball}"/>
		    <!-- untarred name is the same, regardless of 32-bit or 64-bit, so move command the same for both -->          
		    <move file="${lin.bin}/${unix.perl.version}" tofile="${lin.bin}/perl" />
          </else>	  
	  </if> <!-- end mac or linux -->
	</else>
        </if> <!-- end windows or other -->
        
		<!-- build the collections -->
		<exec dir="gs2build" executable="${rk.home}/kits/${rk.name}/resources/build.sh" failonerror="true"/>
        
        <!-- create archives -->
        <mkdir dir="products"/>
        <zip destfile="products/Greenstone3-documented-examples-${version}.zip"  basedir="." includes="documented-examples/**/*"/>
        <exec executable="tar">
          <arg line="-czf products/Greenstone3-documented-examples-${version}.tar.gz documented-examples"/>
        </exec>

	  </target>

	<target name="properties" depends="core-properties"/>

</project>
