dnl Process this file with autoconf to produce a configure script.
dnl This autoconf script is free software; the Free Software Foundation
dnl gives unlimited permission to copy, distribute and modify it.

AC_INIT(src/Scene.h)
AC_CONFIG_HEADER(src/config.h)

OS=`uname`

dnl fix unix filepermissions first
echo fix unix filepermissions
sh batch/fixpermissions.sh

OLD_CFLAGS="$CFLAGS"
OLD_CXXFLAGS="$CXXFLAGS"

dnl Check for compiler programs

AC_PROG_CC
AC_PROG_CXX
AC_PROG_CXXCPP

dnl fix wrong "-g -O2" flags settings by some autoconf versions when
dnl detecting gcc/g++

if test "$CFLAGS" != "$OLD_CFLAGS"; then
 CFLAGS="$OLD_CFLAGS"
 echo reseting CFLAGS to $CFLAGS
fi
if test "$CXXFLAGS" != "OLD_CXXFLAGS"; then
 CXXFLAGS="$OLD_CXXFLAGS"
 echo reseting CXXFLAGS to $CXXFLAGS
fi


dnl Warn about defect compilers

if test "X_$OS" = "X_Linux" ; then
 echo xxxxxxxxx Warning xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 echo problems with the buggy Redhat/SuSE Linux \"gcc 2.96\" compiler '?' Use
 echo  
 echo  rm -f config.cache
 echo  sh ./configure --with-kgcc
 echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
fi

dnl Checks for special options.

AC_ARG_WITH(oldmotif,--with-oldmotif           used for compatibility with old motif/lesstif versions,
            AC_DEFINE(HAVE_OLD_MOTIF))

AC_ARG_WITH(olpc,--with-olpc               used for compatibility with the one laptop per child computer,
            HAVE_OLPC=1;CPPFLAGS="$CPPFLAGS -I/usr/local/include/freetype2";export CPPFLAGS;EXTRA_LIBS="-lselinux -lpthread";export EXTRA_LIBS;OPTIM="$OPTIM -O3 -mmmx -m3dnow -ffast-math";export OPTIM;AC_DEFINE(HAVE_OLPC))

if test "X_$OPTIM" = "X_" ;then
   OPTIM=-g
fi
AC_ARG_WITH(optimization,--with-optimization       optimize for speed,
            OPTIM=-O2;export OPTIM)

LIBS="$LIBS $EXTRA_LIBS"
export LIBS

AC_ARG_WITH(iconscale2,--with-iconscale2         used to scale major icons by factor 2,
            AC_DEFINE(HAVE_ICON_SCALE_2))

AC_ARG_WITH(devil,--without-devil 	  do not use DevIL library to load textureimages ,
            DEVIL=no)

AC_ARG_WITH(png_handle_unknown,--without-png_handle_unknown  use if link fails cause of png_handle_unknown,
            AC_DEFINE(HAVE_NO_PNG_HANDLE_UNKNOWN))

AC_ARG_WITH(sdljoystick,--without-sdljoystick 	  do not use SDL joystick code,
            SDL_JOYSTICK=no)

AC_ARG_WITH(helpurl,--with-helpurl=\"helpurl\"  URL of the \"docs\" directory,
            HELPURL="$withval";export HELPURL)
if test "X_$HELPURL" != "X_" ; then
   AC_DEFINE_UNQUOTED(HAVE_HELP_URL,"${HELPURL}")
else 
   if test -d docs ; then
      AC_DEFINE_UNQUOTED(HAVE_HELP_URL,"${PWD}/docs")
   fi
fi

AC_ARG_WITH(vrmlnodesurl,--with-vrmlnodesurl=\"vrmlnodesurl\" URL of ISO standard vrml97 node list e.g. downloaded version of  http://www.web3d.org/x3d/specifications/vrml/ISO-IEC-14772-VRML97/part1/nodesRef.html,
            VRMLNODESURL="$withval";export VRMLNODESURL)
if test "X_$VRMLNODESURL" != "X_" ; then
   AC_DEFINE_UNQUOTED(HAVE_VRML_NODES_URL,"${VRMLNODESURL}")
fi

AC_ARG_WITH(x3durl,--with-x3durl=\"x3durl\" URL of ISO standard X3D e.g. downloaded version of http://www.web3d.org/x3d/specifications/ISO-IEC-19775-1.2-X3D-AbstractSpecification/,
            X3DURL="$withval";export X3DURL)
if test "X_$X3DURL" != "X_" ; then
   AC_DEFINE_UNQUOTED(HAVE_X3D_URL,"${X3DURL}")
fi

AC_ARG_WITH(protobaseurl, --with-protobaseurl=\"url\" URL of base directory of PROTOs for needed EXTERNPROTO statements,
            PROTO_BASE_URL="$withval";export PROTO_BASE_URL)

VRML97_AMENDMENT1=vrml97Amendment1
X3D=x3d
SCRIPTED_NODES=scripted_Nodes
COVER_NODES=coverNodes
EXPORT_CONTAINER=exportContainers

for i in VRML97_AMENDMENT1 X3D SCRIPTED_NODES COVER_NODES EXPORT_CONTAINER; do
   x=`eval echo '$'"$i"`
   if test "X_$PROTO_BASE_URL" != "X_"; then
      url=HAVE_''$i''_PROTO_URL
      AC_DEFINE_UNQUOTED($url,"$PROTO_BASE_URL/$x")
   else
      if test -d docs/$x ; then
         url=HAVE_''$i''_PROTO_URL
         AC_DEFINE_UNQUOTED($url,"${PWD}/docs/$x")
      fi
   fi
done

AC_ARG_WITH(coverwave,--with-coverwave          allow creation of deprecated cover node Wave,
            AC_DEFINE(HAVE_COVER_WAVE))

AC_ARG_WITH(covertuimap,--with-covertuimap        allow creation of incomplete cover node TUIMap,
            AC_DEFINE(HAVE_COVER_TUI_MAP))

AC_ARG_WITH(wwwbrowser,--with-wwwbrowser=wwwbrowser  webbrowser eg. netscape firefox mozilla...,
            WWWBROWSER="$withval";export WWWBROWSER)

AC_ARG_WITH(vrmlbrowser,--with-vrmlbrowser=vrmlbrowser  VRML browser eg. netscape freewrl lookat...,
            VRMLBROWSER="$withval";export VRMLBROWSER)

KNOWN_IMAGE_EDITORS="gimp imgworks krita kolourpaint xpaint gpaint"
AC_ARG_WITH(imageeditor,--with-imageeditor=imageeditor  object editor for bitmap (.jpg/.png/.gif) files eg. gimp krita xpaint imgworks...,
            IMAGEEDITOR="$withval";export IMAGEEDITOR)

KNOWN_IMAGE_EDITORS_4KIDS="imgworks kolourpaint gpaint krita xpaint gimp"
AC_ARG_WITH(imageeditor4kids,--with-imageeditor4kids=imageeditor  simple object editor for bitmap (.jpg/.png/.gif) files usefull for kids eg. kolourpaint gpaint...,
            IMAGEEDITOR4KIDS="$withval";export IMAGEEDITOR4KIDS)

KNOWN_SOUND_EDITORS="audacity rezound wavesurfer gnusound sweep soundeditor"
AC_ARG_WITH(soundeditor,--with-soundeditor=soundeditor  object editor for sound (.wav) files eg. audacity rezound wavesurfer gnusound sweep soundeditor...,
            SOUNDEDITOR="$withval";export SOUNDEDITOR)

KNOWN_MOVIE_EDITORS="cinelerra avidemux2 avidemux moviemaker"
AC_ARG_WITH(movieeditor,--with-movieeditor=movieeditor  object editor for movie (.mpeg) files eg. cinelerra avidemux2 avidemux moviemaker...,
            MOVIEEDITOR="$withval";export MOVIEEDITOR)

AC_ARG_WITH(checkincommand,--with-checkincommand=checkincommand  default check in command of a revision control system,
            CHECK_IN_COMMAND="$withval";export CHECK_IN_COMMAND)

KNOWN_IMAGE_CONVERTERS="convert"
AC_ARG_WITH(imageconverter,--with-imageconverter=imageconverter  converter for bitmap (.jpg/.png/.gif) files to bmp files for ac3d export...,
            IMAGECONVERTER="$withval";export IMAGECONVERTER)

AC_ARG_WITH(usrlocalinclude,--without-usrlocalinclude  use when the compiler refuse -I/usr/local/include ,
            USRLOCALINCLUDE=no)

AC_ARG_WITH(kgcc,--with-kgcc 	 	  use to avoid the buggy Redhat/SuSE Linux \"gcc 2.96\",
            CC=kgcc;export CC)

AC_ARG_WITH(eulerrotation,--with-eulerrotation      use for euler angles instead of VRML like rotations,
            AC_DEFINE(HAVE_EULER_ROT))

AC_ARG_WITH(routeatend,--with-routeatend         write route statement at end into file,
            AC_DEFINE(HAVE_ROUTE_AT_END))

AC_ARG_WITH(uninstallcomment, --with-uninstallcomment=\"uninstallcomment\"  use to document a uninstall command,
            UNINSTALL_COMMENT="$withval";export UNINSTALL_COMMENT)
if test "X_$UNINSTALL_COMMENT" != "X_" ; then
   AC_DEFINE_UNQUOTED(HAVE_UNINSTALL_COMMENT,"${UNINSTALL_COMMENT}")
else
   AC_DEFINE_UNQUOTED(HAVE_UNINSTALL_COMMENT,"no information how to uninstall white_dune: possibly it has been installed from source")
fi

AC_ARG_WITH(xj3drigidbodyphysicscomponent,--with-xj3drigidbodyphysicscomponent  use special component name xj3d_RigidBodyPhysics,
            AC_DEFINE(HAVE_XJ3D_RIGID_BODY_PHYSICS_COMPONENT))


AC_ARG_WITH(dontreplacevrmlscript,--with-dontreplacevrmlscript  do not replace vrmlscript: with javascript:,
            AC_DEFINE(HAVE_DONT_REPLACE_VRMLSCRIPT))

AC_ARG_WITH(stereo,--without-stereo 	  use if you do not have shutterglases,
            AC_DEFINE(HAVE_NO_STEREO))

AC_ARG_WITH(stereocommand,--with-stereocommand=\"stereocommand\"   how to switch to stereomode (e.g. \"/usr/gfx/setmon -n 1024x768_96s\" on some SGI IRIX systems),
            STEREOCOMMAND="$withval";export STEREOCOMMAND)
if test "X_$STEREOCOMMAND" != "X_" ;then
   AC_DEFINE_UNQUOTED(HAVE_STEREOCOMMAND,"${STEREOCOMMAND}")
fi

AC_ARG_WITH(updatedebug,--with-updatedebug        use debug messages for updates between views,
            AC_DEFINE(HAVE_UPDATE_DEBUG))

AC_ARG_WITH(aflockdebug,--with-aflockdebug        use debug messages for Ascention Flock of birds,
            AC_DEFINE(HAVE_AFLOCK_DEBUG))

AC_ARG_WITH(coredump,--with-coredump 	  switch off emergencysave signalhandling,
            AC_DEFINE(HAVE_WANT_CORE))

unset TEST_FPU_INTERRUPTS
AC_ARG_WITH(fpuinterrupts,--with-fpuinterrupts      switch on interrupts on invalid fpu operations,
            export TEST_FPU_INTERRUPTS="yes")
if test "X_$TEST_FPU_INTERRUPTS" != "X_" ; then
   AC_MSG_CHECKING(for _FPU_SETCW)
   AC_TRY_COMPILE(
                  [
                    #include "fpu_control.h"
                  ],
                  [
                    unsigned int cw;_FPU_SETCW(cw);
                  ],
                  echo yes;AC_DEFINE(HAVE_FPU_SETCW),echo no
                 )
  AC_CHECK_LIB(fpe,handle_sigfpes)
  AC_CHECK_FUNCS(handle_sigfpes)
fi

AC_ARG_WITH(efence,--with-efence 	          use the efence malloc debugging routines,
            HAVE_WANT_EFENCE="yes")

AC_ARG_WITH(duma,--with-duma               use the duma malloc debugging routines,
            HAVE_WANT_DUMA="yes")

AC_ARG_WITH(gif,--without-gif             avoid code to render gif textures,
            HAVE_WANT_GIF=no)

if test "X_$HAVE_WANT_GIF" != "X_no" ; then
  GIF=gif.o
  AC_SUBST(GIF)
  AC_DEFINE(HAVE_GIF)
fi

AC_ARG_WITH(usb,--without-usb             avoid code to use libusb/NXT inputdevice,
            HAVE_WANT_USB=no)

AC_ARG_WITH(teachermenu,--with-teachermenu        add a extra submenu useful for teaching things,
            AC_DEFINE(HAVE_TEACHER_MENU))

AC_ARG_WITH(testinmenu,--with-testinmenu         insert a extra menupoint for testing of developers,
            AC_DEFINE(HAVE_TEST_IN_MENU))

AC_ARG_WITH(cut,--with-cut                currently you better use copy/paste/delete instead...,
            AC_DEFINE(HAVE_CUT))

AC_ARG_WITH(textedit,--without-textedit        disable file -> textedit cause it would do not return,
            AC_DEFINE(HAVE_NO_TEXTEDIT))

AC_ARG_WITH(nebula,--with-nebula 	          use if you want to convert to The Nebula Device,
            NEBULA=nebula/ExportNebula.o;export NEBULA;AC_DEFINE(HAVE_SAND))
AC_SUBST(NEBULA)

AC_ARG_WITH(textureimagemode,--with-textureimagemode   use nonstandard mode field in TextureImage node,
            AC_DEFINE(HAVE_TEXTUREIMAGE_MODE))

AC_ARG_WITH(optbigfiles,--without-optbigfiles     do not optimize compiling of big files ,
            OPT_BIG_FILES=no)
if test "X_$OPT_BIG_FILES" = "X_no" ;then
    OPTIM=-O2
    OPTBIG=-g
else
    OPTBIG=$OPTIM        
fi
AC_SUBST(OPTIM)
AC_SUBST(OPTBIG)

AC_ARG_WITH(gprof,--with-gprof              compile with support for the gprof analyser,
            OPTIM="-pg -DNDEBUG=1";export OPTIM;AC_DEFINE(HAVE_WANT_CORE))
AC_SUBST(OPTIM)

if test "X_$STATIC" = "X_" ;then
   STATIC=""
fi

OBJS='$(OBJS)'
AC_ARG_WITH(archives,--with-archives           link via archives,
            OBJS='$(ARCHIVES)')
export OBJS
AC_SUBST(OBJS)

AC_ARG_WITH(static,--with-static             link with the -static option,
            STATIC=-static;export STATIC)
AC_SUBST(STATIC)

AC_ARG_WITH(ranlib,--without-ranlib          avoid the usage of the ranlib command,
            AVOID_RANLIB="yes")

AC_ARG_WITH(ode,--with-ode                check for ODE library (code is in early development),
            WITH_ODE="yes")

AC_ARG_WITH(osmesa,--with-osmesa 	          use mesa off screen rendering (avoid with real OpenGL),
            HAVE_WANT_OSMESA="yes")

dnl Checks for programs.

AC_PROG_AWK
AC_PROG_YACC
if test "X_$YACC" = "X_yacc" ; then
    WARNING_YACC="Warning: not all versions of yacc will work, you better use bison instead"
    echo $WARNING_YACC 1>&2    
fi
AC_PROG_LEX
if test "X_$LEX" = "X_lex" ; then
    WARNING_LEX="Warning: not all versions of lex will work, you better use flex instead"
    echo $WARNING_LEX 1>&2    
fi
RC_YACC=$YACC
export RC_YACC
AC_SUBST(RC_YACC)

dnl use --nounistd when $LEX is flex
NOUNISTD=""
if test "X_$LEX" = "X_flex" ; then
   AC_MSG_CHECKING(for flex --nounistd option)
   if flex --help 2>&1 | grep '\--nounistd' > /dev/null ; then
       echo yes
       NOUNISTD="--nounistd"
   else
       echo no
   fi
fi
export NOUNISTD
AC_SUBST(NOUNISTD)

dnl test for egrep compatibility problems when filtering flex/lex output
EGREP_PROBLEMS="yes" 
AC_MSG_CHECKING(for specific egrep pattern compatibility)
ONE=`echo '#include <unistd.h>' | egrep '#include *.unistd\.h.' | wc -l`
if test "X_$ONE" = "X_1" ; then
   echo yes
   EGREP_PROBLEMS="no"
else
   echo no
fi
export EGREP_PROBLEMS
AC_SUBST(EGREP_PROBLEMS)

dnl check for webbrowsers
if test "X_$WWWBROWSER" = "X_" ; then
   AC_PATH_PROGS(WWWBROWSER,[x-www-browser iceweasel firefox phoenix galeon firebird opera mozilla seamonkey lynx links netscape])
fi

if test "X_$WWWBROWSER" = "X_" ; then
   WWWBROWSER=firefox
else 
  dnl handle commandline browsers

  dnl add your favorite xterm replacement here...
  AC_PATH_PROGS(XTERM,[xterm rxvt eterm])
  
  if test "X_$XTERM" != "X_" ; then
      XTERM="$XTERM -e"
   fi

  if test "X_`basename \"$WWWBROWSER\"`" = "X_lynx" ; then
     WWWBROWSER="$XTERM $WWWBROWSER" 
  else 
     if test "X_`basename \"$WWWBROWSER\"`" = "X_links" ; then
        WWWBROWSER="$XTERM $WWWBROWSER" 
     fi
  fi
fi

dnl check for object editors
if test "X_$IMAGEEDITOR" = "X_" ; then
   AC_PATH_PROGS(IMAGEEDITOR,[$KNOWN_IMAGE_EDITORS])
fi
AC_DEFINE_UNQUOTED(HAVE_IMAGE_EDITOR,"${IMAGEEDITOR}")

dnl check for object editors
if test "X_$IMAGEEDITOR4KIDS" = "X_" ; then
   AC_PATH_PROGS(IMAGEEDITOR4KIDS,[$KNOWN_IMAGE_EDITORS_4KIDS])
fi
AC_DEFINE_UNQUOTED(HAVE_IMAGE_EDITOR4KIDS,"${IMAGEEDITOR4KIDS}")


if test "X_$SOUNDEDITOR" = "X_" ; then
   AC_PATH_PROGS(SOUNDEDITOR,[$KNOWN_SOUND_EDITORS])
fi
AC_DEFINE_UNQUOTED(HAVE_SOUND_EDITOR,"${SOUNDEDITOR}")

if test "X_$MOVIEEDITOR" = "X_" ; then
   AC_PATH_PROGS(MOVIEEDITOR,[$KNOWN_MOVIE_EDITORS])
fi
AC_DEFINE_UNQUOTED(HAVE_MOVIE_EDITOR,"${MOVIEEDITOR}")

if test "X_$CHECK_IN_COMMAND" = "X_" ; then
   AC_PATH_PROGS(CHECK_IN_COMMAND,[ci])
fi
if test "X_$CHECK_IN_COMMAND" != "X_" ; then
   if test "X_`basename $CHECK_IN_COMMAND`" = "X_ci" ; then
      CHECK_IN_COMMAND="ci -l -q -f %s < /dev/null"
      echo using ${CHECK_IN_COMMAND} as revision control checkin command
   fi
   AC_DEFINE_UNQUOTED(HAVE_CHECK_IN_COMMAND, "${CHECK_IN_COMMAND}")
fi

if test "X_$IMAGECONVERTER" = "X_" ; then
   AC_PATH_PROGS(IMAGECONVERTER,[$KNOWN_IMAGE_CONVERTERS])
fi
AC_DEFINE_UNQUOTED(HAVE_IMAGE_CONVERTER,"${IMAGECONVERTER}")

AC_DEFINE_UNQUOTED(HAVE_X3DV_TO_X3D_COMMAND, "")

SDL_JOYSTICK_BSD="no"
SDL_JOYSTICK_LINUX="no"
SDL_JOYSTICK_MACOSX="yes"

dnl check for operation system dependend things
AC_PATH_XTRA

LD_OPTIONS=
COMMONFLAGS=
PARSER_CPP_CFLAG=
export PARSER_CPP_CFLAG
if test "X_$OS" = "X_Linux" ; then
    CPPFLAGS="$CPPFLAGS $X_CFLAGS -I/usr/X11R6/include/ -I/usr/X11R6/LessTif/Motif1.2/include"
    LIBS="$LIBS -L/usr/local/lib $X_LIBS -L/usr/X11R6/LessTif/Motif1.2/lib"
    SDL_JOYSTICK_LINUX="yes"
elif test "X_$OS" = "X_IRIX" ; then
    LD_OPTIONS="-n32"
    CPPFLAGS="$CPPFLAGS -I/usr/freeware/include $X_CFLAGS"
    LIBS="$LIBS -L/usr/local/lib32 -L/usr/freeware/lib32 -L/usr/lib32 $X_LIBS"

    dnl check for cosmoplayer
    if test -f "/var/netscape/communicator/plugins/libcosmoplayer.so" ; then
       VRMLBROWSER=netscape
       echo using netscape as default VRML browser on SGI IRIX
    fi
    if test -f "/var/netscape/communicator/plugins32/libcosmoplayer.so" ; then
       VRMLBROWSER=netscape
       echo using netscape as default VRML browser on SGI IRIX
    fi
elif test "X_$OS" = "X_IRIX64" ; then
    if test "`echo $CC | grep 64`" = "" ; then
       CPPFLAGS="$CPPFLAGS -I/usr/freeware/include $X_CFLAGS"
       LIBS="$LIBS -L/usr/local/lib32 -L/usr/freeware/lib32 -L/usr/lib32 $X_LIBS"
    else
       CPPFLAGS="$CPPFLAGS -I/usr/freeware/include $X_CFLAGS"
       LIBS="$LIBS -L/usr/local/lib64 -L/usr/freeware/lib64 -L/usr/lib64 $X_LIBS"
    fi

    if test "X_$VRMLBROWSER" = "X_" ; then
       dnl check for cosmoplayer
       if test -f "/var/netscape/communicator/plugins/libcosmoplayer.so" ; then
          VRMLBROWSER=netscape
       fi
       if test -f "/var/netscape/communicator/plugins32/libcosmoplayer.so" ; then
          VRMLBROWSER=netscape
       fi
    fi
elif test "X_$OS" = "X_SunOS" ; then
    LIBS="$LDFLAGS $LIBS $X_LIBS"
    export LIBS
    PARSER_CPP_CFLAG=-U__GNUC_MINOR__
    export PARSER_CPP_CFLAG
    # some solaris sfw bison crash on src/swt/rcparser.y 
    RC_YACC=yacc
    export RC_YACC
    AC_SUBST(RC_YACC)
elif test "X_$OS" = "X_Darwin" ; then
    MACOSX=`sw_vers | awk '/ProductVersion:/ {split($2,a,".");print a[[1]] "." a[[2]]}'`
    MACSDK=MacOSX""$MACOSX""u.sdk
    if test "X_$MACOSX" = "X_10.6" ; then
        dnl yet another workaround for MacOSX 10.6 "snowleopard"
        FAT_COMMONFLAGS="-I/usr/include -arch i386 -arch ppc -arch x86_64"
        FAT_LIBS=" -flat_namespace -Wl,-syslibroot,/Developer/SDKs/$MACSDK -arch ppc -arch i386 -arch x86_64 -Wl,-multiply_defined,warning"
        CPPFLAGS="$CPPFLAGS $X_CFLAGS -I/usr/X11R6/include -DMACOSX=1"
        LIBS="$FAT_LIBS $LIBS $X_LIBS -L/usr/X11R6/lib -multiply_defined warning -lXft -lXrender -lfontconfig"
        COMMONFLAGS="$FAT_COMMONFLAGS"
    else
        CPPFLAGS="$CPPFLAGS $X_CFLAGS -I/usr/X11R6/include -DMACOSX=1"
        dnl fat binaries options
        dnl
        if test "X_$MACOSX" = "X_10.5" ; then
            FAT_COMMONFLAGS="-arch i386 -arch ppc"
        else
            FAT_COMMONFLAGS="-isysroot /Developer/SDKs/$MACSDK -arch i386 -arch ppc"
        fi
        FAT_LIBS=" -flat_namespace -Wl,-syslibroot,/Developer/SDKs/$MACSDK -arch ppc -arch i386 -Wl,-multiply_defined,warning"
        dnl
        COMMONFLAGS="$FAT_COMMONFLAGS"
        dnl -force_flat_namespace as workaround for defect XFree86 4.2 compile
        dnl LIBS="$FAT_LIBS $LIBS $X_LIBS -force_flat_namespace -lXft"
        dnl known to work in MacOSX 10.4.2 "tiger"
        LIBS="$FAT_LIBS $LIBS $X_LIBS -multiply_defined warning -lXft -lXrender -lfontconfig"
        if test "X_$MACOSX" = "X_10.5" ; then
           dnl yet another workaround for MacOSX 10.5 "leopard"
           LIBS="$LIBS -dylib_file /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"
        fi
        LIBS="-L/usr/X11R6/lib $LIBS "
    fi
    dnl check for Firefox or Internet explorer (cortona VRML browser)
    if test -d "/Applications/Firefox.app" ; then
       WWWBROWSER="/usr/bin/open -a \\\"/Applications/Firefox.app\\\""
       VRMLBROWSER="/usr/bin/open -a \\\"/Applications/Firefox.app\\\""
    else
       if test -d "/Applications/Internet Explorer.app" ; then
          if test "X_$WWWBROWSER" = "X_" ; then
             WWWBROWSER="/usr/bin/open -a \\\"/Applications/Internet Explorer.app\\\""
          fi
          if test "X_$VRMLBROWSER" = "X_" ; then
             VRMLBROWSER="/usr/bin/open -a \\\"/Applications/Internet Explorer.app\\\""
          fi
       fi
    fi
    (DUNE=$PWD/bin/dune && cd desktop/macosx/white_dune.app/Contents/MacOS && rm -f dune && ln -s $DUNE .) 
    if test -d "/Applications/X11.app" ; then    
       if test -x "/usr/bin/open" ; then    
          AC_DEFINE_UNQUOTED(HAVE_X11STARTCOMMAND,"/usr/bin/open -a /Applications/X11.app/Contents/MacOS/X11")
       else
          AC_DEFINE_UNQUOTED(HAVE_X11STARTCOMMAND,"/Applications/X11.app/Contents/MacOS/X11")
       fi
    else 
       if test -d "/Applications/Utilities/X11.app" ; then
          if test -x "/usr/bin/open" ; then    
             AC_DEFINE_UNQUOTED(HAVE_X11STARTCOMMAND,"/usr/bin/open -a /Applications/Utilities/X11.app/Contents/MacOS/X11")
          else
             AC_DEFINE_UNQUOTED(HAVE_X11STARTCOMMAND,"/Applications/Utilities/X11.app/Contents/MacOS/X11")
          fi
       else 
          if test -f "/usr/X11R6/bin/X" ; then
             AC_DEFINE_UNQUOTED(HAVE_X11STARTCOMMAND,"/usr/X11R6/bin/X")
          else
             AC_DEFINE_UNQUOTED(HAVE_X11STARTCOMMAND,"X")
          fi
       fi
    fi     
    if test "X_$SDL_JOYSTICK_MACOSX" = "X_yes" ; then
       if test "X_$MACOSX" = "X_10.6" ; then
          dnl yet another workaround for MacOSX 10.6 "snowleopard"
          SYSTEM_LIBS="$SYSTEM_LIBS -lIOKit"   
       else
          SYSTEM_LIBS="$SYSTEM_LIBS -framework IOKit"   
       fi
       LIBS="$LIBS $SYSTEM_LIBS"
       SDL_JOYSTICK_SUBDIR="darwin"
       SDL_JOYSTICK_LIBS="SDLjoystick/libSDLjoystick.a"
    fi   
elif test "X_$OS" = "X_NetBSD" ; then
    CPPFLAGS="$CPPFLAGS $X_CFLAGS"
    LIBS="$LIBS $X_LIBS"
    SDL_JOYSTICK_BSD="yes"
elif test "X_$OS" = "X_OpenBSD" ; then
    CPPFLAGS="$CPPFLAGS $X_CFLAGS"
    LIBS="$LIBS $X_LIBS"
    SDL_JOYSTICK_BSD="yes"
    CPPFLAGS="$CPPFLAGS -I/usr/local/include/libpng"
elif test "X_$OS" = "X_FreeBSD" ; then
    CPPFLAGS="$CPPFLAGS $X_CFLAGS"
    LIBS="$LIBS $X_LIBS -lXft"
    SDL_JOYSTICK_BSD="yes"
elif test "X_$OS" = "X_AIX" ; then
    CPPFLAGS="$CPPFLAGS -DAIX=1"
    export CPPFLAGS
elif test "X_$OS" = "X_HP-UX" ; then
    CPPFLAGS="$CPPFLAGS -I/usr/contrib/X11R6/include -I/opt/graphics/OpenGL/include -I/usr/include/Motif2.1"
    export CPPFLAGS
    LDFLAGS="$LDFLAGS -L/opt/graphics/OpenGL/lib -L/usr/lib/Motif2.1 -L/usr/contrib/X11R6/lib"
    export LDFLAGS
elif test "X_$OS" = "X_OSF1"; then
    LDFLAGS="$LDFLAGS -lrt"
fi
export LD_OPTIONS
AC_SUBST(LD_OPTIONS)
export PARSER_CPP_FLAG
AC_SUBST(PARSER_CPP_CFLAG)
export CPPFLAGS
AC_SUBST(CPPFLAGS)
export COMMONFLAGS
AC_SUBST(COMMONFLAGS)
export CFLAGS
AC_SUBST(CFLAGS)
export CXXFLAGS
AC_SUBST(CXXFLAGS)

if test "X_$CC" != "X_" ; then
    AC_MSG_CHECKING($CC support -I/usr/local/include)
    cat > /tmp/_white_dune_test_$$.c << EOF
    int main(int argc, char** argv)
        {
        return 0;
        }
EOF
    if test "X_$USRLOCALINCLUDE" != "X_no" ;then 
        if $CC -I/usr/local/include -c -o /tmp/_white_dune_test_$$.o /tmp/_white_dune_test_$$.c ; then
           CPPFLAGS="$CPPFLAGS -I/usr/local/include"
           LDFLAGS="$LDFLAGS -L/usr/local/lib"
           echo yes
        else 
           echo no
        fi
        rm -f /tmp/_white_dune_test_$$.c
        rm -f /tmp/_white_dune_test_$$.o
    fi
fi

if test "X_$VRMLBROWSER" = "X_" ;then
   dnl check for known vrmlbrowsers
   AC_PATH_PROGS(VRMLBROWSER,[/opt/instantReality/bin/InstantPlayer /Applications/FreeWRL/FreeWRL.app/Contents/MacOS/FreeWRL freewrl cc3dglut xj3d vrwave lookat])
fi

if test "X_$VRMLBROWSER" = "X_" ;then
   if test "X_$WWWBROWSER" != "X_" ;then
      VRMLBROWSER=$WWWBROWSER
   fi 
fi

NETSCAPE_OPENURL=FALSE
if test  "`basename \"$WWWBROWSER\"`" = "netscape" ; then
   NETSCAPE_OPENURL=TRUE
fi
if test  "`basename \"$WWWBROWSER\"`" = "mozilla" ; then
   NETSCAPE_OPENURL=TRUE
fi
if test  "`basename \"$WWWBROWSER\"`" = "firefox" ; then
   NETSCAPE_OPENURL=TRUE
fi
if test  "`basename \"$WWWBROWSER\"`" = "seamonkey" ; then
   NETSCAPE_OPENURL=TRUE
fi
if test  "`basename \"$WWWBROWSER\"`" = "galeon" ; then
   NETSCAPE_OPENURL=TRUE
fi

if test  "X_$NETSCAPE_OPENURL" = "X_TRUE" ; then
   VRMLREMOTEBROWSER="$WWWBROWSER -remote OpenURL\\\\(%s\\\\)"
else
   if test "X_$VRMLBROWSER" != "X_" ;then
      VRMLREMOTEBROWSER="$VRMLBROWSER %s"
   fi
fi
AC_DEFINE_UNQUOTED(HAVE_VRML_REMOTE_BROWSER,"${VRMLREMOTEBROWSER}")

if test "X_$VRMLBROWSER" != "X_" ;then
   AC_DEFINE_UNQUOTED(HAVE_VRML_BROWSER,"${VRMLBROWSER} %s")
fi

NETSCAPE_OPENURL=FALSE
if test  "`basename \"$WWWBROWSER\"`" = "netscape" ; then
   NETSCAPE_OPENURL=TRUE
fi
if test  "`basename \"$WWWBROWSER\"`" = "mozilla" ; then
   NETSCAPE_OPENURL=TRUE
fi
if test  "`basename \"$WWWBROWSER\"`" = "phoenix" ; then
   NETSCAPE_OPENURL=TRUE
fi
if test  "`basename \"$WWWBROWSER\"`" = "galeon" ; then
   NETSCAPE_OPENURL=TRUE
fi

if test  "X_$NETSCAPE_OPENURL" = "X_TRUE" ; then
   WWWREMOTEBROWSER="$WWWBROWSER -remote OpenURL\\\\(%s\\\\)"
else
   if test "X_$WWWBROWSER" != "X_" ;then
      WWWREMOTEBROWSER="$WWWBROWSER %s &"
   fi
fi
AC_DEFINE_UNQUOTED(HAVE_WWW_BROWSER,"${WWWREMOTEBROWSER}")

if test "X_$AVOID_RANLIB" = "X_yes" ; then
   RANLIB=echo
   export RANLIB 
else
   AC_PATH_PROGS(RANLIB,ranlib,echo)
fi

if test "X_$SDL_JOYSTICK" != "X_no" ; then

   if test "X_$SDL_JOYSTICK_LINUX" = "X_yes" ; then
      dnl from configure.in of SDL for joystick
      dnl Check for Linux 2.4 unified input event interface support
      AC_ARG_ENABLE(input-events,
           [  --enable-input-events   use Linux 2.4 unified input interface [default=yes]],
                     , enable_input_events=yes)
       if true; then
           AC_MSG_CHECKING(for Linux 2.4 unified input interface)
           use_input_events=no
           AC_TRY_COMPILE([
             #include <linux/input.h>
           ],[
             #ifndef EVIOCGNAME
             #error EVIOCGNAME() ioctl not available
             #endif
           ],[
           use_input_events=yes
           ])
           AC_MSG_RESULT($use_input_events)
           if test x$use_input_events = xyes; then
               SDLCFLAGS="-DUSE_INPUT_EVENTS"
               SDL_JOYSTICK_SUBDIR="linux"
               SDL_JOYSTICK_LIBS="SDLjoystick/libSDLjoystick.a"
           fi
       fi
   fi
   
   if test "X_$SDL_JOYSTICK_BSD" = "X_yes" ; then
      dnl from configure.in of SDL for joystick
      dnl Check for the usbhid(3) library on *BSD
      if true ; then
           have_libusbhid=no
           have_libusb=no
           AC_CHECK_LIB(usbhid, hid_init, have_libusbhid=yes)
           AC_CHECK_LIB(usb, hid_init, have_libusb=yes)
           if test x$have_libusbhid = xyes; then
               SYSTEM_LIBS="$SYSTEM_LIBS -lusbhid"
           fi
           if test x$have_libusb = xyes; then
               SYSTEM_LIBS="$SYSTEM_LIBS -lusb"
           fi
   
           AC_CHECK_HEADER(usb.h, have_usb_h=yes)
           AC_CHECK_HEADER(usbhid.h, have_usbhid_h=yes)
           AC_CHECK_HEADER(libusb.h, have_libusb_h=yes)
           AC_CHECK_HEADER(libusbhid.h, have_libusbhid_h=yes)
           if test x$have_usb_h = xyes; then
               SDLCFLAGS="$SDLCFLAGS -DHAVE_USB_H"
               LIBS="$LIBS $SYSTEM_LIBS"
               SDL_JOYSTICK_SUBDIR="bsd"
               SDL_JOYSTICK_LIBS="SDLjoystick/libSDLjoystick.a"
           fi
           if test x$have_usbhid_h = xyes; then
               SDLCFLAGS="$SDLCFLAGS -DHAVE_USBHID_H"
               LIBS="$LIBS $SYSTEM_LIBS"
               SDL_JOYSTICK_SUBDIR="bsd"
               SDL_JOYSTICK_LIBS="SDLjoystick/libSDLjoystick.a"
           fi
           if test x$have_libusb_h = xyes; then
               SDLCFLAGS="$SDLCFLAGS -DHAVE_LIBUSB_H"
               LIBS="$LIBS $SYSTEM_LIBS"
               SDL_JOYSTICK_SUBDIR="bsd"
               SDL_JOYSTICK_LIBS="SDLjoystick/libSDLjoystick.a"
           fi
           if test x$have_libusbhid_h = xyes; then
               SDLCFLAGS="$SDLCFLAGS -DHAVE_LIBUSBHID_H"
               LIBS="$LIBS $SYSTEM_LIBS"
               SDL_JOYSTICK_SUBDIR="bsd"
               SDL_JOYSTICK_LIBS="SDLjoystick/libSDLjoystick.a"
           fi
   
           AC_MSG_CHECKING(for usbhid)
           have_usbhid=no
           AC_TRY_COMPILE([
             #include <sys/types.h>
             #if defined(HAVE_USB_H)
             #include <usb.h>
             #endif
             #include <dev/usb/usb.h>
             #include <dev/usb/usbhid.h>
             #if defined(HAVE_USBHID_H)
             #include <usbhid.h>
             #elif defined(HAVE_LIBUSB_H)
             #include <libusb.h>
             #elif defined(HAVE_LIBUSBHID_H)
             #include <libusbhid.h>
             #endif
           ],[
             struct report_desc *repdesc;
             struct usb_ctl_report *repbuf;
             hid_kind_t hidkind;
           ],[
           have_usbhid=yes
           ])
           AC_MSG_RESULT($have_usbhid)
   
           if test x$have_usbhid = xyes; then
               AC_MSG_CHECKING(for ucr_data member of usb_ctl_report)
               have_usbhid_ucr_data=no
               AC_TRY_COMPILE([
                 #include <sys/types.h>
                 #if defined(HAVE_USB_H)
                 #include <usb.h>
                 #endif
                 #include <dev/usb/usb.h>
                 #include <dev/usb/usbhid.h>
                 #if defined(HAVE_USBHID_H)
                 #include <usbhid.h>
                 #elif defined(HAVE_LIBUSB_H)
                 #include <libusb.h>
                 #elif defined(HAVE_LIBUSBHID_H)
                 #include <libusbhid.h>
                 #endif
               ],[
                 struct usb_ctl_report buf;
                 if (buf.ucr_data) { }
               ],[
               have_usbhid_ucr_data=yes
               ])
               if test x$have_usbhid_ucr_data = xyes; then
                   SDLCFLAGS="$SDLCFLAGS -DUSBHID_UCR_DATA"
                   LIBS="$LIBS $SYSTEM_LIBS"
                   SDL_JOYSTICK_SUBDIR="bsd"
                   SDL_JOYSTICK_LIBS="SDLjoystick/libSDLjoystick.a"
               fi
               AC_MSG_RESULT($have_usbhid_ucr_data)
               
   	    AC_MSG_CHECKING(for new usbhid API)
               have_usbhid_new=no
               AC_TRY_COMPILE([
                 #include <sys/types.h>
                 #if defined(HAVE_USB_H)
                 #include <usb.h>
                 #endif
                 #include <dev/usb/usb.h>
                 #include <dev/usb/usbhid.h>
                 #if defined(HAVE_USBHID_H)
                 #include <usbhid.h>
                 #elif defined(HAVE_LIBUSB_H)
                 #include <libusb.h>
                 #elif defined(HAVE_LIBUSBHID_H)
                 #include <libusbhid.h>
                 #endif
               ],[
                 report_desc_t d;
   	      hid_start_parse(d, 1, 1);
               ],[
               have_usbhid_new=yes
               ])
               if test x$have_usbhid_new = xyes; then
                   SDLCFLAGS="$SDLCFLAGS -DUSBHID_NEW"
                   LIBS="$LIBS $SYSTEM_LIBS"
                   SDL_JOYSTICK_SUBDIR="bsd"
                   SDL_JOYSTICK_LIBS="SDLjoystick/libSDLjoystick.a"
               fi
               AC_MSG_RESULT($have_usbhid_new)
           fi
       fi
   fi
   
   AC_SUBST(SDLCFLAGS)
   AC_SUBST(SDL_JOYSTICK_SUBDIR)
   AC_SUBST(SDL_JOYSTICK_LIBS)
   
   if test "X_$SDL_JOYSTICK_SUBDIR" != "X_" ; then
      AC_DEFINE(HAVE_SDL_JOYSTICK)    
   fi
fi

LDFLAGS="$LDFLAGS $OPTIM"
export LDFLAGS

dnl extend CC with $CPPFLAGS for tests 

OLD_CC=$CC
CC="$CC $CPPFLAGS"
export CC


dnl Checks for header files.

AC_HEADER_STDC
AC_CHECK_HEADER(stdarg.h, AC_DEFINE(HAVE_STDARG_H))
AC_CHECK_HEADER(varargs.h, AC_DEFINE(HAVE_VARARGS_H))

AC_CHECK_HEADER(Xm/Xm.h, , MOTIF_ERROR=1)

if test "X_$MOTIF_ERROR" = "X_1" ; then
[ 
cat 1>&2 << EOF

 *** couldn't find Motif/Lesstif develop file ***

 This package will not compile without a Motif/Lesstif devel package.  
 If Motif is not available, or too bloody expensive, you can use LessTif, 
 which is available open source from:

	http://www.lesstif.org/download.html

EOF
 exit 1
]
fi

AC_CHECK_HEADER(X11/Xlib.h,,X11_ERROR=1)
AC_CHECK_HEADER(X11/keysym.h,,X11_ERROR=1)
AC_CHECK_HEADER(X11/cursorfont.h,,X11_ERROR=1)
AC_CHECK_HEADER(X11/Intrinsic.h,,X11_ERROR=1)
AC_CHECK_HEADER(X11/IntrinsicP.h,,X11_ERROR=1)

if test "X_$X11_ERROR" = "X_1" ; then
[
 cat 1>&2 << EOF

 *** couldn't find basic X11 develop file ***

 This package will not compile without serveral X11 library headers

EOF
 exit 1
]
fi

dnl Checks for libraries.
AC_HAVE_LIBRARY(dl)
if test "X_$NEBULA" != "X_" ;then
   AC_HAVE_LIBRARY(stlport_gcc)
fi
AC_CHECK_FUNCS(atexit)
AC_CHECK_FUNCS(_exit)
AC_CHECK_FUNCS(snprintf)
AC_CHECK_FUNCS(gettimeofday)
AC_CHECK_LIB(m, sin)
AC_CHECK_FUNCS(powf)
AC_CHECK_FUNCS(powl)
AC_CHECK_FUNCS(rint)
if test "X_$WITH_ODE" = "X_yes" ; then
   AC_CHECK_LIB(ode, dWorldCreate)
fi
AC_CHECK_LIB(X11, XCreateWindow)
AC_CHECK_LIB(Xmu, XmuLookupStandardColormap)
AC_CHECK_LIB(Xt, XtCreateWidget)
AC_CHECK_LIB(Xext, XShmQueryVersion)
AC_HAVE_LIBRARY(Xp)
AC_CHECK_LIB(Xm, XmCreateMainWindow , , MOTIF_ERROR=1)
if test "X_$MOTIF_ERROR" = "X_1" ; then
[ 
cat 1>&2 << EOF

 *** couldn't find a working Motif/Lesstif development system ***
 
 This package will not compile without a working Motif/Lesstif development 
 system.
 
 Inspect the config.log file to find out, what part of the Motif/Lesstif X11 
 development system is not available/working.

 If Motif or OpenMotif is not available, or too expensive, you can use LessTif, 
 which is available open source from:

	http://www.lesstif.org/download.html

EOF
 exit 1
]
fi
if test "X_$OS" = "X_SunOS" ; then
 dnl Warn about known problematic LessTif implementations
 if (pkginfo | grep LessTif) ; then
  echo xxxxxxxxx Warning xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  echo Solaris can deliver a doubtfull version of LessTif in /opt/sfw/LessTif 
  echo e.g. 0.92.26
  echo  
  echo if you click to a icon, but get no reaction, temporary deinstall 
  echo the LessTif package and install a modern version of LessTif 
  echo or use:
  echo 
  echo rm -f config.cache
  echo  sh ./configure --with-buginlesstif 
  echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 fi
fi
AC_CHECK_HEADER(X11/extensions/XInput.h, AC_DEFINE(HAVE_XINPUT))
AC_CHECK_LIB(Xi, XOpenDevice)

AC_CHECK_HEADER(GL/gl.h,,GL_ERROR=1)
AC_CHECK_HEADER(GL/glu.h,,GLU_ERROR=1)

if test "X_$GLU_ERROR" = "X_1" ; then
   echo "GLU Library header (part of OpenGL/Mesa) not found"
   GL_ERROR=1
fi

if test "X_$GL_ERROR" = "X_1" ; then
[
 cat 1>&2 << EOF

 *** couldn't find OpenGL develop file ***

 This package will not compile without OpenGL.  If your OS does not
 support it natively you can use Mesa, the open source OpenGL workalike.
 Mesa is available for download from:

	http://www.mesa3d.org/download.html

EOF
 exit 1
]
fi

AC_CHECK_LIB(GL, glBegin , , GL_ERROR=1)
if test "X_$GL_ERROR" = "X_1" ; then
   AC_CHECK_LIB(MesaGL, glBegin , GL_ERROR=0)
fi
AC_CHECK_FUNCS(glVertex3f)
AC_CHECK_FUNCS(glDeleteTextures)
AC_CHECK_FUNCS(glGenTextures)
AC_CHECK_FUNCS(glBindTexture)
AC_CHECK_LIB(GLU, gluProject , , GLU_ERROR=1)
if test "X_$GLU_ERROR" = "X_1" ; then
   AC_CHECK_LIB(MesaGLU, gluProject , GLU_ERROR=0)
fi

if test "X_$GLU_ERROR" = "X_1" ; then
   echo "GLU library (part of OpenGL/Mesa) problem"
   GL_ERROR=1
fi

if test "X_$GL_ERROR" = "X_1" ; then
[
 cat 1>&2 << EOF

 *** OpenGL library problem ***

 This package will not compile without a working OpenGL development system.  

 Inspect the config.log file to find out, what part of the OpenGL
 development system is not available/working.

 If your OS does not support it natively you can use Mesa, the open source 
 OpenGL workalike. 
 Mesa is available for download from:

	http://www.mesa3d.org/download.html

EOF
 exit 1
]
fi

AC_CHECK_FUNCS(gluNewTess)

AC_MSG_CHECKING(for _GLUfuncptr)
AC_TRY_LINK(
            [
              #include "GL/gl.h"
              #include "GL/glu.h"
              static void Callback(GLenum type, void *data)
                 {}
              void test_GLUfuncptr(void) {
                   GLUtesselator *tess=0;
                   gluTessCallback(tess, GLU_TESS_BEGIN_DATA, 
		                   (_GLUfuncptr)0);
					   
                   }
            ],
            [
             /* dummy */
            ],
            echo  yes;AC_DEFINE(HAVE_GLU_FUNC_PTR),
            echo  no
           )

dnl check for Mesa Off Screen rendering

if test "X_$HAVE_WANT_OSMESA" = "yes" ; then
   AC_CHECK_LIB(OSMesa,OSMesaMakeCurrent)
   AC_CHECK_FUNCS(OSMesaCreateContext)
   AC_CHECK_FUNCS(OSMesaCreateContextExt)
fi

dnl use prefined libraries for libexpat
AC_CHECK_LIB(expat, XML_ParserCreate, ,EXPAT_ERROR=1)
if test "X_$EXPAT_ERROR" = "X_1" ; then
   cat 1>&2 << EOF

*** couldn't find matching libexpat version, libexpat 2.0.1 would work ***

Couldn't find libexpat, the XML parsing C library.
This is not a fatal error; the package will be simply built without
the possiblity to read XML encoded X3D files (ISO/IEC 19776-1).  
It is recommended to add it, download and install it from:

	http://expat.sourceforge.net

and re-run configure.

EOF
   EXPAT_WARNING="no usable expat library: no parsing of XML encoded X3D (ISO/IEC 19776-1)"
fi


dnl use prefined libraries for libz, libpng, libjpeg 
if test "X_$LIBS_Z_PNG_JPEG" != "X_" ; then
   AC_DEFINE(HAVE_LIBPNG)
   AC_DEFINE(HAVE_LIBZ)
   AC_DEFINE(HAVE_LIBJPEG)
   LIBS="$LIBS_Z_PNG_JPEG $LIBS"    
else
   AC_CHECK_LIB(z, gzopen, , ZLIB_ERROR=1)
   if test "X_$ZLIB_ERROR" = "X_1" ; then
      cat 1>&2 << EOF

*** couldn't find working zlib (==libz) version, zlib 1.1.3 would work ***

Couldn't find zlib(==libz) develop package.
zlib/libz is a library for lossless data-compression.
This is not a fatal error; the package will be simply built without
support to open gz compressed VRML files. Some versions of the png library 
also need zlib for linking.
It is recommended to add it, download and install it from:

	http://www.gzip.org/zlib/

and re-run configure.

EOF
      ZLIB_WARNING="no usable zlib (==libz) library: no reading of compressed VRML files, possibly no rendering of png textures"
   fi

   if test "X_$HAVE_OLPC" = "X_1" ; then
      AC_CHECK_LIB(expat, XML_ExpatVersion)
      AC_CHECK_LIB(freetype, FT_Library_Version)
      AC_CHECK_LIB(fontconfig, FcGetVersion)
      AC_CHECK_LIB(Xrender, XRenderQueryVersion)
      AC_CHECK_LIB(Xft, XftGetVersion)
   fi

   if test "X_$DEVIL" != "X_no" ; then
 
      AC_CHECK_LIB(IL, ilInit , , HAVE_IL=no)

      if test "X_$HAVE_IL" != "X_no" ; then
         AC_CHECK_LIB(ILU, iluInit , , HAVE_ILU=no)
         if test "X_$HAVE_ILU" != "X_no" ; then
            HAVE_ILU=yes
         fi
      fi
   fi

   if test "X_$HAVE_ILU" != "X_yes" ; then

      AC_CHECK_LIB(jpeg, jpeg_start_decompress, ,JPEG_ERROR=1)
      if test "X_$JPEG_ERROR" = "X_1" ; then
         cat 1>&2 << EOF

*** couldn't find matching libjpeg version, libjpeg-6b would work ***

Couldn't find libjpeg, the Indepedent JPEG group's jpeg library.
This is not a fatal error; the package will be simply built without
jpeg support.  It is recommended to add it, download and install it from:

	http://www.ijg.org/
	ftp://ftp.uu.net/graphics/jpeg/

and re-run configure.

EOF
         JPEG_WARNING="no usable jpeg library: no rendering of jpg textures"
      fi

      AC_CHECK_LIB(png, png_get_IHDR, ,PNG_ERROR=1)
      if test "X_$PNG_ERROR" = "X_1" ; then
         cat 1>&2 << EOF

*** couldn't find matching libpng version, libpng-1.06 would work ***

Couldn't find libpng, the Portable Network Graphics library.
This is not a fatal error; the package will be simply built without
png support.  It is recommended to add it, download and install it from:

	http://www.libpng.org/pub/png/

and re-run configure.

EOF
         PNG_WARNING="no usable libpng library: no rendering of png textures"
      fi
   fi
fi

AC_MSG_CHECKING(for png_handle_unknown linking)
AC_TRY_LINK(
            [
              #include "png.h"
              #include <setjmp.h>
              void png_handle_unknown PNGARG((png_structp png_ptr,
                    png_infop info_ptr, png_uint_32 length)) 
                    { longjmp(NULL, 0); }
            ],
            [
             /* dummy */
            ],
            echo  yes,
            echo  no;AC_DEFINE(HAVE_NO_PNG_HANDLE_UNKNOWN)
           )

AC_CHECK_HEADER(linux/joystick.h,AC_DEFINE(LINUX_JOYSTICK))
AC_CHECK_HEADER(sball.h, SBALL_HEADER=yes;export SBALL_HEADER)
if test "X_$SBALL_HEADER" = "X_yes" ; then
 AC_CHECK_LIB(sball, sball_open)
fi
if test "X_$HAVE_WANT_USB" != "X_no" ; then
 AC_CHECK_LIB(usb, usb_init)
fi

if test "X_$HAVE_WANT_EFENCE" = "X_yes" ; then
   AC_CHECK_LIB(efence, Page_AllowAccess)
fi

if test "X_$HAVE_WANT_DUMA" = "X_yes" ; then
   // duma usually use the pthread library
   AC_CHECK_LIB(pthread, pthread_start_thread)
   AC_CHECK_LIB(duma, Page_AllowAccess)
fi

dnl check for signal_handler(int);

AC_MSG_CHECKING(for signal_handler(int))
cat > /tmp/test_$$.cpp << EOT
#include <signal.h>
   void signal_fatal_handler(int sign){}
   int main(int argc,char** argv) {signal(1,&signal_fatal_handler);return 0;}
EOT
$CXX -o /tmp/a_$$.out /tmp/test_$$.cpp 2>/dev/null > /dev/null
RET=$?
if test "X_$RET" = "X_0" ;then
  AC_DEFINE(HAVE_SIGNAL_INT)
  echo yes
else
  echo no
fi
rm -f /tmp/a_$$.out /tmp/test_$$.cpp

dnl check for typename 

AC_MSG_CHECKING(for typename)
cat > /tmp/test_$$.cpp << EOT
template <class c> class a { typedef typename c::d e;};
EOT
$CXX -c -o /tmp/a_$$.out /tmp/test_$$.cpp 2>/dev/null > /dev/null
RET=$?
if test "X_$RET" = "X_0" ;then
  AC_DEFINE(HAVE_TYPENAME)
  echo yes
else
  echo no
fi
rm -f /tmp/a_$$.out /tmp/test_$$.cpp

dnl check if -fpermissive is needed for g++
if test "X_"`echo $CXX|awk '{print $1}'` = "X_g++" ; then

   AC_MSG_CHECKING(for g++ -fpermissive)
   cat > /tmp/test_$$.cpp << EOT
   #include <stddef.h>

   class test {};

   test *ptr = NULL;
EOT
   $CXX -c -o /tmp/a_$$.out /tmp/test_$$.cpp 2>/dev/null > /dev/null
   RET=$?
   if test "X_$RET" = "X_0" ;then
      echo not needed
   else
      echo yes
      CXXFLAGS="$CXXFLAGS -fpermissive"
   fi
   rm -f /tmp/a_$$.out /tmp/test_$$.cpp
fi

AC_MSG_CHECKING(for -std=c99)
cat > /tmp/test_$$.c << EOT
int main(int argc, char** argv) {return 0;}
EOT
$CC -std=c99 -c -o /tmp/test_$$.o /tmp/test_$$.c 2>/dev/null > /dev/null
RET=$?
if test "X_$RET" = "X_0" ;then
  C99="-std=c99"
  AC_SUBST(C99)
  echo yes
else
  echo no
fi
rm -f /tmp/test_$$.o /tmp/test_$$.c

AC_MSG_CHECKING(for fpclassify)
AC_TRY_LINK(
               [
                 #include "math.h"
               ],
               [
                 int result = fpclassify(1);
               ],
               echo yes;AC_DEFINE(HAVE_FPCLASSIFY),echo no;TEST_XOPEN_SOURCE=yes
               )

if test "$TEST_XOPEN_SOURCE" = yes ; then
   AC_MSG_CHECKING(for _XOPEN_SOURCE 600 for fpclassify)
   AC_TRY_LINK(
               [
                 #define _XOPEN_SOURCE 600
                 #include "math.h"
               ],
               [
                 int result = fpclassify(1);
               ],
               echo yes;AC_DEFINE(HAVE_XOPEN_SOURCE_4_FPCLASSIFY),echo no
               )
fi

AC_MSG_CHECKING(for isless)
AC_TRY_LINK(
               [
                 #include "math.h"
               ],
               [
                 int result = isless(0.0,1.1);
               ],
               echo yes;AC_DEFINE(HAVE_ISLESS),echo no
               )

AC_MSG_CHECKING(for termios.c_ospeed)
cat > /tmp/test_$$.cpp << EOT
#include <termios.h>
   void test(void) {struct termios t;t.c_ospeed=B19200}
EOT
$CXX -o /tmp/a_$$.out /tmp/test_$$.cpp 2>/dev/null > /dev/null
RET=$?
if test "X_$RET" = "X_0" ;then
  AC_DEFINE(HAVE_C_OSPEED)
  echo yes
else
  echo no
fi
rm -f /tmp/a_$$.out /tmp/test_$$.cpp

dnl check for libefence.a

ARXSTRDUP_O="echo no way to extract strdup efence may fail in strdup"
STRDUP_O=

LIBEFENCE_A=
EFENCE_EXTRA_LIBS=
AC_MSG_CHECKING(for libefence.a location)
for i in /usr/lib32 /usr/lib /usr/local/lib32 /usr/local/lib ; do
   if test -f $i/libefence.a ; then 
       LIBEFENCE_A=$i/libefence.a
       export LIBEFENCE_A

       EFENCE_EXTRA_LIBS=-lpthread
       export EFENCE_EXTRA_LIBS
   fi
done
if test "X_$LIBEFENCE_A" != "X_" ; then 
    echo $LIBEFENCE_A
    AC_MSG_CHECKING(for strdup extraction)
    CURRENT_DIR=$PWD
    cd /tmp && 
        if ar x /usr/lib/libc.a strdup.o ;then 
           echo yes

           ARXSTRDUP_O="(cd /tmp && ar x /usr/lib/libc.a strdup.o)"
           export ARXSTRDUP_O

           STRDUP_O=/tmp/strdup.o
           export STRDUP_O

           rm -f $STRDUP_O
        else
           echo no
        fi
    cd $CURRENT_DIR
else
    echo none 
fi
AC_SUBST(LIBEFENCE_A)
AC_SUBST(EFENCE_EXTRA_LIBS)    

LIBDUMA_A=
DUMA_EXTRA_LIBS=
AC_MSG_CHECKING(for libduma.a location)
for i in /usr/lib32 /usr/lib /usr/local/lib32 /usr/local/lib ; do
   if test -f $i/libduma.a ; then 
       LIBDUMA_A=$i/libduma.a
       export LIBDUMA_A

       DUMA_EXTRA_LIBS=-lpthread
       export DUMA_EXTRA_LIBS
   fi
done
if test "X_$LIBDUMA_A" != "X_" ; then 
    echo $LIBDUMA_A
    AC_MSG_CHECKING(for strdup extraction)
    CURRENT_DIR=$PWD
    cd /tmp && 
        if ar x /usr/lib/libc.a strdup.o ;then 
           echo yes

           ARXSTRDUP_O="(cd /tmp && ar x /usr/lib/libc.a strdup.o)"
           export ARXSTRDUP_O

           STRDUP_O=/tmp/strdup.o
           export STRDUP_O

           rm -f $STRDUP_O
        else
           echo no
        fi
    cd $CURRENT_DIR    
else
    echo none 
fi
AC_SUBST(LIBDUMA_A)
AC_SUBST(DUMA_EXTRA_LIBS)    

AC_SUBST(ARXSTRDUP_O)
AC_SUBST(STRDUP_O)

dnl build version number

DUNE_VERSION="white_dune `batch/getversion.sh`"
AC_DEFINE_UNQUOTED(HAVE_DUNE_VERSION,"${DUNE_VERSION}")

dnl automatic generate functions/lists for VRML types (e.g. SFBool <=> SFBOOL)

sh batch/mkSFMFTypes.sh

dnl CC="$OLD_CC"
dnl export CC

AC_LANG_CPLUSPLUS

AC_MSG_CHECKING(for new handler)
AC_TRY_COMPILE(
                  [
                    #include <new.h>
                  ],
                  [
                    void handler(void);
                    set_new_handler(handler);
                  ],
                  echo yes;AC_DEFINE(HAVE_NEW_HANDLER),echo no
                 )

AC_MSG_CHECKING(for new new handler)
AC_TRY_COMPILE(
                  [
                    #include <new>
                    void handler(void);
                  ],
                  [
                    std::set_new_handler(handler);
                  ],
                  echo yes;AC_DEFINE(HAVE_NEW_NEW_HANDLER),echo no
                 )

CC="$OLD_CC"
export CC

dnl generate command to generate dune.rc file from dune.*.rc files
RCFILE_FIRST=dune.english.rc
RCFILE_REST=`cd src && ls dune.*.rc | grep -v $RCFILE_FIRST | xargs echo` 
RESOURCE_FILES="$RCFILE_FIRST $RCFILE_REST"
AC_SUBST(RESOURCE_FILES)

dnl generate command to test icon size
AC_PATH_PROGS(BMPTOPNM,[bmptopnm])
if test "X_$BMPTOPNM" = "X_" ; then
   echo "unable to test for icon size without bmptopnm (harmless)" 1>&2
   TESTICONSIZE="@echo no bmptopnm: can not compare iconsize of "
   TESTICONSIZE2="@echo no bmptopnm: can not compare iconsize of "
else
   TESTICONSIZE="../batch/testiconsize.sh $BMPTOPNM"
   TESTICONSIZE2="../batch/testiconsize2.sh $BMPTOPNM"
fi
AC_SUBST(TESTICONSIZE)
AC_SUBST(TESTICONSIZE2)

AC_PATH_PROGS(IMAGECONVERTER,[convert])
if test "X_$IMAGECONVERTER" = "X_" ; then
   echo "unable to convert textures to bmp for ac3d export" 1>&2
fi
AC_SUBST(IMAGECONVERTER)

AC_PATH_PROGS(JAVAC,javac,echo)
AC_SUBST(JAVAC)
if test "X_$JAVAC" = "X_" ; then
    JAVA="echo"
else
    AC_PATH_PROGS(JAVA,java,echo)
fi
AC_SUBST(JAVA)

LIBS="$LIBS $EXTRA_LIBS"

AC_OUTPUT(src/Makefile src/swt/motif/Makefile \
          src/swt/tests/Makefile src/swt/rc/Makefile\
          src/SDLjoystick/Makefile test/Makefile \
          docs/export_example_c/Makefile \
          docs/export_example_c++/Makefile \
          docs/export_example_java/Makefile )

(cd src && make resource.h)

(cd src/swt/motif && make $DUNEMAKEFLAGS depend)
(cd src && make $DUNEMAKEFLAGS depend)

if test "X_" != "X_$SDL_JOYSTICK_SUBDIR" ; then
   (cd src/SDLjoystick && make $DUNEMAKEFLAGS depend)
fi

(cd src/SDLjoystick && touch SDL_error.h)   
(cd src/SDLjoystick && touch SDL_joystick_c.h)

dnl repeat warnings at end

if test "X_$WARNING_LEX" != "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo " " $WARNING_LEX 1>&2
else
    touch src/lexer.l src/swt/rc/rclex.l
fi

if test "X_$WARNING_YACC" != "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo " " $WARNING_YACC 1>&2
else
    touch src/parser.y src/swt/rc/rcparse.y
fi

if test "X_$XLSFONTS_WARNING" != "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo " " $XLSFONTS_WARNING 1>&2
fi

if test "X_$GLUT_WARNING" != "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo " " $GLUT_WARNING 1>&2
fi

if test "X_$ZLIB_WARNING" != "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo " " $ZLIB_WARNING 1>&2
fi

if test "X_$PNG_WARNING" != "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo " " $PNG_WARNING 1>&2
fi

if test "X_$JPEG_WARNING" != "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo " " $JPEG_WARNING 1>&2
fi

if test "X_$EXPAT_WARNING" != "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo " " $EXPAT_WARNING 1>&2
fi

if test "X_$IMAGEEDITOR" = "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo "  no known program to change jpeg (.jpg) and png (.png) files" 1>&2
    echo "  if you have such a program, you should" 1>&2
    echo "  restart configure with the --with-imageeditor= option" 1>&2
fi

if test "X_$SOUNDEDITOR" = "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo "  no known program to change wave (.wav) files" 1>&2
    echo "  if you have such a program, you should" 1>&2
    echo "  restart configure with the --with-soundeditor= option" 1>&2
fi

if test "X_$MOVIEEDITOR" = "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo "  no known program to change mpeg1 (.mpeg) files" 1>&2
    echo "  if you have such a program, you should" 1>&2
    echo "  restart configure with the --with-movieeditor= option" 1>&2
fi

if test "X_$IMAGECONVERTER" = "X_" ; then
    echo " " 1>&2
    echo "Warning:" 1>&2
    echo "  no known program to convert bitmap files (.jpg, .png) to bmp files for ac3d export" 1>&2
    echo "  if you have such a program, you should" 1>&2
    echo "  restart configure with the --with-imageconverter= option" 1>&2
fi

if test "X_$AVOID_RANLIB" = "X_yes" ; then
    if test "X_$OS" = "X_Darwin" ; then
        echo " " 1>&2
        echo "Warning:" 1>&2
        echo "  the usage of the --without-ranlib option may be not wise of MacOSX" 1>&2
        echo "  a lot of MacOSX versions require the usage of the ranlib command" 1>&2
    fi
fi

