<?xml version="1.0"?>

<project name="lwjgl native code, linux" basedir="/dev/null" default="compile">
	<property name="libname32" value="liblwjgl.so"/>
	<property name="libname64" value="liblwjgl64.so"/>
	<property name="libs32" value="-L/usr/X11R6/lib -L/usr/X11/lib -lm -lX11 -lXext -lXcursor -lXrandr -lXxf86vm -lpthread -L${java.home}/lib -L${java.home}/lib/i386 -ljawt" />
	<property name="libs64" value="-L/usr/X11R6/lib64 -L/usr/X11/lib64 -lm -lX11 -lXext -lXcursor -lXrandr -lXxf86vm -lpthread -L${java.home}/lib -L${java.home}/lib/amd64 -ljawt" />
	<property name="cflags32" value="-O3 -Wall -c -fPIC -std=c99 -Wunused"/>

    <target name="compile">
		<exec executable="uname" outputproperty="hwplatform">
			<arg value="-m"/>
		</exec>
		<condition property="cflags_pthread" value="-pthreads" else="-pthread">
			<os name="SunOS" />
		</condition>
		<condition property="version_script_flags32" value="" else="-Wl,--version-script='${lwjgl.src.native}/linux/lwjgl.map'">
			<os name="SunOS" />
		</condition>
		<condition property="version_script_flags64" value="-m64" else="-Wl,--version-script='${lwjgl.src.native}/linux/lwjgl.map'">
			<and>
				<os name="SunOS" />
			</and>
		</condition>
    	<condition property="cflags64" value="-O3 -m64 -Wall -c -fPIC -std=c99 -Wunused" else="-O3 -Wall -c -fPIC -std=c99 -Wunused">
    		<os name="SunOS" />
    	</condition>

		<property name="linker_flags32" value="${version_script_flags32} -shared -O3 -Wall -o ${libname32} ${libs32}"/>
		<property name="linker_flags64" value="${version_script_flags64} -shared -O3 -Wall -o ${libname64} ${libs64}"/>

    	<condition property="build.32bit.only">
    		<not>
	    		<or>
					<equals arg1="${hwplatform}" arg2="x86_64"/>
					<equals arg1="${hwplatform}" arg2="i86pc"/>
				</or>
    		</not>
    	</condition>

    	<!-- On linux, the 64 bit jre doesn't have the 32 bit libs -->
    	<condition property="build.64bit.only">
    		<and>
    			<os name="Linux"/>
    			<equals arg1="${hwplatform}" arg2="x86_64"/>
    		</and>
    	</condition>

    	<antcall target="compile32"/>
    	<antcall target="compile64"/>
    </target>

    <target name="compile32" unless="build.64bit.only">
    	<mkdir dir="${lwjgl.target.gen.obj}/i386"/>
    	<apply dir="${lwjgl.target.gen.obj}/i386" executable="gcc" failonerror="true" parallel="true">
			<arg line="${cflags32} ${cflags_pthread}"/>
			<arg value="-I${java.home}/include"/>
			<arg value="-I${java.home}/include/linux"/>
			<arg value="-I${java.home}/../include"/>
			<arg value="-I${java.home}/../include/linux"/>
			<arg value="-I${java.home}/../include/solaris"/>
			<arg value="-I${lwjgl.src.native}/common"/>
		    <arg value="-I${lwjgl.src.native}/common/opengl"/>
			<arg value="-I${lwjgl.src.native}/linux"/>
		    <arg value="-I${lwjgl.src.native}/linux/opengl"/>
		    <arg value="-I${lwjgl.target.gen.headers}"/>
			<mapper type="glob" from="*.c" to="*.o"/>
		    <fileset dir="${lwjgl.src.native}/common" includes="*.c"/>
		    <fileset dir="${lwjgl.src.native}/common/opengl" includes="*.c"/>
		    <fileset dir="${lwjgl.target.gen.native}/openal" includes="*.c"/>
		    <fileset dir="${lwjgl.target.gen.native}/opencl" includes="*.c"/>
		    <fileset dir="${lwjgl.target.gen.native}/opengl" includes="*.c"/>
		    <fileset dir="${lwjgl.src.native}/linux" includes="*.c"/>
		    <fileset dir="${lwjgl.src.native}/linux/opengl" includes="*.c"/>
	    </apply>
		<apply dir="${lwjgl.target.natives}" parallel="true" executable="gcc" failonerror="true">
			<srcfile/>
			<arg line="${linker_flags32}"/>
			<fileset dir="${lwjgl.target.gen.obj}/i386" includes="*.o"/>
		</apply>
		<apply dir="${lwjgl.target.natives}" parallel="true" executable="strip" failonerror="true">
			<fileset file="${libname32}"/>
		</apply>
    </target>

    <target name="compile64" unless="build.32bit.only">
        <mkdir dir="${lwjgl.target.gen.obj}/x86_64"/>
    	<apply dir="${lwjgl.target.gen.obj}/x86_64" executable="gcc" failonerror="true" parallel="true">
			<arg line="${cflags64} ${cflags_pthread}"/>
			<arg value="-I${java.home}/include"/>
			<arg value="-I${java.home}/include/linux"/>
			<arg value="-I${java.home}/../include"/>
			<arg value="-I${java.home}/../include/linux"/>
			<arg value="-I${java.home}/../include/solaris"/>
			<arg value="-I${lwjgl.src.native}/common"/>
		    <arg value="-I${lwjgl.src.native}/common/opengl"/>
			<arg value="-I${lwjgl.src.native}/linux"/>
		    <arg value="-I${lwjgl.src.native}/linux/opengl"/>
		    <arg value="-I${lwjgl.target.gen.headers}"/>
			<mapper type="glob" from="*.c" to="*.o"/>
		    <fileset dir="${lwjgl.src.native}/common" includes="*.c"/>
		    <fileset dir="${lwjgl.src.native}/common/opengl" includes="*.c"/>
		    <fileset dir="${lwjgl.target.gen.native}/openal" includes="*.c"/>
		    <fileset dir="${lwjgl.target.gen.native}/opencl" includes="*.c"/>    		
		    <fileset dir="${lwjgl.target.gen.native}/opengl" includes="*.c"/>
		    <fileset dir="${lwjgl.src.native}/linux" includes="*.c"/>
		    <fileset dir="${lwjgl.src.native}/linux/opengl" includes="*.c"/>
	    </apply>
		<apply dir="${lwjgl.target.natives}" parallel="true" executable="gcc" failonerror="true">
			<srcfile/>
			<arg line="${linker_flags64}"/>
			<fileset dir="${lwjgl.target.gen.obj}/x86_64" includes="*.o"/>
		</apply>
		<apply dir="${lwjgl.target.natives}" parallel="true" executable="strip" failonerror="true">
			<fileset file="${lwjgl.target.natives}/${libname64}"/>
		</apply>
    </target>
</project>
