<?xml version="1.0"?>

<!-- Ant file for building native ogl renderer files for Linux/x86 -->
<project name="j3d-core native" default="compile">

  <target name="init" depends="init-cg,init-nocg">
    <!-- Create the build directories for linux -->
    <mkdir dir="${build}/${platform}/${bldType}/native/ogl/objs"/>
    <mkdir dir="${build}/${platform}/${bldType}/lib/i386"/>
    
    <property name="oglsrc"     location="${src}/native/ogl"/>
  </target>

  <target name="init-cg" if="build.cg">
    <property name="cflags.cg"  value="-DCOMPILE_CG_SHADERS=1"/>
  </target>

  <target name="init-nocg" unless="build.cg">
    <property name="cflags.cg"  value=""/>
  </target>

  <target name="compile-ogl">
    <echo message="Executing 32 bit native renderer build [${bldType}]"/>

    <!-- Compile the c source files-->
    <!-- Inhibit all warning for 32 bit build. Any warning will be caught in the 64 bit build -->
    <exec dir="${build}/${platform}/${bldType}/native/ogl/objs" executable="gcc">
	<arg line="-w -m32 -mcpu=i386 -I${oglsrc} -I${java.home}/../include -I${java.home}/../include/linux -I${javahCoreTarget} ${bldFlag} -DLINUX ${cflags.cg} -c ${oglsrc}/DrawingSurfaceObjectAWT.c ${oglsrc}/Canvas3D.c ${oglsrc}/GraphicsContext3D.c  ${oglsrc}/NativeScreenInfo.c  ${oglsrc}/NativeConfigTemplate3D.c  ${oglsrc}/MasterControl.c ${oglsrc}/GeometryArrayRetained.c  ${oglsrc}/Attributes.c  ${oglsrc}/CgShaderProgram.c  ${oglsrc}/GLSLShaderProgram.c  ${oglsrc}/Lights.c"/>
    </exec>

    <!-- Create the library file-->
    <exec dir="${build}/${platform}/${bldType}/native/ogl/objs" executable="ld">
	<arg line="DrawingSurfaceObjectAWT.o  Canvas3D.o  GraphicsContext3D.o  NativeScreenInfo.o  NativeConfigTemplate3D.o  MasterControl.o GeometryArrayRetained.o  Attributes.o  CgShaderProgram.o  GLSLShaderProgram.o  Lights.o -G -z defs -L/usr/X11R6/lib -ldl -lGL -lX11 -lXext -lm -lnsl -lc -L${java.home}/lib/i386 -ljawt -L${java.home}/lib/i386/server -ljvm  -o libj3dcore-ogl.so"/>
    </exec>

  </target>

  <target name="compile-ogl-cg" if="build.cg">
    <!-- Compile the wrapper -->
    <exec dir="${build}/${platform}/${bldType}/native/ogl/objs" executable="gcc">
	<arg line="-m32 -mcpu=i386 -I${oglsrc} -I${java.home}/../include -I${java.home}/../include/linux -I${javahCoreTarget} ${bldFlag} -DLINUX ${cflags.cg} -c ${oglsrc}/CgWrapper.c"/>
    </exec>

    <!-- Create the wrapper library -->
    <exec dir="${build}/${platform}/${bldType}/native/ogl/objs" executable="ld">
	<arg line="CgWrapper.o -G -z defs -L/usr/X11R6/lib -ldl -lCg -lCgGL -lpthread -lGL -lX11 -lXext -lm -lnsl -lc -o libj3dcore-ogl-cg.so"/>
    </exec>

  </target>

  <target name="compile" depends="init,compile-ogl,compile-ogl-cg">

    <!-- Copy the  library file -->
    <copy todir="${build}/${platform}/${bldType}/lib/i386">
          <fileset dir="${build}/${platform}/${bldType}/native/ogl/objs"
                      includes="libj3dcore-ogl*.so"
          />
    </copy>

  </target>

  <target name="dist">
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/${platform}/lib/i386"/>

    <!-- Copy the library files -->
    <copy todir="${dist}/${platform}/lib/i386">
          <fileset dir="${build}/${platform}/opt/lib/i386"
                      includes="libj3dcore-ogl*.so"
          />
    </copy>

  </target>

</project>
