<project name="BuildImages" default="build" >
	<!--
		Build the images directory for a given implementation. The resulting images will contain:
		1. All the images from "common" AND
		2. All the images for the specific implementation.

		Where there is a name conflict (an image with the same name in both common and implementation)
		then this is interpreted as an override by the implementation, in other words the implementation
		version of the image will overwrite the common version.

		This build must be called with the name of the implementation rootdir set in property:
		"implementation.name". If not set then the images from "common" alone will be used.

	-->

	<import file="build-import.xml"/>
	<property name="images.rootdir" location="${common.src.rootdir}/images"/>
	<property name="impl.images.rootdir" location="${impl.src.main.dir}/images"/>
	<property name="images.build.target.dir" location="${target.rootdir}/images"/>

	<target name="build" depends="init, copysrc" description="Builds images">
		<copy todir="${images.build.target.dir}" overwrite="true">
			<fileset dir="${images.tmp.src.dir}" includes="*.*" excludes="*.b64"/>
		</copy>
	</target>

	<target name="copysrc">
		<!--
			This step takes care of:
				- Image overrides (allowing implementation images to override common images)
				- Excludes file
				- Property expansion (in SVGs)
		-->
		<copy todir="${images.tmp.src.dir}" overwrite="true">
			<fileset dir="${images.rootdir}" includes="*.*" excludes="*.svg"/>
		</copy>
		<copy todir="${images.tmp.src.dir}" overwrite="true">
			<fileset dir="${impl.images.rootdir}" includes="*.*" excludes="*.svg" erroronmissingdir="false"/>
		</copy>
		<copy todir="${images.tmp.src.dir}" overwrite="true">
			<fileset dir="${images.rootdir}" includes="*.svg"/>
			<filterchain>
				<expandproperties/>
				<deletecharacters chars="\t"/>
				<trim/>
				<ignoreblank/>
				<striplinebreaks/>
			</filterchain>
		</copy>
		<copy todir="${images.tmp.src.dir}" overwrite="true">
			<fileset dir="${impl.images.rootdir}" includes="*.svg" erroronmissingdir="false"/>
			<filterchain>
				<expandproperties/>
				<deletecharacters chars="\t"/>
				<trim/>
				<ignoreblank/>
				<striplinebreaks/>
			</filterchain>
		</copy>
		<echo message="Done copying images"/>
	</target>

	<target name="clean" description="Cleans up all artifacts produced by this build">
		<delete dir="${images.tmp.src.dir}"/>
		<echo message="Clean from ${ant.file}"/>
	</target>

	<target name="init" depends="clean">
		<mkdir dir="${images.tmp.src.dir}"/>
	</target>

</project>