<?xml version="1.0"?>

<project name="lwjgl native code, native code" basedir="../../bin/lwjgl" default="compile">
	<property name="native" location="../../src/native"/>
	<property environment="env"/>
	<property name="mingwprefix" location="x86_64-pc-mingw32-"/>
	<property name="mingwhome" location="c:/MinGW64"/>
	<property name="strip" location="${mingwhome}/${mingwprefix}strip"/>
	<property name="gcc" location="${mingwhome}/${mingwprefix}gcc"/>
	<property name="dlltool" location="${mingwhome}/${mingwprefix}dlltool"/>
	<property name="dllname" value="lwjgl64.dll"/>

	<target name="compile_dir">
		<apply dir="." failonerror="true" executable="${gcc}" dest="." skipemptyfilesets="true">
			<arg line="-c -Wall -O2 -std=gnu99 -D_JNI_IMPLEMENTATION_"/>
			<arg value="-I${dxhome}/include"/>
			<arg value="-I${alhome}/include"/>
			<arg value="-I${jdkhome}/include"/>
			<arg value="-I${jdkhome}/include/win32"/>
			<arg value="-I${native}/common"/>
			<arg value="-I${native}/windows"/>
			<srcfile/>
			<fileset dir="${native}/windows" includes="*.c"/>
			<fileset dir="${native}/common" includes="*.c"/>
			<fileset dir="${native}/generated/openal" includes="*.c"/>
			<fileset dir="${native}/generated/opencl" includes="*.c"/>
			<fileset dir="${native}/generated/opengl" includes="*.c"/>
			<mapper type="glob" from="*.c" to="*.o"/>
		</apply>
	</target>

	<target name="link">
		<echo file="jawt.def">
			EXPORTS
			 JAWT_GetAWT
		</echo>
		<exec dir="." executable="${dlltool}" failonerror="true">
			<arg line="--def jawt.def --kill-at --dllname jawt.dll --output-lib libjawt.a"/>
		</exec>
		<apply dir="." parallel="true" executable="${gcc}" failonerror="true">
			<arg value="-Wl,--kill-at"/>
			<arg line="-shared -o ${dllname}"/>
			<srcfile/>
			<arg line="libjawt.a"/>
			<arg value="-L${java.home}/../lib"/>
			<arg value="-L${alhome}/libs"/>
			<arg line="${libs}"/>
			<fileset dir="." includes="*.o"/>
		</apply>
	</target>

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

	<target name="compile">
		<property name="libs" value="-lkernel32 -lole32 -lopengl32 -lversion -luser32 -lgdi32 -ladvapi32 -lwinmm"/>
		<antcall target="compile_dir"/>
		<antcall target="link"/>
		<apply dir="." executable="${strip}">
			<fileset file="${dllname}"/>
		</apply>
    </target>
</project>

