<?xml version="1.0"?>

<!--
 * Copyright (c) 2006, Televolution, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of Televolution nor the names of any contributors may be
 * used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
-->

<project name="gnomemidlet" default="build" basedir=".">

   <property environment="env"/>

   <property file="build.properties"/>

   <taskdef resource="antenna.properties"/>

   <target name="init">
      <tstamp/>
      <path id="setlibclasspath">
         <fileset dir="${lib}">
            <include name="**/*.jar"/>
         </fileset>
      </path>
      <property name="libclasspath" refid="setlibclasspath" /> 
   </target>

   <target name="mkdirs">
      <mkdir dir="${classes}"/>
      <mkdir dir="${build}"/>
   </target>

   <target name="env">
      <echo message="build         = ${build}"/>
      <echo message="classes       = ${classes}"/>
      <echo message="lib           = ${lib}"/>
      <echo message="src           = ${src}"/>
      <echo message="wtk.home      = ${wtk.home}"/>
      <echo message="bootclasspath = ${bootclasspath}"/>
   </target>

   <target name="clean">
      <delete dir="${classes}"/>
      <delete dir="${build}"/>
   </target>

   <target name="makeJad">
      <wtkjad jadfile="${build}/${jad.filename}"
         jarfile="${build}/${jar.filename}"
         name="${app.name}"
         vendor="${app.vendor}"
         target="${target.url}" 
         version="${app.version}"
      >

      <midlet name="${app.name}" class="${app.class}"/>
      <attribute name="app.rpcurl" value="${app.rpcurl}"/>
      <attribute name="app.fetchmethod" value="${app.fetchmethod}"/>
      <attribute name="app.dialmethod" value="${app.dialmethod}"/>
      <attribute name="app.vmsgmethod" value="${app.vmsgmethod}"/>
      <attribute name="app.click2dialmethod" value="${app.click2dialmethod}"/>
      <attribute name="app.setconfigmethod" value="${app.setconfigmethod}"/>
      <attribute name="MIDlet-Permissions" value="javax.microedition.io.Connector.http"/>
      <attribute name="MIDlet-Info-URL" value="${info.url}"/>

      </wtkjad>

   </target>

   <!-- See target 'local'.  Used when testing local build visavis "ant local; emulator -Xdescriptor build/pg.jad" -->
   <target name="makeLocalJad">
      <wtkjad jadfile="${build}/${jad.filename}"
         jarfile="${build}/${jar.filename}"
         name="${app.name}"
         vendor="${app.vendor}"
         version="${app.version}"
      >

      <midlet name="${app.name}" class="${app.class}"/>
      <attribute name="app.rpcurl" value="${app.rpcurl}"/>
      <attribute name="app.fetchmethod" value="${app.fetchmethod}"/>
      <attribute name="app.dialmethod" value="${app.dialmethod}"/>
      <attribute name="app.vmsgmethod" value="${app.vmsgmethod}"/>
      <attribute name="app.click2dialmethod" value="${app.click2dialmethod}"/>
      <attribute name="app.setconfigmethod" value="${app.setconfigmethod}"/>
      <attribute name="MIDlet-Permissions" value="javax.microedition.io.Connector.http"/>
      <attribute name="MIDlet-Info-URL" value="${info.url}"/>

      </wtkjad>

   </target>

   <target name="compile" >
      <wtkbuild srcdir="${src}" 
                destdir="${classes}" 
                debug="true" 
                preverify="true" 
                bootclasspath="${bootclasspath}:${libclasspath}"
      />
      <!-- an attempt to drive with jdk1.5 and impose j2me-acceptable outputs.  it failed.
                executable="${compiler.home}/bin/javac" 
                target="1.1"
                source="1.2"
                compiler="${compiler}"
      -->

   </target>

   <target name="makeJar">
      <wtkpackage jarfile="${build}/${jar.filename}"
                  jadfile="${build}/${jad.filename}"
                  obfuscate="false"
                  preverify="true"
                  libclasspath="${libclasspath}"
                  bootclasspath="${bootclasspath}"> 
         <fileset dir="${classes}"/>
         <fileset dir="${res}"/>
      </wtkpackage>
   </target>

   <target name="strip">
      <wtksmartlink jarfile="${build}/${jar.filename}"
                    jadfile="${build}/${jad.filename}"
                    classpath="${libclasspath}"
                    bootclasspath="${bootclasspath}"> 
      </wtksmartlink>
   </target>

   <target name="build" depends="env,mkdirs,init,makeJad,compile,makeJar,strip"/>

   <!-- Use this target when testing local build visavis "ant local; emulator -Xdescriptor build/pg.jad" -->
   <target name="local" depends="env,mkdirs,init,makeLocalJad,compile,makeJar,strip"/>

   <target name="source" depends="env">
      <zip destfile="${lib}/${name}-src.zip" >
         <zipfileset dir="${basedir}">
           <include name="build.xml"/>
           <include name="build.properties"/>
           <include name="antenna.properties"/>
           <include name="README"/>
           <include name="CHANGES"/>
           <include name="makeall.sh"/>
           <include name="upload-stub.sh"/>
           <include name="removeapp.sh"/>
           <include name="install.sh"/>
           <include name="runams.sh"/>
           <include name="listapps.sh"/>
         </zipfileset>
         <zipfileset dir="${res}" prefix="${res}">
            <include name="**/*.png"/>
         </zipfileset>
         <zipfileset dir="${src}" prefix="${src}">
            <include name="**/*.java"/>
         </zipfileset>
         <zipfileset dir="${kxml.home}" prefix="src">
            <include name="**/*.java"/>
         </zipfileset>
      </zip>
   </target>

</project>
