<project name="KoLmafia" default="debug" basedir=".">
<!-- ========================================== -->
<!-- set the global properties for this build -->
<!-- ========================================== -->
<property name="root" value="."/>
<property name="src" value="src"/>
<property name="lib" value="lib"/>
<property name="util" value="util"/>
<property name="build" value="build"/>
<property name="dist" value="dist"/>
<property name="docs" value="${dist}/docs"/>
<property name="KoLConstants" value="${src}/net/sourceforge/kolmafia/KoLConstants.java"/>
<property name="main" value="net.sourceforge.kolmafia.KoLmafia"/>
<property name="synopsis" value="An alternate interface to Kingdom of Loathing"/>
<property environment="env"/>
<!-- Setting the version string. This breaks on platforms where we don't have grep... -->
<exec executable="grep" outputproperty="KoLVersion">
<arg value="VERSION_NAME" />
<arg value="${KoLConstants}" />
<redirector>
<outputfilterchain>
<replacestring from='public static final String VERSION_NAME = ' to=""/>
<replacestring from='KoLmafia v' to=""/>
<deletecharacters chars=';\"'/>
<trim/>
</outputfilterchain>
</redirector>
</exec>
<property name="KoLVersionedBaseFileName" value="${ant.project.name}-${KoLVersion}"/>
<property name="jarfile" value="${dist}/${KoLVersionedBaseFileName}.jar"/>
<property name="tarfile" value="${dist}/${KoLVersionedBaseFileName}.tar.gz"/>
<property name="appfile" value="${dist}/${KoLVersionedBaseFileName}.app"/>
<property name="dmgfile" value="${dist}/${KoLVersionedBaseFileName}.dmg"/>
<property name="debfile" value="${dist}/${KoLVersionedBaseFileName}.deb"/>
<property name="exefile" value="${dist}/${KoLVersionedBaseFileName}.exe"/>
<!-- classpath -->
<path id="classpath.compile">
</path>
<!-- ========================================== -->
<!-- create directories used by other targets -->
<!-- ========================================== -->
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
<mkdir dir="${dist}"/>
</target>
<!-- ==================================== -->
<!-- displays the current version from ${KoLConstants} -->
<!-- ==================================== -->
<target name="printversion">
<echo message="version: ${KoLVersion}" />
<echo message="version: ${KoLVersion_partial_NAME}" />
</target>
<!-- ==================================== -->
<!-- sets the default compiler to Jikes -->
<!-- ==================================== -->
<target name="jikeshome" if="env.JIKES_HOME">
<property name="build.compiler" value="jikes" />
<echo message="Set compiler: ${env.JIKES_HOME}" />
</target>
<!-- ================================== -->
<!-- reports the current Java version -->
<!-- ================================== -->
<target name="javahome" if="env.JAVA_HOME">
<exec executable="java" failifexecutionfails="false">
<arg value="-version"/>
</exec>
</target>
<!-- ================================== -->
<!-- update files from the repository -->
<!-- ================================== -->
<target name="update">
<exec executable="svn" failifexecutionfails="false">
<arg value="update"/>
<arg value="${root}"/>
</exec>
</target>
<!-- ================================== -->
<!-- update files from the repository -->
<!-- ================================== -->
<target name="version">
<exec executable="svnversion" outputproperty="revision" failifexecutionfails="false">
<arg value="-n"/>
<arg value="${root}"/>
</exec>
<property name="revision" value="0"/>
<echo message="Current revision: ${revision}"/>
</target>
<!-- ======================= -->
<!-- clean up object files -->
<!-- ======================= -->
<target name="clean">
<delete dir="${build}" failonerror="false"/>
<delete dir="${docs}" failonerror="false"/>
<delete failonerror="false">
<fileset dir="${dist}">
<include name="${ant.project.name}*"/>
</fileset>
</delete>
<symlink action="delete" link="${dist}/${KoLVersionedBaseFileName}/Applications" failonerror="false" />
<delete dir="${appfile}" failonerror="false"/>
</target>
<!-- ================================ -->
<!-- clean up KoLmafia object files -->
<!-- ================================ -->
<target name="start">
<delete dir="${build}/net/sourceforge/kolmafia" failonerror="false"/>
<delete dir="${docs}" failonerror="false"/>
<delete dir="${appfile}" failonerror="false"/>
<delete failonerror="false">
<fileset dir="${dist}">
<include name="${ant.project.name}*"/>
</fileset>
</delete>
<antcall target="init"/>
</target>
<!-- ====================== -->
<!-- generate class files -->
<!-- ====================== -->
<target name="compile" depends="init,jikeshome,javahome">
<javac srcdir="${src}" destdir="${build}"
source="1.4"
failonerror="false" debug="on"
debuglevel="lines,vars,source" deprecation="off"
nowarn="on" includeantruntime="false">
<classpath refid="classpath.compile"/>
</javac>
<copy todir="${build}" preservelastmodified="true">
<fileset dir="${src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy todir="${build}" preservelastmodified="true">
<fileset dir="${lib}">
<exclude name="**/*.jar"/>
</fileset>
</copy>
</target>
<!-- ========================================== -->
<!-- generate a zipped TAR of the source code -->
<!-- ========================================== -->
<target name="tar" depends="init">
<tar destfile="${tarfile}" basedir="${root}" compression="gzip">
<exclude name="build/**"/>
<exclude name="dist/**"/>
</tar>
</target>
<!-- =========================== -->
<!-- generate the standard JAR -->
<!-- =========================== -->
<target name="jar" depends="init,version">
<replace file="${KoLConstants}"
token="REVISION = null" value='REVISION = "${revision}"'/>
<antcall target="compile"/>
<replace file="${KoLConstants}"
token='REVISION = "${revision}"' value="REVISION = null"/>
<jar destfile="${jarfile}"
basedir="${build}"
update="true" index="true" compress="true">
<manifest>
<attribute name="Main-Class" value="${main}"/>
</manifest>
</jar>
</target>
<!-- =========================== -->
<!-- generate the standard EXE -->
<!-- =========================== -->
<target name="jsmooth" depends="init,update,jar">
<move file="${util}/windows/build.jsmooth" tofile="${util}/windows/tmp.build.jsmooth" />
<replace file="${util}/windows/tmp.build.jsmooth" token="dist/KoLmafia.exe" value='${exefile}'/>
<replace file="${util}/windows/tmp.build.jsmooth" token="dist/KoLmafia.jar" value='${jarfile}'/>
<taskdef name="jsmooth" classname="net.charabia.jsmoothgen.ant.JSmoothGen" classpath="${util}/windows/jsmoothgen-ant.jar" />
<jsmooth project="${util}/windows/tmp.build.jsmooth" skeletonroot="${util}/windows/skeletons"/>
<delete file="${util}/windows/tmp.build.jsmooth"/>
</target>
<!-- ================================ -->
<!-- generate an application bundle -->
<!-- ================================ -->
<target name="jarbundler" depends="init,update,jar">
<taskdef name="jarbundler" classname="net.sourceforge.jarbundler.JarBundler" classpath="${util}/macosx/jarbundler-2.1.0.jar" />
<jarbundler dir="${dist}" name="${KoLVersionedBaseFileName}" mainclass="net.sourceforge.kolmafia.KoLmafia" jar="${jarfile}" icon="${util}/macosx/limeglass.icns" vmoptions="-Xincgc" />
</target>
<!-- ========================== -->
<!-- create an OSX disk image -->
<!-- ========================== -->
<target name="dmg" depends="init,update,jar,jarbundler">
<mkdir dir="${dist}/${KoLVersionedBaseFileName}"/>
<symlink action="single" link="${dist}/${KoLVersionedBaseFileName}/Applications" resource="/Applications" />
<exec executable="cp" dir="${dist}">
<arg line="-a ${basedir}/${appfile} ${basedir}/${dist}/${KoLVersionedBaseFileName}/" />
</exec>
<delete file="${basedir}/${dmgfile}"/>
<exec executable="hdiutil" dir="${dist}">
<arg line="create ${basedir}/${dmgfile} -srcfolder ${basedir}/${dist}/${KoLVersionedBaseFileName} -volname ${KoLVersionedBaseFileName}" />
</exec>
<exec executable="rm" dir="${dist}">
<arg line="-rf KoLmafia*" />
</exec>
</target>
<!-- ========================== -->
<!-- create a Debian package -->
<!-- ========================== -->
<target name="debian" depends="init,update,version,jar,desktop">
<taskdef name="deb" classname="com.googlecode.ant_deb_task.Deb" classpath="${util}/debian/ant-deb.jar" />
<deb todir="${dist}" package="kolmafia" priority="optional" section="games" depends="sun-java6-jre">
<version upstream="${revision}" debian="${revision}"/>
<maintainer name="Veracity" email="veracity@hambo.com"/>
<description synopsis="${synopsis}">${synopsis}</description>
<tarfileset file="${jarfile}" prefix="usr/lib" filemode="755"/>
<tarfileset file="${build}/kolmafia.desktop" prefix="usr/share/applications"/>
<tarfileset file="util/debian/kol.xpm" prefix="usr/share/pixmaps"/>
<tarfileset file="util/debian/kol" prefix="usr/bin" filemode="755"/>
</deb>
</target>
<!-- ============================= -->
<!-- create Debian desktop entry -->
<!-- ============================= -->
<target name="desktop">
<taskdef name="desktopentry" classname="com.googlecode.ant_deb_task.DesktopEntry" classpath="${util}/debian/ant-deb.jar" />
<desktopentry toFile="build/kolmafia.desktop" name="${ant.project.name}" comment="${synopsis}" exec="/usr/bin/kol" icon="kol.xpm" terminal="false" type="Application" categories="Game;RolePlaying" />
</target>
<!-- ================================ -->
<!-- generate the alpha testing JAR -->
<!-- ================================ -->
<target name="debug" depends="start,version">
<replace file="${KoLConstants}"
token="RELEASED = true" value='RELEASED = false'/>
<antcall target="jar"/>
<replace file="${KoLConstants}"
token="RELEASED = false" value='RELEASED = true'/>
</target>
<!-- ============================ -->
<!-- generate a daily build JAR -->
<!-- ============================ -->
<target name="daily" depends="clean,init,update,version">
<replace file="${KoLConstants}"
token="REVISION = null" value='REVISION = "${revision}"'/>
<replace file="${KoLConstants}"
token="RELEASED = true" value='RELEASED = false'/>
<antcall target="compile"/>
<replace file="${KoLConstants}"
token='REVISION = "${revision}"' value="REVISION = null"/>
<replace file="${KoLConstants}"
token="RELEASED = false" value='RELEASED = true'/>
<jar destfile="${dist}/${ant.project.name}-${revision}.jar"
basedir="${build}"
update="true" index="true" compress="true">
<manifest>
<attribute name="Main-Class" value="${main}"/>
</manifest>
</jar>
</target>
<!-- =========================== -->
<!-- generate the distribution -->
<!-- =========================== -->
<target name="dist" depends="clean,init,update">
<antcall target="tar"/>
<antcall target="jar"/>
<antcall target="jsmooth"/>
<antcall target="jarbundler"/>
<antcall target="dmg"/>
</target>
<!-- ==================================================== -->
<!-- runs program with all needed libraries in the path -->
<!-- ==================================================== -->
<target name="exec" depends="jar">
<java fork="true" jar="${jarfile}" dir="${dist}">
<jvmarg value="-Xincgc" />
</java>
</target>
<!-- ============================================== -->
<!-- generates the release notes for the archive -->
<!-- ==================================================== -->
<target name="notes" depends="jar">
<java fork="true" classname="net.sourceforge.kolmafia.utilities.ReleaseNotes" classpath="${jarfile}" dir="${dist}" />
</target>
<!-- ======================================= -->
<!-- generate the javadocs from sourcecode -->
<!-- ======================================= -->
<target name="javadoc" depends="init">
<mkdir dir="${docs}"/>
<mkdir dir="${docs}/api"/>
<javadoc sourcepath="${src}" destdir="${docs}" packagenames="*">
<link href="http://java.sun.com/j2se/1.4.2/docs/api/"/>
<classpath>
<pathelement location="${lib}"/>
<pathelement location="${build}"/>
</classpath>
</javadoc>
</target>
</project>