1AC_DEFUN([AX_CHECK_GL],
2[AC_REQUIRE([AC_PATH_X])dnl
3AC_REQUIRE([ACX_PTHREAD])dnl
4
5#
6# There isn't a reliable way to know we should use the Apple OpenGL framework
7# without a configure option.  A Mac OS X user may have installed an
8# alternative GL implementation (e.g., Mesa), which may or may not depend on X.
9#
10AC_ARG_WITH([apple-opengl-framework],
11            [AC_HELP_STRING([--with-apple-opengl-framework],
12                            [use Apple OpenGL framework (Mac OS X only)])])
13if test "X$with_apple_opengl_framework" = "Xyes"; then
14  AC_DEFINE([HAVE_APPLE_OPENGL_FRAMEWORK], [1],
15            [Use the Apple OpenGL framework.])
16  GL_CFLAGS="-framework OpenGL"
17else
18  GL_CFLAGS="${PTHREAD_CFLAGS}"
19  GL_LIBS="${PTHREAD_LIBS} -lm"
20
21  #
22  # Use x_includes and x_libraries if they have been set (presumably by
23  # AC_PATH_X).
24  #
25  if test "X$no_x" != "Xyes"; then
26    if test -n "$x_includes"; then
27      GL_CFLAGS="-I${x_includes} ${GL_CFLAGS}"
28    fi
29    if test -n "$x_libraries"; then
30      GL_LIBS="-L${x_libraries} -lX11 ${GL_LIBS}"
31    fi
32  fi
33
34  AC_LANG_PUSH(C)
35
36  AC_CHECK_HEADERS([windows.h])
37
38  AC_CACHE_CHECK([for OpenGL library], [ax_cv_check_gl_libgl],
39  [ax_cv_check_gl_libgl="no"
40  ax_save_CPPFLAGS="${CPPFLAGS}"
41  CPPFLAGS="${GL_CFLAGS} ${CPPFLAGS}"
42  ax_save_LIBS="${LIBS}"
43  LIBS=""
44  ax_check_libs="-lopengl32 -lGL"
45    for ax_lib in ${ax_check_libs}; do
46    if test "X$CC" = "Xcl"; then
47      ax_try_lib=`echo $ax_lib | sed -e 's/^-l//' -e 's/$/.lib/'`
48    else
49      ax_try_lib="${ax_lib}"
50    fi
51    LIBS="${ax_try_lib} ${GL_LIBS} ${ax_save_LIBS}"
52    AC_TRY_LINK([
53# if HAVE_WINDOWS_H && defined(_WIN32)
54#   include <windows.h>
55# endif
56# include <GL/gl.h>
57],
58    [glBegin(0)],
59    [ax_cv_check_gl_libgl="${ax_try_lib}"; break])
60  done
61  LIBS=${ax_save_LIBS}
62  CPPFLAGS=${ax_save_CPPFLAGS}])
63
64  if test "X${ax_cv_check_gl_libgl}" = "Xno"; then
65    no_gl="yes"
66    GL_CFLAGS=""
67    GL_LIBS=""
68  else
69    GL_LIBS="${ax_cv_check_gl_libgl} ${GL_LIBS}"
70  fi
71  AC_LANG_POP(C)
72fi
73
74AC_SUBST([GL_CFLAGS])
75AC_SUBST([GL_LIBS])
76])dnl
77