From e1427617117042f8507f04aa73ea044dc83c713b Mon Sep 17 00:00:00 2001
From: John Darrington <john@darrington.wattle.id.au>
Date: Sun, 8 Jan 2012 15:58:23 +0100
Subject: [PATCH] Added Mesa/OpenGL Braden McDaniel's checking macros

These macros test whether GL/gl, GL/glu and GL/glut libraries
and header files have been installed.

They should be called as AX_CHECK_GL, AX_CHECK_GLU and AX_CHECK_GLUT
respectively.

The author is Braden McDaniel <braden@endoframe.com> who for some reason
maintains them seperately at http://code.google.com/p/autoconf-gl-macros

The licence is GPLv2+
---
 m4/ax_check_gl.m4   |  148 +++++++++++++++++++++++++++++++++++++++++++++++++++
 m4/ax_check_glu.m4  |  141 ++++++++++++++++++++++++++++++++++++++++++++++++
 m4/ax_check_glut.m4 |  114 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 403 insertions(+), 0 deletions(-)
 create mode 100644 m4/ax_check_gl.m4
 create mode 100644 m4/ax_check_glu.m4
 create mode 100644 m4/ax_check_glut.m4

diff --git a/m4/ax_check_gl.m4 b/m4/ax_check_gl.m4
new file mode 100644
index 0000000..6820145
--- /dev/null
+++ b/m4/ax_check_gl.m4
@@ -0,0 +1,148 @@
+# -*- mode: autoconf -*-
+#
+# AX_CHECK_GL
+#
+# Check for an OpenGL implementation.  If GL is found, the required compiler
+# and linker flags are included in the output variables "GL_CFLAGS" and
+# "GL_LIBS", respectively.  If no usable GL implementation is found, "no_gl"
+# is set to "yes".
+#
+# If the header "GL/gl.h" is found, "HAVE_GL_GL_H" is defined.  If the header
+# "OpenGL/gl.h" is found, HAVE_OPENGL_GL_H is defined.  These preprocessor
+# definitions may not be mutually exclusive.
+#
+# version: 2.7
+# author: Braden McDaniel <braden@endoframe.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception, the you may copy, distribute and modify the
+# configure scripts that are the output of Autoconf when processing
+# the Macro.  You need not follow the terms of the GNU General Public
+# License when using or distributing such scripts.
+#
+AC_DEFUN([AX_CHECK_GL],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_PATH_X])dnl
+AC_REQUIRE([AC_PROG_SED])dnl
+
+AC_LANG_PUSH([C])
+AX_LANG_COMPILER_MS
+
+#
+# Use x_includes and x_libraries if they have been set (presumably by
+# AC_PATH_X).
+#
+AS_IF([test X$no_x != Xyes -a -n "$x_includes"],
+      [GL_CFLAGS="-I$x_includes $GL_CFLAGS"])
+
+AC_CHECK_HEADERS([windows.h])
+
+ax_save_CPPFLAGS=$CPPFLAGS
+CPPFLAGS="$GL_CFLAGS $CPPFLAGS"
+AC_CHECK_HEADERS([GL/gl.h OpenGL/gl.h], , , [
+# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
+#   include <windows.h>
+# endif
+])
+CPPFLAGS=$ax_save_CPPFLAGS
+
+m4_define([AX_CHECK_GL_PROGRAM],
+          [AC_LANG_PROGRAM([[
+# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
+#   include <windows.h>
+# endif
+# ifdef HAVE_GL_GL_H
+#   include <GL/gl.h>
+# elif defined(HAVE_OPENGL_GL_H)
+#   include <OpenGL/gl.h>
+# else
+#   error no gl.h
+# endif]],
+                           [[glBegin(0)]])])
+
+m4_define([AX_CHECK_GL_GLX_PROGRAM],
+          [AC_LANG_PROGRAM([[
+# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
+#   include <windows.h>
+# endif
+# ifdef HAVE_GL_GL_H
+#   include <GL/gl.h>
+# elif defined(HAVE_OPENGL_GL_H)
+#   include <OpenGL/gl.h>
+# else
+#   error no gl.h
+# endif]],
+                           [[glXQueryVersion(0, 0, 0)]])])
+
+AC_CACHE_CHECK([for OpenGL library], [ax_cv_check_gl_libgl],
+[ax_cv_check_gl_libgl=no
+case $host_cpu in
+  x86_64) ax_check_gl_libdir=lib64 ;;
+  *)      ax_check_gl_libdir=lib ;;
+esac
+ax_save_CPPFLAGS=$CPPFLAGS
+CPPFLAGS="$CPPFLAGS $GL_CFLAGS"
+ax_save_LDFLAGS=$LDFLAGS
+AS_IF([test X$no_x != Xyes -a -n "$x_libraries"],
+      [LDFLAGS="$LDFLAGS -L$x_libraries"])
+ax_save_LIBS=$LIBS
+ax_check_libs="-lopengl32 -lGL"
+for ax_lib in $ax_check_libs; do
+  AS_IF([test X$ax_compiler_ms = Xyes],
+        [ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`],
+        [ax_try_lib=$ax_lib])
+  LDFLAGS="$ax_save_LDFLAGS $GL_LIBS"
+  LIBS="$ax_try_lib $ax_save_LIBS"
+AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM],
+               [ax_cv_check_gl_libgl=$ax_try_lib; break],
+               [ax_check_gl_dylib_flag='-dylib_file /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib'
+                LDFLAGS="$ax_save_LDFLAGS $GL_LIBS $ax_check_gl_dylib_flag"
+                AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM],
+                               [ax_cv_check_gl_libgl="$ax_check_gl_dylib_flag $ax_try_lib"; break])])
+done
+
+#
+# If no_x is "yes", we don't want to wind up using a libGL that is
+# linked with X11.  Test to see if the found libGL includes GLX
+# functions.  If it does and no_x is "yes", we want to reset
+# ax_cv_check_gl_libgl back to "no".
+#
+# Note that LDFLAGS and LIBS should still have whatever values they
+# had when we broke out of the test loop above; use that.
+#
+AS_IF([test "X$ax_cv_check_gl_libgl" != Xno],
+      [AC_LINK_IFELSE([AX_CHECK_GL_GLX_PROGRAM],
+                      [AS_IF([test X$no_x = Xyes],
+                             [ax_cv_check_gl_libgl=no])])])
+
+LIBS=$ax_save_LIBS
+AS_IF([test "X$ax_cv_check_gl_libgl" = Xno -a X$no_x = Xyes],
+      [LDFLAGS="$ax_save_LDFLAGS -framework OpenGL"
+      AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM],
+                     [ax_cv_check_gl_libgl='-framework OpenGL'])])
+
+LDFLAGS=$ax_save_LDFLAGS
+CPPFLAGS=$ax_save_CPPFLAGS])
+
+AS_IF([test "X$ax_cv_check_gl_libgl" = Xno],
+      [no_gl=yes; GL_CFLAGS=""; GL_LIBS=""],
+      [GL_LIBS="$ax_cv_check_gl_libgl $GL_LIBS"])
+AC_LANG_POP([C])
+
+AC_SUBST([GL_CFLAGS])
+AC_SUBST([GL_LIBS])
+])dnl
diff --git a/m4/ax_check_glu.m4 b/m4/ax_check_glu.m4
new file mode 100644
index 0000000..1680f3c
--- /dev/null
+++ b/m4/ax_check_glu.m4
@@ -0,0 +1,141 @@
+# -*- mode: autoconf -*-
+#
+# AX_CHECK_GLU
+#
+# Check for GLU.  If GLU is found, the required preprocessor and linker flags
+# are included in the output variables "GLU_CFLAGS" and "GLU_LIBS",
+# respectively.  If no GLU implementation is found, "no_glu" is set to "yes".
+#
+# If the header "GL/glu.h" is found, "HAVE_GL_GLU_H" is defined.  If the
+# header "OpenGL/glu.h" is found, HAVE_OPENGL_GLU_H is defined.  These
+# preprocessor definitions may not be mutually exclusive.
+#
+# Some implementations (in particular, some versions of Mac OS X) are known
+# to treat the GLU tesselator callback function type as "GLvoid (*)(...)"
+# rather than the standard "GLvoid (*)()".  If the former condition is
+# detected, this macro defines "HAVE_VARARGS_GLU_TESSCB".
+#
+# version: 2.4
+# author: Braden McDaniel <braden@endoframe.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception, the you may copy, distribute and modify the
+# configure scripts that are the output of Autoconf when processing
+# the Macro.  You need not follow the terms of the GNU General Public
+# License when using or distributing such scripts.
+#
+AC_DEFUN([AX_CHECK_GLU],
+[AC_REQUIRE([AX_CHECK_GL])dnl
+AC_REQUIRE([AC_PROG_CXX])dnl
+GLU_CFLAGS=$GL_CFLAGS
+
+ax_save_CPPFLAGS=$CPPFLAGS
+CPPFLAGS="$GL_CFLAGS $CPPFLAGS"
+AC_CHECK_HEADERS([GL/glu.h OpenGL/glu.h], , , [
+# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
+#   include <windows.h>
+# endif
+])
+CPPFLAGS=$ax_save_CPPFLAGS
+
+m4_define([AX_CHECK_GLU_PROGRAM],
+          [AC_LANG_PROGRAM([[
+# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
+#   include <windows.h>
+# endif
+# ifdef HAVE_GL_GLU_H
+#   include <GL/glu.h>
+# elif defined(HAVE_OPENGL_GLU_H)
+#   include <OpenGL/glu.h>
+# else
+#   error no glu.h
+# endif]],
+                           [[gluBeginCurve(0)]])])
+
+AC_CACHE_CHECK([for OpenGL Utility library], [ax_cv_check_glu_libglu],
+[ax_cv_check_glu_libglu=no
+ax_save_CPPFLAGS=$CPPFLAGS
+CPPFLAGS="$GL_CFLAGS $CPPFLAGS"
+ax_save_LDFLAGS=$LDFLAGS
+ax_save_LIBS=$LIBS
+
+#
+# First, check for the possibility that everything we need is already in
+# GL_LIBS.
+#
+LDFLAGS="$ax_save_LDFLAGS $GL_LIBS"
+#
+# libGLU typically links with libstdc++ on POSIX platforms.
+# However, setting the language to C++ means that test program
+# source is named "conftest.cc"; and Microsoft cl doesn't know what
+# to do with such a file.
+#
+AC_LANG_PUSH([C++])
+AS_IF([test X$ax_compiler_ms = Xyes],
+      [AC_LANG_PUSH([C])])
+AC_LINK_IFELSE([AX_CHECK_GLU_PROGRAM],
+               [ax_cv_check_glu_libglu=yes],
+               [LIBS=""
+                ax_check_libs="-lglu32 -lGLU"
+                for ax_lib in ${ax_check_libs}; do
+                  AS_IF([test X$ax_compiler_ms = Xyes],
+                        [ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`],
+                        [ax_try_lib=$ax_lib])
+                  LIBS="$ax_try_lib $ax_save_LIBS"
+                  AC_LINK_IFELSE([AX_CHECK_GLU_PROGRAM],
+                                 [ax_cv_check_glu_libglu=$ax_try_lib; break])
+                done])
+AS_IF([test X$ax_compiler_ms = Xyes],
+      [AC_LANG_POP([C])])
+AC_LANG_POP([C++])
+
+LIBS=$ax_save_LIBS
+LDFLAGS=$ax_save_LDFLAGS
+CPPFLAGS=$ax_save_CPPFLAGS])
+AS_IF([test "X$ax_cv_check_glu_libglu" = Xno],
+      [no_glu=yes; GLU_CFLAGS=""; GLU_LIBS=""],
+      [AS_IF([test "X$ax_cv_check_glu_libglu" = Xyes],
+             [GLU_LIBS=""],
+             [GLU_LIBS="$ax_cv_check_glu_libglu"])])
+AC_SUBST([GLU_CFLAGS])
+AC_SUBST([GLU_LIBS])
+
+#
+# Some versions of Mac OS X include a broken interpretation of the GLU
+# tesselation callback function signature when using the C++ compiler.
+#
+AS_IF([test "X$ax_cv_check_glu_libglu" != Xno],
+      [AC_CACHE_CHECK([for varargs GLU tesselator callback function type],
+                      [ax_cv_varargs_glu_tesscb],
+                      [AC_LANG_PUSH([C++])
+                      ax_cv_varargs_glu_tesscb=no
+                      ax_save_CXXFLAGS=$CXXFLAGS
+                      CXXFLAGS="$GL_CFLAGS $CXXFLAGS"
+                      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+# ifdef HAVE_GL_GLU_H
+#   include <GL/glu.h>
+# else
+#   include <OpenGL/glu.h>
+# endif]],
+                                        [[GLvoid (*func)(...); gluTessCallback(0, 0, func)]])],
+                                        [ax_cv_varargs_glu_tesscb=yes])
+                      CXXFLAGS=$ax_save_CXXFLAGS
+                      AC_LANG_POP([C++])])
+      AS_IF([test X$ax_cv_varargs_glu_tesscb = Xyes],
+            [AC_DEFINE([HAVE_VARARGS_GLU_TESSCB], [1],
+                       [Use nonstandard varargs form for the GLU tesselator callback])])])
+])
diff --git a/m4/ax_check_glut.m4 b/m4/ax_check_glut.m4
new file mode 100644
index 0000000..a71e938
--- /dev/null
+++ b/m4/ax_check_glut.m4
@@ -0,0 +1,114 @@
+# -*- mode: autoconf -*-
+#
+# AX_CHECK_GLUT
+#
+# Check for GLUT.  If GLUT is found, the required compiler and linker flags
+# are included in the output variables "GLUT_CFLAGS" and "GLUT_LIBS",
+# respectively.  If GLUT is not found, "no_glut" is set to "yes".
+#
+# If the header "GL/glut.h" is found, "HAVE_GL_GLUT_H" is defined.  If the
+# header "GLUT/glut.h" is found, HAVE_GLUT_GLUT_H is defined.  These
+# preprocessor definitions may not be mutually exclusive.
+#
+# version: 2.3
+# author: Braden McDaniel <braden@endoframe.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception, the you may copy, distribute and modify the
+# configure scripts that are the output of Autoconf when processing
+# the Macro.  You need not follow the terms of the GNU General Public
+# License when using or distributing such scripts.
+#
+AC_DEFUN([AX_CHECK_GLUT],
+[AC_REQUIRE([AX_CHECK_GLU])dnl
+AC_REQUIRE([AC_PATH_XTRA])dnl
+
+#
+# Kilgard's GLUT need's both Xmu and Xi, while freeglut just needs Xi.
+# It's also probably a good idea to accommodate the possibility of a
+# GLUT implementation that needs neither.
+#
+AC_LANG_PUSH([C])
+AC_CHECK_LIB([Xmu], [XmuScreenOfWindow],
+             [ax_check_glut_xmu_libs=-lXmu], ,
+             [$X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS])
+AC_CHECK_LIB([Xi], [XIQueryVersion],
+             [ax_check_glut_xi_libs=-lXi], ,
+             [$X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS])
+AC_LANG_POP([C])
+
+ax_save_CPPFLAGS=$CPPFLAGS
+CPPFLAGS="$GLU_CFLAGS $CPPFLAGS"
+AC_CHECK_HEADERS([GL/glut.h GLUT/glut.h])
+CPPFLAGS=$ax_save_CPPFLAGS
+
+GLUT_CFLAGS=$GLU_CFLAGS
+
+m4_define([AX_CHECK_GLUT_PROGRAM],
+          [AC_LANG_PROGRAM([[
+# if HAVE_WINDOWS_H && defined(_WIN32)
+#   include <windows.h>
+# endif
+# ifdef HAVE_GL_GLUT_H
+#   include <GL/glut.h>
+# elif defined(HAVE_GLUT_GLUT_H)
+#   include <GLUT/glut.h>
+# else
+#   error no glut.h
+# endif]],
+                           [[glutMainLoop()]])])
+
+AC_CACHE_CHECK([for GLUT library], [ax_cv_check_glut_libglut],
+[ax_cv_check_glut_libglut=no
+#
+# If X is present, assume GLUT depends on it.
+#
+AC_LANG_PUSH(C)
+ax_save_CPPFLAGS=$CPPFLAGS
+CPPFLAGS="$GLUT_CFLAGS $CPPFLAGS"
+ax_save_LDFLAGS=$LDFLAGS
+ax_save_LIBS=$LIBS
+LIBS=""
+AS_IF([test X$no_x != Xyes],
+      [ax_check_glut_x_libs="$ax_check_glut_xmu_libs $ax_check_glut_xi_libs $X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS"])
+ax_check_libs="-lglut32 -lglut"
+for ax_lib in $ax_check_libs; do
+  AS_IF([test X$ax_compiler_ms = Xyes],
+        [ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`],
+        [ax_try_lib=$ax_lib])
+  LIBS="$ax_try_lib $ax_check_glut_x_libs $ax_save_LIBS"
+  AC_LINK_IFELSE([AX_CHECK_GLUT_PROGRAM],
+                 [ax_cv_check_glut_libglut=$ax_try_lib; break])
+done
+
+LIBS=$ax_save_LIBS
+AS_IF([test "X$ax_cv_check_glut_libglut" = Xno -a X$no_x = Xyes],
+      [LDFLAGS="$ax_save_LDFLAGS -framework GLUT"
+      AC_LINK_IFELSE([AX_CHECK_GLUT_PROGRAM],
+                     [ax_cv_check_glut_libglut='-framework GLUT'])])
+
+LDFLAGS=$ax_save_LDFLAGS
+CPPFLAGS=$ax_save_CPPFLAGS
+AC_LANG_POP(C)])
+
+AS_IF([test "X$ax_cv_check_glut_libglut" = Xno],
+      [no_glut=yes; GLUT_CFLAGS=""; GLUT_LIBS=""],
+      [GLUT_LIBS="$ax_cv_check_glut_libglut"])
+
+AC_SUBST([GLUT_CFLAGS])
+AC_SUBST([GLUT_LIBS])
+])dnl
-- 
1.7.2.5

