"Matthew D. Langston" <[EMAIL PROTECTED]> writes:

> The macro MDL_HAVE_OPENGL is what you want.  It is in the Autoconf
> Macro Archive at http://peti.cys.de/autoconf-archive/ in the file
> mdl_have_opengl.m4.  It should do everything you want.  If it
> doesn't, please let me know (or better yet, send me a patch) as I am
> the original author if it.

Your OpenGL detection macro is seriously flawed in a number of
ways. You should for instance look at the way you use AC_CACHE_CHECK
(hint: there should not be any sideeffects within a cached check).

I started working on fixing the problems of your macro, but I gave up,
the overall structure of the macro is just not flexible enough. So I
wrote my own instead. I've attached it to this mail for your perusal.

Its not perfect, but it seems to work well on the platforms it has
been tested (Linux, HPUX, IRIX, Solaris, BeOS), within the context of
the configure process for the Coin¹ library.

BTW, some major difference from your macro:

* it handles GL and GLU (or Mesa and MesaGLU) exclusively (I've got a
  separate macro for GLX)

* it assumes that all the necessary libraries GL depends on has been
  configured to be covered by the environment variables LDFLAGS and
  LIBS _before_ the macro is run


Regards,
Morten

¹ <http://www.coin3d.org>


dnl Usage:
dnl  SIM_CHECK_OPENGL([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
dnl
dnl  Try to find an OpenGL development system, either a native
dnl  implementation or the OpenGL-compatible Mesa libraries. If
dnl  it is found, these shell variables are set:
dnl
dnl    $sim_ac_gl_cppflags (extra flags the compiler needs for OpenGL/Mesa)
dnl    $sim_ac_gl_ldflags  (extra flags the linker needs for OpenGL/Mesa)
dnl    $sim_ac_gl_libs     (link libraries the linker needs for OpenGL/Mesa)
dnl
dnl  The CPPFLAGS, LDFLAGS and LIBS flags will also be modified accordingly.
dnl  In addition, the variable $sim_ac_gl_avail is set to "yes" if an
dnl  OpenGL-compatible development system is found. If the OpenGL system
dnl  found is the Mesa libraries, we will also set $sim_ac_gl_is_mesa to
dnl  "yes".
dnl
dnl
dnl Author: Morten Eriksen, <[EMAIL PROTECTED]>.
dnl
dnl TODO:
dnl    * [mortene:20000122] make sure this work on MSWin (with
dnl      Cygwin installation)
dnl

AC_DEFUN(SIM_CHECK_OPENGL,[
dnl Autoconf is a developer tool, so don't bother to support older versions.
AC_PREREQ([2.14.1])

AC_ARG_WITH(opengl, AC_HELP_STRING([--with-opengl=DIR], [OpenGL/Mesa installation 
directory]), , [with_opengl=yes])

sim_ac_gl_avail=no
sim_ac_gl_is_mesa=no

if test x"$with_opengl" != xno; then
  if test x"$with_opengl" != xyes; then
    sim_ac_gl_cppflags="-I${with_opengl}/include"
    sim_ac_gl_ldflags="-L${with_opengl}/lib"
  else
    case "$host_os" in
      hpux*)
        # This is a common location for the OpenGL libraries on HPUX.
        sim_ac_gl_cppflags="-I/opt/graphics/OpenGL/include"
        sim_ac_gl_ldflags="-L/opt/graphics/OpenGL/lib" ;;
    esac
  fi

  sim_ac_save_cppflags=$CPPFLAGS
  sim_ac_save_ldflags=$LDFLAGS

  CPPFLAGS="$CPPFLAGS $sim_ac_gl_cppflags"
  LDFLAGS="$LDFLAGS $sim_ac_gl_ldflags"

  sim_ac_save_libs=$LIBS

  AC_CACHE_CHECK([whether OpenGL libraries are available], sim_cv_lib_gl, [
    sim_cv_lib_gl=UNRESOLVED
    # Some platforms (like BeOS) have the GLU functionality in the GL library.
    for i in -lMesaGL -lGL "-lMesaGLU -lMesaGL" "-lGLU -lGL"; do
      if test "x$sim_cv_lib_gl" = "xUNRESOLVED"; then
        LIBS="$i $sim_ac_save_libs"
        AC_TRY_LINK([#include <GL/gl.h>
                     #include <GL/glu.h>],
                    [glPointSize(1.0f); gluSphere(0L, 1.0, 1, 1);],
                    sim_cv_lib_gl="$i")
      fi
    done
  ])


  if test "x$sim_cv_lib_gl" != "xUNRESOLVED"; then
    sim_ac_gl_libs="$sim_cv_lib_gl"
    LIBS="$sim_ac_gl_libs $sim_ac_save_libs"
    sim_ac_gl_avail=yes
    AC_CACHE_CHECK([whether OpenGL libraries are the Mesa libraries],
      sim_cv_lib_gl_ismesa,
      [AC_TRY_LINK([#include <GL/gl.h>],
                   [#ifndef MESA
                    #error not mesa
                    #endif],
                   sim_cv_lib_gl_ismesa=yes,
                   sim_cv_lib_gl_ismesa=no)])
    if test x"$sim_cv_lib_gl_ismesa" = xyes; then
      sim_ac_gl_is_mesa=yes
    fi

    ifelse($1, , :, $1)
  else
    CPPFLAGS=$sim_ac_save_cppflags
    LDFLAGS=$sim_ac_save_ldflags
    LIBS=$sim_ac_save_libs
    ifelse($2, , :, $2)
  fi
fi
])

Reply via email to