Import fmit upstream version 0.97.6
[fmit.git] / m4 / mdl_have_opengl.m4
1 dnl Available from the GNU Autoconf Macro Archive at:
2 dnl http://www.gnu.org/software/ac-archive/htmldoc/mdl_have_opengl.html
3 dnl
4 AC_DEFUN([MDL_HAVE_OPENGL],
5 [
6   AC_REQUIRE([AC_PROG_CC])
7   AC_REQUIRE([AC_PATH_X])
8   AC_REQUIRE([AC_PATH_XTRA])
9
10   AC_CACHE_CHECK([for OpenGL], mdl_cv_have_OpenGL,
11   [
12 dnl Check for Mesa first, unless we were asked not to.
13 dnl     AC_ARG_WITH(Mesa, AC_HELP_STRING([--with-Mesa],[Prefer the Mesa library over a vendors native OpenGL library (default=yes)]))
14     AC_ARG_ENABLE(Mesa,
15                 AC_HELP_STRING([--enable-Mesa],[Prefer the Mesa library
16                 over a vendors native OpenGL library (default=yes)]),
17                 [use_Mesa=$enableval], [use_Mesa=yes])
18
19     if test x"$use_Mesa" = xyes; then
20        GL_search_list="MesaGL   GL"
21       GLU_search_list="MesaGLU GLU"
22       GLX_search_list="MesaGLX GLX"
23     else
24        GL_search_list="GL  MesaGL"
25       GLU_search_list="GLU MesaGLU"
26       GLX_search_list="GLX MesaGLX"
27     fi
28
29     AC_LANG_SAVE
30     AC_LANG_C
31
32 dnl If we are running under X11 then add in the appropriate libraries.
33 if test x"$no_x" != xyes; then
34 dnl Add everything we need to compile and link X programs to GL_X_CFLAGS
35 dnl and GL_X_LIBS.
36   GL_CFLAGS="$X_CFLAGS"
37   GL_X_LIBS="$X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS"
38 fi
39     GL_save_CPPFLAGS="$CPPFLAGS"
40     CPPFLAGS="$GL_CFLAGS"
41
42     GL_save_LIBS="$LIBS"
43     LIBS="$GL_X_LIBS"
44
45
46     # Save the "AC_MSG_RESULT file descriptor" to FD 8.
47     exec 8>&AC_FD_MSG
48
49     # Temporarily turn off AC_MSG_RESULT so that the user gets pretty
50     # messages.
51     exec AC_FD_MSG>/dev/null
52
53     AC_SEARCH_LIBS(glAccum,          $GL_search_list, have_GL=yes,   have_GL=no)
54     AC_SEARCH_LIBS(gluBeginCurve,   $GLU_search_list, have_GLU=yes,  have_GLU=no)
55     AC_SEARCH_LIBS(glXChooseVisual, $GLX_search_list, have_GLX=yes,  have_GLX=no)
56     AC_SEARCH_LIBS(glutInit,        glut,             have_glut=yes, have_glut=no)
57
58
59
60     # Restore pretty messages.
61     exec AC_FD_MSG>&8
62
63     if test -n "$LIBS"; then
64       mdl_cv_have_OpenGL=yes
65       GL_LIBS="$LIBS"
66       AC_SUBST(GL_CFLAGS)
67       AC_SUBST(GL_LIBS)
68     else
69       mdl_cv_have_OpenGL=no
70       GL_CFLAGS=
71     fi
72
73 dnl Reset GL_X_LIBS regardless, since it was just a temporary variable
74 dnl and we don't want to be global namespace polluters.
75     GL_X_LIBS=
76
77     LIBS="$GL_save_LIBS"
78     CPPFLAGS="$GL_save_CPPFLAGS"
79
80     AC_LANG_RESTORE
81     
82 dnl bugfix: dont forget to cache this variables, too
83     mdl_cv_GL_CFLAGS="$GL_CFLAGS"
84     mdl_cv_GL_LIBS="$GL_LIBS"
85     mdl_cv_have_GL="$have_GL"
86     mdl_cv_have_GLU="$have_GLU"
87     mdl_cv_have_GLX="$have_GLX"
88     mdl_cv_have_glut="$have_glut"
89   ])
90   GL_CFLAGS="$mdl_cv_GL_CFLAGS"
91   GL_LIBS="$mdl_cv_GL_LIBS"
92   have_GL="$mdl_cv_have_GL"
93   have_GLU="$mdl_cv_have_GLU"
94   have_GLX="$mdl_cv_have_GLX"
95   have_glut="$mdl_cv_have_glut"
96 ])
97 dnl endof bugfix -ainan