<?xml version="1.0" encoding="UTF-8" ?>

<!-- Copyright (C) 2008 Ted Kosan (license information is at the end of this document.) -->

<project id="mathpiper" name="mathpiper" default="dist" basedir="." >
	<description>
		Build file for MathPiper.
	</description>
	
	
        <!--
	<property name="compile.source" value="1.5" />
	<property name="compile.target" value="1.5" />
	<property name="src.dir" value="${basedir}/src" />
	<property name="build.dir" value="${basedir}/build" />
	<property name="mathpiper.dir" value="${basedir}" />
	<path id="build_classpath">
	</path> -->

	
	<!-- <property name="version" value=".58" /> -->
	<property name="build.classes.dir" value="${build.dir}/classes" />
	
	
	<target id="noop" name="noop" description="Do nothing." />
	
	<target id="clean" name="clean" 
		description="Deletes the MathPiper build directory" >
		
		<echo message="Removing the build directory...." />
		<delete dir="${build.dir}" />
	</target>
	
	<target name="init" depends="clean">
	    <condition property="IsUnix" value="true">
		    <os family="unix" />
	    </condition>

		<tstamp>
			<format property="build.time" pattern="MM/dd/yyyy hh:mm aa" />
		</tstamp>
		<mkdir dir="${build.dir}" />
		<mkdir dir="${build.classes.dir}" />
	</target>
	
	<target name="compile" depends="init"
		description="Compiles the application" >
		<!--<echo message="${compile.source}." />
		<echo message="${src.dir}." />
		<echo message="${build.classes.dir}." />-->
	
		<javac 
			source="${compile.source}"
			target="${compile.target}" 
			srcdir="${src.dir}"
			destdir="${build.classes.dir}"
			debug="off"
			deprecation="on"
			optimize="off"
                        includeantruntime="false">
			<classpath refid="build_classpath" />
			<include name="**/*.java" />
		</javac>
		
		<copy todir="${build.classes.dir}/org/mathpiper/ui/gui/hoteqn">
			<fileset dir="${src.dir}/org/mathpiper/ui/gui/hoteqn" >
				<include name="*.gif" />
			</fileset>
		</copy>
		
		<copy todir="${build.classes.dir}/org/mathpiper/ui/gui/jmathtex/xmlconfigurationparsers">
			<fileset dir="${src.dir}/org/mathpiper/ui/gui/jmathtex/xmlconfigurationparsers" >
				<include name="*.xml" />
				<include name="*.ttf" />
			</fileset>
		</copy>
		
		<copy todir="${build.classes.dir}/org/scilab">
			<fileset dir="${src.dir}/org/scilab" >
				<include name="**/*.xml" />
				<include name="**/*.ttf" />
			</fileset>
		</copy>
		
		
		<copy todir="${build.classes.dir}/org/mathpiper/scripts4">
			<fileset dir="${src.dir}/org/mathpiper/scripts4" >
				<include name="**/*.mpw" />
			</fileset>
		</copy>
		
	</target>
	
      
       
       
      
   	<target name="buildscripts4" >
		<mkdir dir="${build.classes.dir}/org/mathpiper/ui/gui/help/data" />
	        <mkdir dir="${build.classes.dir}/org/mathpiper/assembledscripts" />
	        <mkdir dir="${build.classes.dir}/org/mathpiper/assembledscripts/initialization.rep" />
		<taskdef name="buildscripts" classname="org.mathpiper.test.Build" classpath="${build.classes.dir}"  />

		<buildscripts sourceScriptsDirectory="${src.dir}/org/mathpiper/scripts4/"
                 outputScriptsDirectory="${build.classes.dir}/org/mathpiper/assembledscripts/"
		 outputDirectory="${build.classes.dir}/"
		 baseDirectory="${basedir}/"/>
        </target>
      
      


    
    
	<target id="dist" name="dist" depends="compile,buildscripts4" >
	
		<!--<copy todir="${build.classes.dir}/org/mathpiper/scripts">
			<fileset dir="${mathpiper.dir}/src/org/mathpiper/scripts" >
				<include name="*.rep/**/*" />
			</fileset>
		</copy>-->
		
		<mkdir dir="${build.classes.dir}/tests" />
		<mkdir dir="${build.classes.dir}/tests/scripts4" />
		<copy todir="${build.classes.dir}/tests/scripts4">
			<fileset dir="${mathpiper.dir}/tests/scripts4" >
				<include name="**/*" />
			</fileset>
		</copy>

		
		<copy file="${mathpiper.dir}/tests/win_test.bat" todir="${build.classes.dir}"/>
		<copy file="${mathpiper.dir}/tests/unix_test.sh" todir="${build.classes.dir}"/>

		<antcall target="chmod-unix-test-script"/>
		
		<!--<copy file="${mathpiper.dir}/mathpiper.properties" todir="${build.classes.dir}">
			<filterset>
	               
		       	   <filter token="VERSION" value="${version}" />
	               
			 </filterset>
		</copy>-->
	
		<mkdir dir="${build.dir}/dist" />
		
		<jar jarfile="${build.dir}/dist/mathpiper.jar"
			basedir="${build.classes.dir}" update="true"
			manifest="${mathpiper.dir}/resources/MANIFEST.MF">
			<!--<manifest> 
				<section name="mathpiper" >
					<attribute name="Build-Date" value="${build.time}"/>
				</section>
			</manifest>-->
			<include name="**/*" />
			<exclude name="**/*.bat,**/*.sh" />
		</jar> 
	</target>
	
	<target  id="chmod-unix-test-script" name="chmod-unix-test-script" if="IsUnix">
	    <echo message="Making unix test script executable."/>
	    <exec executable="chmod">
		    <arg value="+x" />
		    <arg value="${build.classes.dir}/unix_test.sh" />
	    </exec>
	</target>
	
	<target id="geogebra_dist" name="geogebra_dist" depends="buildscripts4" >
	
	<!--  
	cvs -z3 -d:ext:tkosan@geogebra.cvs.sourceforge.net:/cvsroot/geogebra co -P geogebra
	export CVSROOT=:ext:tkosan@geogebra.cvs.sourceforge.net:/cvsroot/geogebra
	cvs commit -m "The code is now compatible with Java 1.4."
	cvs import -m "This is a stripped-down version of MathPiper.  An example of how to use MathPiper can be found in the org/mathpiper/HowToUse.java file." geogebra/org/mathpiper/geogebrascripts MATHPIPER V0_63
	
	Edit BuiltinFunctionInitialize to remove functions at the bottom of the file.
	Edit Interpreters to remove references to AsynchronousInterpreter.
	
	-->
		
		<delete dir="${build.dir}/geogebra_dist" />
	
		<!--<copy todir="${build.classes.dir}">
			<fileset dir="${mathpiper.dir}/scripts" >
				<include name="**/*" />
			</fileset>
		</copy>-->
		

		

		<mkdir dir="${build.dir}/geogebra_dist" />
		<mkdir dir="${build.dir}/geogebra_dist/src" />
		<mkdir dir="${build.dir}/geogebra_dist/src/org/mathpiper/geogebrascripts" />
		<mkdir dir="${build.dir}/geogebra_dist/src/org/mathpiper/builtin/functions/optional" />
		<mkdir dir="${build.dir}/geogebra_dist/src/org/mathpiper/builtin/functions/plugins" />
		

		

		
		
		<copy todir="${build.dir}/geogebra_dist/src">
			<fileset dir="${mathpiper.dir}/src/" >
				<include name="org/mathpiper/Version.java" />
				<include name="org/mathpiper/HowToUse.java" />
				<include name="org/mathpiper/builtin/" />
				<exclude name="org/mathpiper/builtin/functions/optional/" />
				<exclude name="org/mathpiper/builtin/functions/plugins/" />
				<include name="org/mathpiper/builtin/library/jas/" />
				<exclude name="org/mathpiper/builtin/library/cern/" />
				<exclude name="org/mathpiper/builtin/library/jscistats/" />
				<exclude name="org/mathpiper/builtin/library/statdistlib/" />
				<include name="edu/" />
				<include name="org/apache/" />
				<include name="org/mathpiper/exceptions/" />
				<include name="org/mathpiper/interpreters/" />
				<include name="org/mathpiper/io/" />
				<include name="org/mathpiper/lisp/" />
				<include name="org/mathpiper/parametermatchers/" />
				<include name="org/mathpiper/printers/" />
				<include name="org/mathpiper/ui/text/consoles/" />
				<include name="org/mathpiper/ui/gui/consoles/Console.java" />

			</fileset>
		</copy>



		
		<copy todir="${build.dir}/geogebra_dist/src/org/mathpiper/geogebrascripts">
			<fileset dir="${build.dir}/classes/org/mathpiper/assembledscripts" includes="*.rep/**/*" />
			<filterchain>
				<filterreader classname="org.apache.tools.ant.filters.StripJavaComments">
				<!--<param name="foo" value="bar"/>-->
				</filterreader>
				<!--<scriptfilter language="beanshell">
				if (self.getToken().indexOf("bad") != -1) {
				self.setToken(null);
				}
				</scriptfilter>-->
			</filterchain>
		</copy>		
		


		  <replaceregexp file="${build.dir}/geogebra_dist/src/org/mathpiper/interpreters/SynchronousInterpreter.java"
                         match="assembledscripts"
                         replace="geogebrascripts"/>

		
	<!--	<mkdir dir="${build.dir}/geogebra_dist/classes" />
		
		<copy todir="${build.dir}/geogebra_dist/classes">
			<fileset dir="${build.dir}/geogebra_dist/scripts" >
				<include name="**/*" />
			</fileset>
		</copy>
		
		
		<javac 
			source="1.4"
			target="1.4" 
			srcdir="${build.dir}/geogebra_dist"
			destdir="${build.dir}/geogebra_dist/classes"
			debug="off"
			deprecation="on"
			optimize="off">
			<include name="**/*.java" />
		</javac>
		
		<jar jarfile="${build.dir}/geogebra_dist/mathpiper.jar"
			basedir="${build.dir}/geogebra_dist/classes" update="true" >
			<include name="**/*" />

		</jar> -->

	</target>
	
	
	
	
	
	<target id="geogebra_compile" name="geogebra_compile" depends="geogebra_dist" >
	
	      <delete dir="${build.dir}/geogebra_dist/build" />
	      
	      
	      <mkdir dir="${build.dir}/geogebra_dist/build" />
	      
	      
	      <mkdir dir="${build.dir}/geogebra_dist/build/org/mathpiper/test" />
	      <copy file="${src.dir}/org/mathpiper/test/RunTestSuite.java" todir="${build.dir}/geogebra_dist/src/org/mathpiper/test"/>

	     
	      
			<javac 
			source="1.5"
			target="1.5" 
			srcdir="${build.dir}/geogebra_dist/src"
			destdir="${build.dir}/geogebra_dist/build"
			debug="off"
			deprecation="on"
			optimize="off">
			<!--<classpath refid="build_classpath" />-->
			<include name="**/*.java" />
		</javac>
		
		
		<delete dir="${build.dir}/geogebra_dist/src/org/mathpiper/test" />
		
		
		<!-- Copy MathPiper scripts -->
		<mkdir dir="${build.dir}/geogebra_dist/build/org/mathpiper/geogebrascripts" />
		<copy todir="${build.dir}/geogebra_dist/build/org/mathpiper/geogebrascripts">
			<fileset dir="${build.dir}/geogebra_dist/src/org/mathpiper/geogebrascripts" >
				<include name="**/*" />
			</fileset>
		</copy>
		
		
		
		<!-- Copy test scripts -->
		<mkdir dir="${build.dir}/geogebra_dist/build/tests" />
		<copy todir="${build.dir}/geogebra_dist/build/tests">
			<fileset dir="${mathpiper.dir}/tests" >
				<include name="**/*" />
			</fileset>
		</copy>
		
		<mkdir dir="${build.dir}/geogebra_dist/build/org/mathpiper/builtin/functions/optional" />
	        <mkdir dir="${build.dir}/geogebra_dist/build/org/mathpiper/builtin/functions/plugins" />
		
		<copy file="${mathpiper.dir}/tests/win_test.bat" todir="${build.dir}/geogebra_dist/build"/>
		<copy file="${mathpiper.dir}/tests/unix_test.sh" todir="${build.dir}/geogebra_dist/build"/>

	</target>


</project>

<!-- {{{ License.
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 }}} -->

