<project name="examples" default="eg1" basedir="." xmlns:cpptasks="antlib:net.sf.antcontrib.cpptasks">

	<property name="javacc.home" value="../../../target/" />
	<condition property="linux">
		<os name="Linux" />
	</condition>
	<condition property="linux">
		<os name="Windows 7" />
	</condition>
	<condition property="platform" value="Linux">
		<isset property="linux" />
	</condition>
	
	
	<target name="eg1" description="Builds example 'eg1'">
		<delete dir="eg1" />
		<mkdir dir="eg1" />
		<copy file="eg1.jjt" todir="eg1" />
		<copy file="eg1.cc" todir="eg1" />
		<jjtree target="eg1.jjt" outputdirectory="eg1" javacchome="${javacc.home}" />
		<javacc target="eg1/eg1.jj" outputdirectory="eg1" javacchome="${javacc.home}" />
		<cpptasks:cc outtype="executable" subsystem="console" outfile="eg1/eg1" objdir="eg1">
			<fileset dir="eg1" includes="*.cc" />
			<compiler name="g++" id="Linuxg++" >
				<compilerarg value="-g" if="debug" />
				<compilerarg value="-Wall" />
				<compilerarg value="-fpermissive" />
				<compilerarg value="-O2" />
				<compilerarg value="-std=c++11" />
			</compiler>
			
			<linker id="LinuxLinker" name="g++" libtool="true">
				<linkerarg value="-g" if="debug" />
				<libset libs="stdc++" />
			</linker>
		</cpptasks:cc>
		<exec executable="eg1/eg1.exe"/>
	</target>

	<target name="eg2" description="Builds example 'eg2'">
		<delete dir="eg2" />
		<mkdir dir="eg2" />
		<copy file="eg2.jjt" todir="eg2" />
		<copy file="eg2.cc" todir="eg2" />
		<jjtree target="eg2.jjt" outputdirectory="eg2" javacchome="${javacc.home}" />
		<javacc target="eg2/eg2.jj" outputdirectory="eg2" javacchome="${javacc.home}" />
		<copy file="ASTMyID.h" todir="eg2" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG2"/>
		    </filterset>
		</copy>
		<copy file="ASTMyID.cc" todir="eg2" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG2"/>
		    </filterset>
		</copy>
		<cpptasks:cc outtype="executable" subsystem="console" outfile="eg2/eg2" objdir="eg2">
			<fileset dir="eg2" includes="*.cc" />
			<compiler name="g++" id="Linuxg++" >
				<compilerarg value="-g" if="debug" />
				<compilerarg value="-Wall" />
				<compilerarg value="-fpermissive" />
				<compilerarg value="-O2" />
				<compilerarg value="-std=c++11" />
			</compiler>
			
			<linker id="LinuxLinker" name="g++" libtool="true">
				<linkerarg value="-g" if="debug" />
				<libset libs="stdc++" />
			</linker>
		</cpptasks:cc>
		<exec executable="eg2/eg2.exe"/>
	</target>

	<target name="eg3" description="Builds example 'eg3'">
		<delete dir="eg3" />
		<mkdir dir="eg3" />
		<copy file="eg3.jjt" todir="eg3" />
		<copy file="eg3.cc" todir="eg3" />
		<jjtree target="eg3.jjt" outputdirectory="eg3" javacchome="${javacc.home}" />
		<javacc target="eg3/eg3.jj" outputdirectory="eg3" javacchome="${javacc.home}" />
		<copy file="ASTMyID.h" todir="eg3" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG3"/>
		    </filterset>
		</copy>
		<copy file="ASTMyID.cc" todir="eg3" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG3"/>
		    </filterset>
		</copy>
		<cpptasks:cc outtype="executable" subsystem="console" outfile="eg3/eg3" objdir="eg3">
			<fileset dir="eg3" includes="*.cc" />
			<compiler name="g++" id="Linuxg++" >
				<compilerarg value="-g" if="debug" />
				<compilerarg value="-Wall" />
				<compilerarg value="-fpermissive" />
				<compilerarg value="-O2" />
				<compilerarg value="-std=c++11" />
			</compiler>
			
			<linker id="LinuxLinker" name="g++" libtool="true">
				<linkerarg value="-g" if="debug" />
				<libset libs="stdc++" />
			</linker>
		</cpptasks:cc>
		<exec executable="eg3/eg3.exe"/>
	</target>

	<target name="eg4" description="Builds example 'eg4'">
		<delete dir="eg4" />
		<mkdir dir="eg4" />
		<copy file="eg4.jjt" todir="eg4" />
		<copy file="eg4.cc" todir="eg4" />
		<jjtree target="eg4.jjt" outputdirectory="eg4" javacchome="${javacc.home}" />
		<javacc target="eg4/eg4.jj" outputdirectory="eg4" javacchome="${javacc.home}" />
		<copy file="ASTMyID.h" todir="eg4" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG4"/>
		    </filterset>
		</copy>
		<copy file="ASTMyID.cc" todir="eg4" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG4"/>
		    </filterset>
		</copy>
		<copy file="ASTMyOtherID.h" todir="eg4" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG4"/>
		    </filterset>
		</copy>
		<copy file="ASTMyOtherID.cc" todir="eg4" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG4"/>
		    </filterset>
		</copy>
		<copy file="Eg4DumpVisitor.h" todir="eg4" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG4"/>
		    </filterset>
		</copy>
		<copy file="Eg4DumpVisitor.cc" todir="eg4" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG4"/>
		    </filterset>
		</copy>
		<copy file="MyErrorHandler.h" todir="eg4" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG4"/>
		    </filterset>
		</copy>
		<copy file="MyErrorHandler.cc" todir="eg4" overwrite="on">
		    <filterset>
		      <filter token="NAMESPACE" value="EG4"/>
		    </filterset>
		</copy>
		<cpptasks:cc outtype="executable" subsystem="console" outfile="eg4/eg4" objdir="eg4">
			<fileset dir="eg4" includes="*.cc" />
			<compiler name="g++" id="Linuxg++" >
				<compilerarg value="-g" if="debug" />
				<compilerarg value="-Wall" />
				<compilerarg value="-fpermissive" />
				<compilerarg value="-O2" />
				<compilerarg value="-std=c++11" />
			</compiler>
			
			<linker id="LinuxLinker" name="g++" libtool="true">
				<linkerarg value="-g" if="debug" />
				<libset libs="stdc++" />
			</linker>
		</cpptasks:cc>
		<exec executable="eg4/eg4.exe"/>
	</target>

	<target name="all" description="Builds all examples" depends="clean,eg1,eg2,eg3,eg4">
		<echo message="*******" />
		<echo message="******* All Built ******" />
		<echo message="*******" />
	</target>

	<target name="clean" description="Cleans up any example directories">
		<delete dir="eg1" />
		<delete dir="eg2" />
		<delete dir="eg3" />
		<delete dir="eg4" />
	</target>


</project>
