<?xml version="1.0"?>

<project name="JInput dx8 port, Native code" basedir="." default="compile">
	<property environment="env"/>
	<property name="dxhome" location="${env.DXSDK_DIR}"/>
	<property name="plthome" location="${env.MSSdk}"/>
	<property name="chome" location="c:/MinGW"/>
	<property name="gcc" location="${chome}/bin/gcc"/>
	<property name="strip" location="${chome}/bin/strip"/>

	<target name="compile_dir">
		<echo message="${compiledir}"/>
		<apply dir="${compiledir}" failonerror="true" executable="${gcc}" dest="${compiledir}" skipemptyfilesets="true">
			<arg line="-c -Wall -O2 -std=gnu99"/>
			<arg value="-I${dxhome}/include"/>
			<arg value="-I${java.home}/../include"/>
			<arg value="-I${java.home}/../include/win32"/>
			<arg value="-I${commonhome}/src/native"/>
			<arg value="-I.."/>
			<srcfile/>
			<fileset dir="${compiledir}" includes="*.c"/>
			<mapper type="glob" from="*.c" to="*.o"/>
		</apply>
	</target>

	<target name="link">
		<apply dir="." parallel="true" executable="${gcc}" failonerror="true">
			<arg value="-Wl,--kill-at"/>
			<arg line="-shared -o ${dllname}"/>
			<srcfile/>
			<arg value="-L${java.home}/lib"/>
			<arg value="-L${dxhome}/lib/x86"/>
			<arg line="${libs}"/>
			<fileset dir="${commonhome}/src/native" includes="*.o"/>
			<fileset dir="." includes="*.o"/>
			<fileset dir="${objdir}" includes="*.o"/>
		</apply>
		<apply dir="." executable="${strip}" failonerror="true">
			<fileset dir="." includes="${dllname}"/>
		</apply>
	</target>

	<target name="clean">
		<delete>
			<fileset dir="." includes="*.o"/>
			<fileset dir="raw" includes="*.o"/>
			<fileset dir="dx8" includes="*.o"/>
			<fileset dir="." includes="*.dll"/>
		</delete>
	</target>

	<target name="compile">
		<property name="rawlibs" value="-lkernel32 -luser32 -lsetupapi -luuid"/>
		<property name="dx8libs" value="-lkernel32 -ldinput8 -ldxguid -luser32"/>
		<property name="commonhome" location="../../../common"/>
		<property name="dx8dllname" value="jinput-dx8.dll"/>
		<property name="rawdllname" value="jinput-raw.dll"/>
		<antcall target="compile_dir">
			<param name="compiledir" location="${commonhome}/src/native"/>
		</antcall>
		<antcall target="compile_dir">
			<param name="compiledir" location="."/>
		</antcall>
		<antcall target="compile_dir">
			<param name="compiledir" location="raw"/>
		</antcall>
		<antcall target="compile_dir">
			<param name="compiledir" location="dx8"/>
		</antcall>
		<antcall target="link">
			<param name="dllname" value="${dx8dllname}"/>
			<param name="libs" value="${dx8libs}"/>
			<param name="objdir" location="dx8"/>
		</antcall>
		<antcall target="link">
			<param name="dllname" value="${rawdllname}"/>
			<param name="libs" value="${rawlibs}"/>
			<param name="objdir" location="raw"/>
		</antcall>
    </target>
</project>

