<project name="generator">

	<import file="build-definitions.xml"/>

	<!-- clean the generated files -->
	<target name="clean-generated" description="Deletes the generated java source">
		<delete quiet="true" failonerror="false">
			<fileset dir="${lwjgl.src}/generated" includes="**"/>
		</delete>
	</target>

    <target name="clean-generated-native" description="Deletes the generated native source" depends="clean-generated">
        <delete quiet="false" failonerror="false">
            <fileset dir="${lwjgl.src.native}/generated" includes="**"/>
        </delete>
    </target>

	<!-- Compiles the Java generator source code -->
	<target name="generators" description="Compiles the native method generators">
		<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/util/generator/**.java" source="1.5" target="1.5" taskname="generator">
            <include name="org/lwjgl/util/generator/openal/**.java"/>
            <include name="org/lwjgl/util/generator/opengl/**.java"/>
			<include name="org/lwjgl/util/generator/opengles/**.java"/>
            <include name="org/lwjgl/util/generator/opencl/**.java"/>
			<compilerarg value="-Xlint:none"/>
		</javac>
        <!-- Compile helper classes used by the templates -->
		<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" source="1.5" target="1.5" taskname="generator">
            <include name="org/lwjgl/PointerWrapper.java"/>
            <include name="org/lwjgl/PointerBuffer.java"/>
            <!-- OpenGL -->
			<include name="org/lwjgl/opengl/GLSync.java"/>
            <include name="org/lwjgl/opengl/AMDDebugOutputCallback.java"/>
            <include name="org/lwjgl/opengl/ARBDebugOutputCallback.java"/>
			<include name="org/lwjgl/opengl/KHRDebugCallback.java"/>
			<!-- OpenGL ES -->
			<include name="org/lwjgl/opengles/EGLImageOES.java"/>
			<include name="org/lwjgl/opengles/KHRDebugCallback.java"/>
            <!-- OpenCL -->
            <include name="org/lwjgl/opencl/CLPlatform.java"/>
            <include name="org/lwjgl/opencl/CLDevice.java"/>
            <include name="org/lwjgl/opencl/CLContext.java"/>
            <include name="org/lwjgl/opencl/CLCommandQueue.java"/>
            <include name="org/lwjgl/opencl/CLMem.java"/>
			<include name="org/lwjgl/opencl/CL*Callback.java"/>
            <include name="org/lwjgl/opencl/CLNativeKernel.java"/>
            <include name="org/lwjgl/opencl/CLFunctionAddress.java"/>
		</javac>
	</target>

	<!-- Proxy target to generate it all -->
	<target name="generate-all" depends="generate-openal, generate-opengl, generate-opengl-capabilities, generate-opengl-references,  generate-opengles, generate-opengles-capabilities, generate-opencl, generate-opencl-capabilities" description="Generates java and native source"/>

	<target name="generate-debug" depends="generate-openal-debug, generate-opengl-debug, generate-opengl-capabilities-debug, generate-opengl-references, generate-opengles-debug, generate-opengles-capabilities-debug, generate-opencl-debug, generate-opencl-capabilities-debug" description="Generates java and native source with debug functionality"/>

	<!-- ********************************************************************************
		*********************************************************************************
											OPENAL
		*********************************************************************************
		****************************************************************************  -->
    <property name="java.home" value="${env.JAVA_HOME}" />
	<!-- Generate OpenAL -->
	<target name="generate-openal" depends="generators" description="Generates java and native source for AL">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.al}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<arg value="-d"/>
			<arg path="${lwjgl.src.native}/generated/openal"/>
			<arg value="-Abinpath=${lwjgl.bin}"/>
			<arg value="-Atypemap=org.lwjgl.util.generator.openal.ALTypeMap"/>
			<fileset dir="${lwjgl.src.templates.al}" includes="${openal-template-pattern}"/>
		</apply>
	</target>

	<!-- Generate OpenAL [DEBUG] -->
	<target name="generate-openal-debug" depends="generators" description="Generates java and native source for AL">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.al}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<arg value="-d"/>
			<arg path="${lwjgl.src.native}/generated/openal"/>
			<arg value="-Abinpath=${lwjgl.bin}"/>
			<arg value="-Atypemap=org.lwjgl.util.generator.openal.ALTypeMap"/>
			<arg value="-Ageneratechecks"/>
			<fileset dir="${lwjgl.src.templates.al}" includes="${openal-template-pattern}"/>
		</apply>
	</target>

	<!-- ********************************************************************************
		*********************************************************************************
										OPENGL
		*********************************************************************************
		****************************************************************************  -->

	<!-- Generate OpenGL -->
	<target name="generate-opengl" depends="generators" description="Generates java and native source for GL">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.gl}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<arg value="-d"/>
			<arg path="${lwjgl.src.native}/generated/opengl"/>
			<arg value="-Abinpath=${lwjgl.bin}"/>
			<arg value="-Acontextspecific"/>
			<arg value="-Atypemap=org.lwjgl.util.generator.opengl.GLTypeMap"/>
			<fileset dir="${lwjgl.src.templates.gl}" includes="${opengl-template-pattern}"/>
		</apply>
	</target>

	<!-- Generate OpenGL [DEBUG] -->
	<target name="generate-opengl-debug" depends="generators" description="Generates debug java and native source for GL">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.gl}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<arg value="-d"/>
			<arg path="${lwjgl.src.native}/generated/opengl"/>
			<arg value="-Abinpath=${lwjgl.bin}"/>
			<arg value="-Ageneratechecks"/>
			<arg value="-Acontextspecific"/>
			<arg value="-Atypemap=org.lwjgl.util.generator.opengl.GLTypeMap"/>
			<fileset dir="${lwjgl.src.templates.gl}" includes="${opengl-template-pattern}"/>
		</apply>
	</target>

	<!-- Generate OpenGL references -->
	<target name="generate-opengl-references" depends="generators" description="Generates java and native source for GL">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.gl}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.opengl.GLReferencesGeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<fileset dir="${lwjgl.src.templates.gl}" includes="${opengl-template-pattern}"/>
		</apply>
	</target>

	<!-- Generate OpenGL context capabilities -->
	<target name="generate-opengl-capabilities" depends="generators" description="Generates java and native source for GL">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.gl}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.opengl.GLGeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<arg value="-Acontextspecific"/>
			<fileset dir="${lwjgl.src.templates.gl}" includes="${opengl-template-pattern}"/>
		</apply>
	</target>

	<!-- Generate OpenGL context capabilities [DEBUG] -->
	<target name="generate-opengl-capabilities-debug" depends="generators" description="Generates debug java and native source for GL">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.gl}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.opengl.GLGeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<arg value="-Ageneratechecks"/>
			<arg value="-Acontextspecific"/>
			<fileset dir="${lwjgl.src.templates.gl}" includes="${opengl-template-pattern}"/>
		</apply>
	</target>

	<!-- ********************************************************************************
		*********************************************************************************
											OPENGL ES
		*********************************************************************************
		****************************************************************************  -->

	<!-- Generate OpenGL ES -->
	<target name="generate-opengles" depends="generators" description="Generates java and native source for GL ES">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.gles}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<arg value="-d"/>
			<arg path="${lwjgl.src.native}/generated/opengles"/>
			<arg value="-Abinpath=${lwjgl.bin}"/>
			<!--<arg value="-Acontextspecific"/>-->
			<arg value="-Atypemap=org.lwjgl.util.generator.opengl.GLESTypeMap"/>
			<fileset dir="${lwjgl.src.templates.gles}" includes="${opengles-template-pattern}"/>
		</apply>
	</target>

	<!-- Generate OpenGL ES [DEBUG] -->
	<target name="generate-opengles-debug" depends="generators" description="Generates debug java and native source for GL ES">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.gles}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<arg value="-d"/>
			<arg path="${lwjgl.src.native}/generated/opengles"/>
			<arg value="-Abinpath=${lwjgl.bin}"/>
			<arg value="-Ageneratechecks"/>
			<!--<arg value="-Acontextspecific"/>-->
			<arg value="-Atypemap=org.lwjgl.util.generator.opengl.GLESTypeMap"/>
			<fileset dir="${lwjgl.src.templates.gles}" includes="${opengles-template-pattern}"/>
		</apply>
	</target>

	<!-- Generate OpenGL ES context capabilities -->
	<target name="generate-opengles-capabilities" depends="generators" description="Generates java and native source for GL ES">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.gles}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.opengl.GLESGeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<!--<arg value="-Acontextspecific"/>-->
			<fileset dir="${lwjgl.src.templates.gles}" includes="${opengles-template-pattern}"/>
		</apply>
	</target>

	<!-- Generate OpenGL ES context capabilities [DEBUG] -->
	<target name="generate-opengles-capabilities-debug" depends="generators" description="Generates debug java and native source for GL ES">
		<apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.gles}" relative="true">
			<arg value="-nocompile"/>
			<arg value="-factory"/>
			<arg value="org.lwjgl.util.generator.opengl.GLESGeneratorProcessorFactory"/>
			<arg value="-cp"/>
			<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
			<arg value="-s"/>
			<arg path="${lwjgl.src}/generated"/>
			<arg value="-Ageneratechecks"/>
			<!--<arg value="-Acontextspecific"/>-->
			<fileset dir="${lwjgl.src.templates.gles}" includes="${opengles-template-pattern}"/>
		</apply>
	</target>

	<!-- ********************************************************************************
		*********************************************************************************
											OPENCL
		*********************************************************************************
		****************************************************************************  -->

	<!-- Generate OpenCL -->
    <target name="generate-opencl" depends="generators" description="Generates java and native source for CL">
        <apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.cl}" relative="true">
            <arg value="-nocompile"/>
            <arg value="-factory"/>
            <arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
            <arg value="-cp"/>
            <arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
            <arg value="-s"/>
            <arg path="${lwjgl.src}/generated"/>
            <arg value="-d"/>
            <arg path="${lwjgl.src.native}/generated/opencl"/>
	        <arg value="-Abinpath=${lwjgl.bin}"/>
            <arg value="-Acontextspecific"/>
            <arg value="-Atypemap=org.lwjgl.util.generator.opencl.CLTypeMap"/>
            <fileset dir="${lwjgl.src.templates.cl}" includes="${opencl-template-pattern}"/>
        </apply>
    </target>

    <!-- Generate OpenCL [DEBUG] -->
    <target name="generate-opencl-debug" depends="generators" description="Generates debug java and native source for CL">
        <apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.cl}" relative="true">
            <arg value="-nocompile"/>
            <arg value="-factory"/>
            <arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
            <arg value="-cp"/>
            <arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
            <arg value="-s"/>
            <arg path="${lwjgl.src}/generated"/>
            <arg value="-d"/>
            <arg path="${lwjgl.src.native}/generated/opencl"/>
	        <arg value="-Abinpath=${lwjgl.bin}"/>
            <arg value="-Ageneratechecks"/>
            <arg value="-Acontextspecific"/>
            <arg value="-Atypemap=org.lwjgl.util.generator.opencl.CLTypeMap"/>
            <fileset dir="${lwjgl.src.templates.cl}" includes="${opencl-template-pattern}"/>
        </apply>
    </target>

    <!-- Generate OpenCL capabilities -->
    <target name="generate-opencl-capabilities" depends="generators" description="Generates capabilities for CL">
        <apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.cl}" relative="true">
            <arg value="-nocompile"/>
            <arg value="-factory"/>
            <arg value="org.lwjgl.util.generator.opencl.CLGeneratorProcessorFactory"/>
            <arg value="-cp"/>
            <arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
            <arg value="-s"/>
            <arg path="${lwjgl.src}/generated"/>
            <arg value="-Acontextspecific"/>
            <fileset dir="${lwjgl.src.templates.cl}" includes="${opencl-template-pattern}"/>
        </apply>
    </target>

    <!-- Generate OpenCL capabilities [DEBUG] -->
    <target name="generate-opencl-capabilities-debug" depends="generators" description="Generates debug capabilities for CL">
        <apply executable="${java.home}/../bin/apt" parallel="true" dir="${lwjgl.src.templates.cl}" relative="true">
            <arg value="-nocompile"/>
            <arg value="-factory"/>
            <arg value="org.lwjgl.util.generator.opencl.CLGeneratorProcessorFactory"/>
            <arg value="-cp"/>
            <arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
            <arg value="-s"/>
            <arg path="${lwjgl.src}/generated"/>
            <arg value="-Ageneratechecks"/>
            <arg value="-Acontextspecific"/>
            <fileset dir="${lwjgl.src.templates.cl}" includes="${opencl-template-pattern}"/>
        </apply>
    </target>
</project>
