<?xml version="1.0"?>

<project name="freeguide-tv-stable" default="main" basedir=".">

    <description>
        Ant build file for FreeGuide.
    </description>

	<!-- set global properties for this build -->
	<property name="src" location="src" />
	<property name="doc"  location="doc" />
	<property name="xmltv"  location="xmltv" />
	<property name="share"  location="xmltv/share" />
	<property name="build" location="build" />
	<property name="dist"  location="dist" />
    
	<property name="freeguideversion"  value="FreeGuide-0.8.6"/>

  	<target name="init">

    	<!-- Create the time stamp -->
    	<tstamp/>
    	<!-- Create the build directory structure used by compile -->
    	<mkdir dir="${build}" />
		<mkdir dir="${build}/program" />
		<mkdir dir="${build}/doc" />
		<mkdir dir="${dist}" />

	</target>
    
    <target name="install-Linux-NoXMLTV-files"
            description="install all the files for linux"
            depends="FreeGuide-Linux-NoXMLTV" >
        
        <!-- These properties are passed in from the rpm .spec file:
            install_share_dir = ~/.rpm/tmp/FreeGuide-0.8.2-root//usr/share
            install_bin_dir   = ~/.rpm/tmp/FreeGuide-0.8.2-root//usr/bin
            install_doc_dir   = ~/.rpm/tmp/FreeGui...usr/doc/freeguide
            install_real_doc_dir = /usr/doc/freeguide
        -->
        
        <property name="install_jar_dir"
            location="${install_share_dir}/freeguide" />

        <property name="install_pixmap_dir" location="${install_share_dir}/pixmaps/freeguide" />
        
        <mkdir dir="${install_jar_dir}" />
        <copy file="${dist}/${freeguideversion}-Linux-NoXMLTV.jar"
            tofile="${install_jar_dir}/FreeGuide.jar" />

        <!-- Copy the different-sized icons to the freeguide pixmaps dir -->
        <mkdir dir="${install_pixmap_dir}" />
        <copy todir="${install_pixmap_dir}/" >
            <fileset dir="${src}/images">
                <include name="logo-*.png" />
                <exclude name="logo-192x192.png" />
                <exclude name="logo-256x256.png" />
            </fileset>
        </copy>
        
        <copy tofile="${install_share_dir}/pixmaps/freeguide.png" file="${src}/images/logo-32x32.png" />
        
        <!-- Creating the launch script: first we need to copy the source launch script, then we replace the string "__ANT_DOC_DIRECTORY__" with the docs directory, and then we move it into place and make it executable. -->
        <copy file="${src}/install/linux/freeguide" tofile="${src}/install/linux/freeguide.tmp" />
        <replace file="${src}/install/linux/freeguide.tmp" token="__ANT_DOC_DIRECTORY__" value="${install_real_doc_dir}" />
        <mkdir dir="${install_bin_dir}" />
        <move file="${src}/install/linux/freeguide.tmp" tofile="${install_bin_dir}/freeguide" />
        <chmod file="${install_bin_dir}/freeguide" perm="a+x" />
        
        <mkdir dir="${install_share_dir}/applications" />
        <copy file="${src}/install/linux/freeguide.desktop" todir="${install_share_dir}/applications/" />

        <mkdir dir="${install_share_dir}/man/man1" />
        <copy file="${build}/freeguide.1.gz" todir="${install_share_dir}/man/man1/" />
        
        <mkdir dir="${install_doc_dir}" />
        <copy todir="${install_doc_dir}/">
            <fileset dir="${doc}">
                <include name="*.html" />
                <include name="*.png" />
                <include name="*.css" />
                <include name="COPYING" />
                <include name="TODO" />
                <exclude name="bugreport.html" />
            </fileset>
        </copy>
        
    </target>
    
  	<target name="compile" depends="init" description="compile the source " >

  		<!-- compile all the .java files -->
		<javac srcdir="${src}/program" destdir="${build}/program" deprecation="on" source="1.4" target="1.4" />

  		<!-- copy in the required images (flash screen) -->
  		<copy todir="${build}/program" file="${src}/images/logo-256x256.png" />
        
		<!-- gzip the man page -->
        <gzip src="${src}/install/linux/freeguide.1" zipfile="${build}/freeguide.1.gz" />
        
	</target>

    <target name="FreeGuide-Win" depends="compile"
			description="generate the windows jar file" >

        <mkdir dir="${build}/windows" />
        
        <!-- Copy the program jar -->
		<copy todir="${build}/windows">
            <fileset dir="${build}/program" />
		</copy>

		<!-- Copy the XMLTV DTD -->
		<copy file="${xmltv}/xmltv.dtd" todir="${build}/windows" />

		<!-- copy in the install.props file for the jar -->
		<copy file="${src}/install/windows/install-win-all.props" tofile="${build}/windows/install-all.props" overwrite="true" />
        
        <!-- Denmark -->
		<copy file="${src}/install/windows/install-win-dk.props" tofile="${build}/windows/install-0.props" overwrite="true" />
        
        <!-- Finland -->
		<copy file="${src}/install/windows/install-win-fi.props" tofile="${build}/windows/install-1.props" overwrite="true" />
        
        <!-- France -->
        <copy file="${src}/install/windows/install-win-fr.props" tofile="${build}/windows/install-2.props" overwrite="true" />
        
        <!-- Germany -->
        <copy file="${src}/install/windows/install-win-de_tvtoday.props" tofile="${build}/windows/install-3.props" overwrite="true" />
        
        <!-- Hungary and Romania -->
		<copy file="${src}/install/windows/install-win-huro.props" tofile="${build}/windows/install-4.props" overwrite="true" />
        
        <!-- Italy -->
		<copy file="${src}/install/windows/install-win-it_lt.props" tofile="${build}/windows/install-5.props" overwrite="true" />
        
        <!-- Japan -->
        <!--<copy file="${src}/install/windows/install-win-jp.props" tofile="${build}/windows/install-6.props" overwrite="true" />-->
        
        <!-- Netherlands -->
        <copy file="${src}/install/windows/install-win-nl.props" tofile="${build}/windows/install-6.props" overwrite="true" />
        <copy file="${src}/install/windows/install-win-nl_wolf.props"
        tofile="${build}/windows/install-7.props" overwrite="true" />
        
        <!-- North America -->
        <copy file="${src}/install/windows/install-win-na_dd.props" tofile="${build}/windows/install-8.props" overwrite="true" />
        
        <!-- Norway -->
        <copy file="${src}/install/windows/install-win-no.props" tofile="${build}/windows/install-9.props" overwrite="true" />
        
        <!-- Portugal -->
        <copy file="${src}/install/windows/install-win-pt.props" tofile="${build}/windows/install-10.props" overwrite="true" />
        
        <!-- Spain -->
		<copy file="${src}/install/windows/install-win-es.props" tofile="${build}/windows/install-11.props" overwrite="true" />
        <copy file="${src}/install/windows/install-win-es_digital.props" tofile="${build}/windows/install-12.props" overwrite="true" />
        
        <!-- Sweden -->
        <copy file="${src}/install/windows/install-win-se.props" tofile="${build}/windows/install-13.props" overwrite="true" />
        <copy file="${src}/install/windows/install-win-se_swedb.props" tofile="${build}/windows/install-14.props" overwrite="true" />
        
        <!-- UK -->
        <copy file="${src}/install/windows/install-win-uk_bleb.props" tofile="${build}/windows/install-15.props" overwrite="true" />
		<copy file="${src}/install/windows/install-win-uk_rt.props" tofile="${build}/windows/install-16.props" overwrite="true" />

		<!-- Make the jar file -->
		<jar 	jarfile="${dist}/${freeguideversion}-Win.jar"
				basedir="${build}/windows"
				manifest="${src}/manifests/FreeGuide.mf" />
        
  	</target>

	<target name="FreeGuide-Linux-NoXMLTV" depends="compile"
  		description="generate the linux jar" >

		<mkdir dir="${build}/linux" />

		<!-- Copy the program file -->
		<copy todir="${build}/linux">
            <fileset dir="${build}/program"/>
		</copy>
        
		<!-- Copy the XMLTV DTD -->
		<copy file="${xmltv}/xmltv.dtd" todir="${build}/linux" />

		<!-- copy in the install.props file for the jar -->
		<copy file="${src}/install/linux/install-lin-all.props" tofile="${build}/linux/install-all.props" overwrite="true" />
        
        <!-- Denmark -->
		<copy file="${src}/install/linux/install-lin-dk.props" tofile="${build}/linux/install-0.props" overwrite="true" />
        
        <!-- Finland -->
		<copy file="${src}/install/linux/install-lin-fi.props" tofile="${build}/linux/install-1.props" overwrite="true" />
        
        <!-- France -->
        <copy file="${src}/install/linux/install-lin-fr.props" tofile="${build}/linux/install-2.props" overwrite="true" />
        
        <!-- Germany -->
        <copy file="${src}/install/linux/install-lin-de_tvtoday.props" tofile="${build}/linux/install-3.props" overwrite="true" />
        
        <!-- Hungary and Romania -->
		<copy file="${src}/install/linux/install-lin-huro.props" tofile="${build}/linux/install-4.props" overwrite="true" />
        
        <!-- Italy -->
		<!--<copy file="${src}/install/linux/install-lin-it_lt.props" tofile="${build}/linux/install-5.props" overwrite="true" />-->
        
        <!-- Japan -->
        <copy file="${src}/install/linux/install-lin-jp.props" tofile="${build}/linux/install-5.props" overwrite="true" />
        
        <!-- Netherlands -->
		<copy file="${src}/install/linux/install-lin-nl.props" tofile="${build}/linux/install-6.props" overwrite="true" />
        <copy file="${src}/install/linux/install-lin-nl_wolf.props" tofile="${build}/linux/install-7.props" overwrite="true" />
        
        <!-- North America -->
		<copy file="${src}/install/linux/install-lin-na_dd.props" tofile="${build}/linux/install-8.props" overwrite="true" />
        
        <!-- Norway -->
		<copy file="${src}/install/linux/install-lin-no.props" tofile="${build}/linux/install-9.props" overwrite="true" />
        
        <!-- Portugal -->
        <copy file="${src}/install/linux/install-lin-pt.props" tofile="${build}/linux/install-10.props" overwrite="true" />
        
        <!-- Spain -->
		<copy file="${src}/install/linux/install-lin-es.props" tofile="${build}/linux/install-11.props" overwrite="true" />
        <copy file="${src}/install/linux/install-lin-es_digital.props" tofile="${build}/linux/install-12.props" overwrite="true" />
        
        <!-- Sweden -->
        <copy file="${src}/install/linux/install-lin-se.props" tofile="${build}/linux/install-13.props" overwrite="true" />
        
        <!-- UK -->
        <copy file="${src}/install/linux/install-lin-uk_bleb.props" tofile="${build}/linux/install-14.props" overwrite="true" />
		<copy file="${src}/install/linux/install-lin-uk_rt.props" tofile="${build}/linux/install-15.props" overwrite="true" />

		<!-- Make the jar installer file -->
		<jar 	jarfile="${dist}/${freeguideversion}-Linux-NoXMLTV.jar"
				basedir="${build}/linux"
				manifest="${src}/manifests/FreeGuide.mf" />

  	</target>

	<target name="FreeGuide-Source"
  		description="generate the source zips"
			depends="FreeGuide-Win,
					 FreeGuide-Linux-NoXMLTV">

		<zip zipfile="${dist}/${freeguideversion}.zip">
			<zipfileset dir="${src}" prefix="${freeguideversion}/src">
				<exclude name="**/.xvpics/**" />
			</zipfileset>
			<zipfileset dir="${doc}" prefix="${freeguideversion}/doc">
				<exclude name="**/.xvpics/**" />
			</zipfileset>
			<zipfileset dir="." includes="build.xml" prefix="${freeguideversion}" />
			<zipfileset dir="xmltv"
				includes="*"
				excludes="CVS/**"
				prefix="${freeguideversion}/xmltv" />
			<zipfileset dir="stats"
				includes="*.sh,*.pl"
				prefix="${freeguideversion}/stats" />
		</zip>

		<tar tarfile="${build}/fg.tar"
			 basedir="."
			 includes="build.xml,src/**,doc/**,xmltv/*,stats/*.sh,stats/*.pl"
			 excludes="**/.xvpics/**,**/CVS/**" />

		<mkdir dir="${build}/${freeguideversion}" />

		<untar dest="${build}/${freeguideversion}" src="${build}/fg.tar" />

		<tar tarfile="${build}/${freeguideversion}.tar" basedir="${build}"
			includes="${freeguideversion}/**" />

  		<gzip src="${build}/${freeguideversion}.tar" zipfile="${dist}/${freeguideversion}.tar.gz" />

	</target>

	<target name="main" depends="FreeGuide-Source"
		description="generate all the installers" >
	</target>

	<target name="clean"
        description="clean up" >
		<!-- Delete the ${build} and ${dist} directory trees -->
		<delete dir="${build}" />
		<delete dir="${dist}" />
	</target>

</project>

