<?xml version="1.0"?>

<project name="MSPSim COOJA support" default="jar" basedir=".">
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="lib" location="lib"/>
  <property name="javadoc" location="javadoc"/>
  <property name="cooja" location="../.."/>
  
  <property name="cooja_jar" value="${cooja}/dist/cooja.jar"/>
  <property name="mspsim" location="../../../mspsim"/>
  <property name="mspsim_jar" value="${lib}/mspsim.jar"/>
  <property name="coffee" location="../../../coffee-manager"/>
  <property name="coffee_jar" value="${lib}/coffee.jar"/>
  <property name="cooja_mspsim_jar" value="${lib}/cooja_mspsim.jar"/>

  <target name="init">
    <tstamp/>
    <mkdir dir="${build}"/>
    <mkdir dir="${lib}"/>
  </target>

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

  <target name="mspsim" depends="init">
    <copy todir="${lib}" file="${mspsim}/mspsim.jar" />
    <copy todir="${lib}" file="${mspsim}/lib/jipv6.jar" />
  </target>

  <target name="coffee" depends="init">
    <ant antfile="build.xml" dir="${coffee}" target="jar" inheritAll="false"/>
    <copy todir="${lib}" file="${coffee}/coffee.jar" />
  </target>

  <target name="compile" depends="init,mspsim,coffee">
    <javac srcdir="${src}" destdir="${build}" debug="on">
      <classpath>
        <pathelement location="${mspsim_jar}"/>
        <pathelement location="${coffee_jar}"/>
        <pathelement location="${cooja_jar}"/>
      </classpath>
    </javac>
  </target>

  <target name="javadoc" depends="compile">
    <delete dir="${javadoc}" quiet="true"/>
    <mkdir dir="${javadoc}/"/>
    <javadoc destdir="${javadoc}">
      <fileset dir="${src}/" includes="**/*.java"/>
      <classpath>
        <pathelement location="${mspsim_jar}"/>
        <pathelement location="${coffee_jar}"/>
        <pathelement location="${cooja_jar}"/>
      </classpath>
    </javadoc>
  </target>

  <target name="jar" depends="init, compile">
    <jar destfile="${cooja_mspsim_jar}" basedir="${build}">
      <manifest>
        <attribute name="Class-Path" value="."/>
      </manifest>
    </jar>
  </target>

</project>
