1dnl @synopsis AX_CHECK_GL
2dnl
3dnl Check for an OpenGL implementation.  If GL is found, the required compiler
4dnl and linker flags are included in the output variables "GL_CFLAGS" and
5dnl "GL_LIBS", respectively.  This macro adds the configure option
6dnl "--with-apple-opengl-framework", which users can use to indicate that
7dnl Apple's OpenGL framework should be used on Mac OS X.  If Apple's OpenGL
8dnl framework is used, the symbol "HAVE_APPLE_OPENGL_FRAMEWORK" is defined.  If
9dnl no GL implementation is found, "no_gl" is set to "yes".
10dnl
11dnl @version 1.8
12dnl @author Braden McDaniel <braden@endoframe.com>
13dnl
14AC_DEFUN([AX_CHECK_GL],
15[AC_REQUIRE([AC_PATH_X])dnl
16AC_REQUIRE([ACX_PTHREAD])dnl
17
18#
19# There isn't a reliable way to know we should use the Apple OpenGL framework
20# without a configure option.  A Mac OS X user may have installed an
21# alternative GL implementation (e.g., Mesa), which may or may not depend on X.
22#
23AC_ARG_WITH([apple-opengl-framework],
24            [AC_HELP_STRING([--with-apple-opengl-framework],
25                            [use Apple OpenGL framework (Mac OS X only)])])
26if test "X$with_apple_opengl_framework" = "Xyes"; then
27  AC_DEFINE([HAVE_APPLE_OPENGL_FRAMEWORK], [1],
28            [Use the Apple OpenGL framework.])
29  GL_LIBS="-framework OpenGL"
30else
31  AC_LANG_PUSH(C)
32
33  AX_LANG_COMPILER_MS
34  if test X$ax_compiler_ms = Xno; then
35    GL_CFLAGS="${PTHREAD_CFLAGS}"
36    GL_LIBS="${PTHREAD_LIBS} -lm"
37  fi
38
39  #
40  # Use x_includes and x_libraries if they have been set (presumably by
41  # AC_PATH_X).
42  #
43  if test "X$no_x" != "Xyes"; then
44    if test -n "$x_includes"; then
45      GL_CFLAGS="-I${x_includes} ${GL_CFLAGS}"
46    fi
47    if test -n "$x_libraries"; then
48      GL_LIBS="-L${x_libraries} -lX11 ${GL_LIBS}"
49    fi
50  fi
51
52  AC_CHECK_HEADERS([windows.h])
53
54  AC_CACHE_CHECK([for OpenGL library], [ax_cv_check_gl_libgl],
55  [ax_cv_check_gl_libgl="no"
56  ax_save_CPPFLAGS="${CPPFLAGS}"
57  CPPFLAGS="${GL_CFLAGS} ${CPPFLAGS}"
58  ax_save_LIBS="${LIBS}"
59  LIBS=""
60  ax_check_libs="-lopengl32 -lGL"
61  for ax_lib in ${ax_check_libs}; do
62    if test X$ax_compiler_ms = Xyes; then
63      ax_try_lib=`echo $ax_lib | sed -e 's/^-l//' -e 's/$/.lib/'`
64    else
65      ax_try_lib="${ax_lib}"
66    fi
67    LIBS="${ax_try_lib} ${GL_LIBS} ${ax_save_LIBS}"
68    AC_LINK_IFELSE(
69    [AC_LANG_PROGRAM([[
70# if HAVE_WINDOWS_H && defined(_WIN32)
71#   include <windows.h>
72# endif
73# include <GL/gl.h>]],
74                     [[glBegin(0)]])],
75    [ax_cv_check_gl_libgl="${ax_try_lib}"; break])
76  done
77  LIBS=${ax_save_LIBS}
78  CPPFLAGS=${ax_save_CPPFLAGS}])
79
80  if test "X${ax_cv_check_gl_libgl}" = "Xno"; then
81    no_gl="yes"
82    GL_CFLAGS=""
83    GL_LIBS=""
84  else
85    GL_LIBS="${ax_cv_check_gl_libgl} ${GL_LIBS}"
86  fi
87  AC_LANG_POP(C)
88fi
89
90AC_SUBST([GL_CFLAGS])
91AC_SUBST([GL_LIBS])
92])dnl
93