<project default="all" name="IP2Country">
	
    <target name="clean">
        <delete dir="dist"/>
    </target>

    <target name="compile">
        <mkdir dir="dist/"/>
        <mkdir dir="dist/tmp"/>
        <mkdir dir="dist/classes"/>
        <javac srcdir="java/src" destdir="dist/classes" target="1.3" source="1.3" classpath="lib/junit3.8.1.jar"/>
    	
        <java classname="net.firefang.ip2c.IP2Country">
          <arg value="ip-to-country.csv"/>
          <arg value="ip-to-country.bin"/>
          <classpath>
            <pathelement path="dist/classes"/>
          </classpath>
        </java>
		<copy todir="dist/tmp/"  file="ip-to-country.bin"/>
    </target>

    <target name="pack">
    	<loadproperties srcFile="build.properties"/>
    		
    	<copy todir="dist/classes">
				<fileset dir="java/src"/>
    	</copy>

    	<copy todir="dist/tmp">
				<fileset dir="php"/>
    	</copy>

    	<copy todir="dist/tmp/"  file="GPL_V2"/>
    	<copy todir="dist/tmp/"  file="README"/>
    	
        <jar destfile="dist/tmp/ip2c.jar" basedir="dist/classes">
            <manifest>
                <attribute name="Main-Class" value="net.firefang.ip2c.IP2Country"/>
            </manifest>
        </jar>
    	
   	    <echo file="dist/tmp/db.version">${database_ver}</echo>

 	<replace dir="dist/tmp" token="SVN-VERSION" value="${version}"/>

    	<zip destfile="dist/ip2c-${version}.zip">
    		<zipfileset dir="dist/tmp/" prefix="ip2c"/>
    	</zip>
    </target>

	<target name="pack_db">
		<loadproperties srcFile="build.properties"/>
		<mkdir dir="dist/tmp2"/>
		<copy todir="dist/tmp2/"  file="dist/tmp/ip-to-country.bin"/>
		<echo file="dist/tmp2/db.version">${database_ver}</echo>
    	<zip destfile="dist/tmp2/ip-to-country.zip">
    		<zipfileset dir="dist/tmp2/"/>
    	</zip>
		<delete file="dist/tmp2/db.version"/>	
	    <echo file="dist/tmp2/ip-to-country.latest"><![CDATA[# Latest ip2country database version
[ip-to-country-db]
version=${database_ver}
bin_url=http://files.firestats.cc/ip2c/ip-to-country.bin
zip_url=http://files.firestats.cc/ip2c/ip-to-country.zip
]]></echo>
    	<zip destfile="dist/ip-to-country-db.zip">
    		<zipfileset dir="dist/tmp2/"/>
    	</zip>

	</target>

    <target name="all" depends="clean, compile, pack, pack_db"/>
</project>
