<project name="tinyos-2.x support sdk java" default="all">

	<property environment="env"/>
	
	<target name="all" >
		<echo message = "Building support sdk java" />
		<exec executable="make" failonerror="true">
			<arg line="all" />
		</exec>
	</target>

	<target name="tinyos.jar">
		<echo message="Building tinyos.jar"></echo>
		<exec failonerror="true" executable="make">
			<arg line="tinyos.jar"></arg></exec>
	</target>

	<target name="javadoc" >
		<echo message = "Building javadoc" />
		<exec executable="make" failonerror="true">
			<arg line="javadoc" />
		</exec>
	</target>
	
	<target name="init">
		<echo message="Generating TinyOS message classes" />
		<exec executable="mig" failonerror="true">
			<arg value="-o" />
			<arg path="net/tinyos/message/SerialPacket.java" />
			<arg value="-java-classname=net.tinyos.message.SerialPacket" />
			<arg value="java" />
			<arg path="${env.TOSDIR}/lib/serial/Serial.h" />
			<arg value="serial_packet" />
			<arg prefix="-I" path="${env.TOSDIR}/types" />
		</exec>
		<exec executable="mig" failonerror="true">
			<arg value="-o" />
			<arg path="net/tinyos/tools/PrintfMsg.java" />
			<arg value="-java-classname=net.tinyos.tools.PrintfMsg" />
			<arg value="java" />
			<arg path="${env.TOSDIR}/lib/printf/printf.h" />
			<arg value="printf_msg" />
		</exec>
		<exec executable="ncg" failonerror="true">
			<arg value="-o" />
			<arg path="net/tinyos/packet/Serial.java" />
			<arg value="-java-classname=net.tinyos.packet.Serial" />
			<arg value="java" />
			<arg path="${env.TOSDIR}/lib/serial/Serial.h" />
			<arg value="Serial.h" />
		</exec>
	</target>
	
	<target name="compile" depends="init">
		<javac srcdir="." classpath="" includeAntRuntime="false" />
	</target>
	
	<target name="jar" depends="compile">
		<jar destfile="tinyos.jar">
			<fileset dir="." includes="**/*.class" />
			<fileset dir="." includes="**/*.lib" />
		</jar>
	</target>
	
	<target name="clean">
		<echo message="Removing generated files" />
		<delete file="net/tinyos/message/SerialPacket.java" />
		<delete file="net/tinyos/tools/PrintfMsg.java" />
		<delete file="net/tinyos/packet/Serial.java" />
		<delete>
			<fileset dir="." includes="**/*.class"/>
		</delete>
	</target>
	
</project>
