1# -*- mode: autoconf -*-
2#
3# AX_CHECK_GLU
4#
5# Check for GLU.  If GLU is found, the required preprocessor and linker flags
6# are included in the output variables "GLU_CFLAGS" and "GLU_LIBS",
7# respectively.  If no GLU implementation is found, "no_glu" is set to "yes".
8#
9# If the header "GL/glu.h" is found, "HAVE_GL_GLU_H" is defined.  If the
10# header "OpenGL/glu.h" is found, HAVE_OPENGL_GLU_H is defined.  These
11# preprocessor definitions may not be mutually exclusive.
12#
13# Some implementations (in particular, some versions of Mac OS X) are known
14# to treat the GLU tesselator callback function type as "GLvoid (*)(...)"
15# rather than the standard "GLvoid (*)()".  If the former condition is
16# detected, this macro defines "HAVE_VARARGS_GLU_TESSCB".
17#
18# version: 2.4
19# author: Braden McDaniel <braden@endoframe.com>
20#
21# This program is free software; you can redistribute it and/or modify
22# it under the terms of the GNU General Public License as published by
23# the Free Software Foundation; either version 2, or (at your option)
24# any later version.
25#
26# This program is distributed in the hope that it will be useful,
27# but WITHOUT ANY WARRANTY; without even the implied warranty of
28# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29# GNU General Public License for more details.
30#
31# You should have received a copy of the GNU General Public License
32# along with this program; if not, write to the Free Software
33# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34# 02110-1301, USA.
35#
36# As a special exception, the you may copy, distribute and modify the
37# configure scripts that are the output of Autoconf when processing
38# the Macro.  You need not follow the terms of the GNU General Public
39# License when using or distributing such scripts.
40#
41AC_DEFUN([AX_CHECK_GLU],
42[AC_REQUIRE([AX_CHECK_GL])dnl
43AC_REQUIRE([AC_PROG_CXX])dnl
44GLU_CFLAGS=$GL_CFLAGS
45
46ax_save_CPPFLAGS=$CPPFLAGS
47CPPFLAGS="$GL_CFLAGS $CPPFLAGS"
48AC_CHECK_HEADERS([GL/glu.h OpenGL/glu.h], , , [
49# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
50#   include <windows.h>
51# endif
52])
53CPPFLAGS=$ax_save_CPPFLAGS
54
55m4_define([AX_CHECK_GLU_PROGRAM],
56          [AC_LANG_PROGRAM([[
57# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
58#   include <windows.h>
59# endif
60# ifdef HAVE_GL_GLU_H
61#   include <GL/glu.h>
62# elif defined(HAVE_OPENGL_GLU_H)
63#   include <OpenGL/glu.h>
64# else
65#   error no glu.h
66# endif]],
67                           [[gluBeginCurve(0)]])])
68
69AC_CACHE_CHECK([for OpenGL Utility library], [ax_cv_check_glu_libglu],
70[ax_cv_check_glu_libglu=no
71ax_save_CPPFLAGS=$CPPFLAGS
72CPPFLAGS="$GL_CFLAGS $CPPFLAGS"
73ax_save_LDFLAGS=$LDFLAGS
74ax_save_LIBS=$LIBS
75
76#
77# First, check for the possibility that everything we need is already in
78# GL_LIBS.
79#
80LDFLAGS="$ax_save_LDFLAGS $GL_LIBS"
81#
82# libGLU typically links with libstdc++ on POSIX platforms.
83# However, setting the language to C++ means that test program
84# source is named "conftest.cc"; and Microsoft cl doesn't know what
85# to do with such a file.
86#
87AC_LANG_PUSH([C++])
88AS_IF([test X$ax_compiler_ms = Xyes],
89      [AC_LANG_PUSH([C])])
90AC_LINK_IFELSE([AX_CHECK_GLU_PROGRAM],
91               [ax_cv_check_glu_libglu=yes],
92               [LIBS=""
93                ax_check_libs="-lglu32 -lGLU"
94                for ax_lib in ${ax_check_libs}; do
95                  AS_IF([test X$ax_compiler_ms = Xyes],
96                        [ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`],
97                        [ax_try_lib=$ax_lib])
98                  LIBS="$ax_try_lib $ax_save_LIBS"
99                  AC_LINK_IFELSE([AX_CHECK_GLU_PROGRAM],
100                                 [ax_cv_check_glu_libglu=$ax_try_lib; break])
101                done])
102AS_IF([test X$ax_compiler_ms = Xyes],
103      [AC_LANG_POP([C])])
104AC_LANG_POP([C++])
105
106LIBS=$ax_save_LIBS
107LDFLAGS=$ax_save_LDFLAGS
108CPPFLAGS=$ax_save_CPPFLAGS])
109AS_IF([test "X$ax_cv_check_glu_libglu" = Xno],
110      [no_glu=yes; GLU_CFLAGS=""; GLU_LIBS=""],
111      [AS_IF([test "X$ax_cv_check_glu_libglu" = Xyes],
112             [GLU_LIBS=""],
113             [GLU_LIBS="$ax_cv_check_glu_libglu"])])
114AC_SUBST([GLU_CFLAGS])
115AC_SUBST([GLU_LIBS])
116
117#
118# Some versions of Mac OS X include a broken interpretation of the GLU
119# tesselation callback function signature when using the C++ compiler.
120#
121AS_IF([test "X$ax_cv_check_glu_libglu" != Xno],
122      [AC_CACHE_CHECK([for varargs GLU tesselator callback function type],
123                      [ax_cv_varargs_glu_tesscb],
124                      [AC_LANG_PUSH([C++])
125                      ax_cv_varargs_glu_tesscb=no
126                      ax_save_CXXFLAGS=$CXXFLAGS
127                      CXXFLAGS="$GL_CFLAGS $CXXFLAGS"
128                      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
129# ifdef HAVE_GL_GLU_H
130#   include <GL/glu.h>
131# else
132#   include <OpenGL/glu.h>
133# endif]],
134                                        [[GLvoid (*func)(...); gluTessCallback(0, 0, func)]])],
135                                        [ax_cv_varargs_glu_tesscb=yes])
136                      CXXFLAGS=$ax_save_CXXFLAGS
137                      AC_LANG_POP([C++])])
138      AS_IF([test X$ax_cv_varargs_glu_tesscb = Xyes],
139            [AC_DEFINE([HAVE_VARARGS_GLU_TESSCB], [1],
140                       [Use nonstandard varargs form for the GLU tesselator callback])])])
141])
142