<?xml version="1.0" ?>
<project name="OS X Plugin, Native code" basedir="." default="compileNativeJinputLib">
	<description>OSX JInput Native Plugin</description>

	<target name="init">
		<mkdir dir="ppc"/>
		<mkdir dir="i386"/>
		<mkdir dir="x86_64"/>
	</target>
	
	<target name="clean">
		<delete failonerror="false">
			<fileset dir="i386"/>
			<fileset dir="x86_64"/>
			<fileset dir="ppc"/>
			<fileset file="libjinput-osx.jnilib"/>
		</delete>
	</target>

	<target name="compile">
		<apply dir="${dstdir}" executable="${compiler}" os="Mac OS X" skipemptyfilesets="true" failonerror="true" dest="${dstdir}">
			<arg line="${cflags} -O2 -Wall -c -fPIC -I${sdkroot}/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers -I../../../../common/src/native -I.."/>
			<mapper type="glob" from="*.c" to="*.o"/>
			<fileset dir="." includes="*.c"/>
			<fileset dir="../../../common/src/native" includes="*.c"/>
		</apply>
	</target>
	
	<target name="link">
		<apply dir="${objdir}" parallel="true" executable="${linker}" os="Mac OS X" failonerror="true" skipemptyfilesets="true">
			<arg line="${linkerflags} -dynamiclib -o ${libname} -framework JavaVM -framework CoreFoundation -framework IOKit -framework CoreServices"/>
			<fileset dir="${objdir}" includes="*.o"/>
		</apply>
		<apply dir="${objdir}" executable="strip" os="Mac OS X" failonerror="true">
			<arg line="-S -X"/>
			<fileset dir="." includes="${libname}"/>
		</apply>
	</target>
	
	<target name="compileNativeJinputLib" depends="init">
		<property name="ppc_sdkroot" location="/Developer/SDKs/MacOSX10.3.9.sdk"/>
		<property name="universal_sdkroot" location="/Developer/SDKs/MacOSX10.4u.sdk"/>
		<property name="x86_64_sdkroot" location="/Developer/SDKs/MacOSX10.5.sdk"/>
		<property name="ppc_flags" value="-isysroot ${universal_sdkroot} -arch ppc -mmacosx-version-min=10.3"/>
		<property name="universal_flags" value="-isysroot ${universal_sdkroot} -arch i386 -mmacosx-version-min=10.4"/>
		<property name="x86_64_flags" value="-isysroot ${x86_64_sdkroot} -arch x86_64 -mmacosx-version-min=10.5"/>
		<antcall target="compile">
			<param name="dstdir" location="ppc"/>
			<param name="compiler" value="gcc-4.0"/>
			<param name="sdkroot" location="${universal_sdkroot}"/>
			<param name="cflags" value="${ppc_flags}"/>
		</antcall>
		<antcall target="link">
			<param name="objdir" location="ppc"/>
			<param name="libname" value="libjinput-osx-ppc.jnilib"/>
			<param name="linker" value="gcc-4.0"/>
			<param name="linkerflags" value="${ppc_flags}"/>
		</antcall>
		<antcall target="compile">
			<param name="dstdir" location="i386"/>
			<param name="compiler" value="gcc-4.0"/>
			<param name="sdkroot" location="${universal_sdkroot}"/>
			<param name="cflags" value="${universal_flags}"/>
		</antcall>
		<antcall target="link">
			<param name="objdir" location="i386"/>
			<param name="libname" value="libjinput-osx-i386.jnilib"/>
			<param name="linker" value="gcc-4.0"/>
			<param name="linkerflags" value="${universal_flags}"/>
		</antcall>
		<antcall target="compile">
			<param name="dstdir" location="x86_64"/>
			<param name="compiler" value="gcc-4.0"/>
			<param name="sdkroot" location="${x86_64_sdkroot}"/>
			<param name="cflags" value="${x86_64_flags}"/>
		</antcall>
		<antcall target="link">
			<param name="objdir" location="x86_64"/>
			<param name="libname" value="libjinput-osx-x86_64.jnilib"/>
			<param name="linker" value="gcc-4.0"/>
			<param name="linkerflags" value="${x86_64_flags}"/>
		</antcall>
		<apply dir="." parallel="true" executable="lipo" os="Mac OS X" failonerror="true" skipemptyfilesets="true" >
			<arg value="-create"/>
			<srcfile/>
			<arg value="-output"/>
			<arg path="libjinput-osx.jnilib"/>
			<fileset file="ppc/libjinput-osx-ppc.jnilib"/>
			<fileset file="i386/libjinput-osx-i386.jnilib"/>
			<fileset file="x86_64/libjinput-osx-x86_64.jnilib"/>
		</apply>
	</target>
</project>
