Simple Ant build file to build and run cpp files

I’ve tried to look for a simple ant build file for compiling c++ files however I’ve had no joy. After couple of hours or so I’ve made my own. It is basic for now however I’m going to update it later. Anyhoo, here it is if you are interested.

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

	<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

	<property name="src.dir" value="src"/>
	<property name="build.dir" value="bin"/>
	<property name="etc.dir" value="etc"/>
	<property name="resultset" value=""/>

	<target name="init">
		<mkdir dir="${build.dir}"/>
		<mkdir dir="${src.dir}"/>
		<mkdir dir="${etc.dir}"/>
	</target>
	
	<target name="build" depends="init">  
		<delete file="main"/>
		<foreach param="param.build" target="do.build">
			<path>  
				<fileset dir="${src.dir}" includes="*.cpp"/>  
			</path>
		</foreach>
	</target> 

	<target name="do.build">
		<propertyregex override="yes"
			property="filename" input="${param.build}"
			regexp=".*/(.*).cpp" replace="\1"/>
		<delete file="${build.dir}/${filename}.o"/>
		<echo message="building ${filename}.cpp"/>
		<exec executable="g++">
			<arg value="-Wall"/>
			<arg value="-c"/>
			<arg value="${src.dir}/${filename}.cpp"/>
			<arg value="-o"/>
			<arg value="${build.dir}/${filename}.o"/>
		</exec>
	</target>

	<target name="make">
		<delete file="${etc.dir}/main.properties"/>
		<echo file="${etc.dir}/main.properties" append="true" message="path="/> 
		<foreach param="param.make" target="do.make">
			<path>  
				<fileset dir="${build.dir}" includes="*.o"/>  
			</path>
		</foreach>
	</target>

	<target name="do.make">
		<propertyregex override="yes"
				property="filename" input="${param.make}"
				regexp=".*/(.*).o" replace="\1"/>
		<echo file="${etc.dir}/main.properties" append="true" message="${build.dir}/${filename}.o "/> 
	</target>

	<target name="run" depends="make">
		<property prefix="make" file="${etc.dir}/main.properties"/>
		<echo message="${make.path}"/>
		<exec command="g++ ${make.path} -o main"/>
		<exec executable="./main"/>
	</target>
</project>