<?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="sdkhome" location="${env.WindowsSdkDir}"/>

	<target name="compile_dir">
		<echo message="${compiledir}"/>
		<echo message="sdkhome: ${sdkhome}"/>
		<echo message="dxhome: ${dxhome}"/>
		<echo message="target arch: ${os.arch}"/>
		<apply dir="${compiledir}" failonerror="true" executable="cl" dest="${compiledir}" skipemptyfilesets="true">
			<arg line="/Ox /W2 /nologo /c"/>
			<arg value="/I${sdkhome}\include"/>
			<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="*.obj"/>
		</apply>
	</target>

	<!--	<target name="link" unless="nolink">-->
	<target name="link">
		<apply dir="." parallel="true" executable="cl" failonerror="true">
			<arg line="/LD /nologo"/>
			<srcfile/>
			<arg line="/Fe${dllname} /link"/>
			<arg value="/LIBPATH:${java.home}\lib"/>
			<arg value="/LIBPATH:${dxhomelib}"/>
			<arg value="/LIBPATH:${sdkhomelib}"/>
			<arg line="/DLL ${libs}"/>
			<fileset dir="${commonhome}/src/native" includes="*.obj"/>
			<fileset dir="." includes="*.obj"/>
			<fileset dir="${objdir}" includes="*.obj"/>
		</apply>
	</target>

	<target name="clean">
		<delete>
			<fileset dir="." includes="*.obj"/>
			<fileset dir="raw" includes="*.obj"/>
			<fileset dir="dx8" includes="*.obj"/>
			<fileset dir="." includes="*.dll"/>
			<fileset dir="." includes="*.exp"/>
			<fileset dir="." includes="*.lib"/>
			<fileset dir="../../../common/src/native" includes="*.obj"/>
		</delete>
	</target>

	<target name="compile">
		<property name="rawlibs" value="Kernel32.lib User32.lib Setupapi.lib"/>
		<property name="dx8libs" value="Kernel32.lib dinput8.lib dxguid.lib User32.lib"/>
		<property name="commonhome" location="../../../common"/>
		
		<condition property="dx8dllname" value="jinput-dx8.dll" else="jinput-dx8_64.dll">
			<equals arg1="${os.arch}" arg2="x86"/>
		</condition>
		<condition property="rawdllname" value="jinput-raw.dll" else="jinput-raw_64.dll">
			<equals arg1="${os.arch}" arg2="x86"/>
		</condition>
		<condition property="dxhomelib" value="${dxhome}\lib\x86" else="${dxhome}\lib\x64">
			<equals arg1="${os.arch}" arg2="x86"/>
		</condition>
		<condition property="sdkhomelib" value="${sdkhome}\lib" else="${sdkhome}\lib\x64">
			<equals arg1="${os.arch}" arg2="x86"/>
		</condition>
		<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>
		<!--		<uptodate property="nolink" targetfile="${dllname}">
			<srcfiles dir="." includes="*.obj"/>
		</uptodate>-->
		<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>

