Add labels for debug menu items.
[familia.git] / m4 / ax_check_glu.m4
1 # ===========================================================================
2 #       http://www.gnu.org/software/autoconf-archive/ax_check_glu.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AX_CHECK_GLU
8 #
9 # DESCRIPTION
10 #
11 #   Check for GLU. If GLU is found, the required preprocessor and linker
12 #   flags are included in the output variables "GLU_CFLAGS" and "GLU_LIBS",
13 #   respectively. If no GLU implementation is found, "no_glu" is set to
14 #   "yes".
15 #
16 #   If the header "GL/glu.h" is found, "HAVE_GL_GLU_H" is defined. If the
17 #   header "OpenGL/glu.h" is found, HAVE_OPENGL_GLU_H is defined. These
18 #   preprocessor definitions may not be mutually exclusive.
19 #
20 #   You should use something like this in your headers:
21 #
22 #     # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
23 #     #  include <windows.h>
24 #     # endif
25 #     # if defined(HAVE_GL_GLU_H)
26 #     #  include <GL/glu.h>
27 #     # elif defined(HAVE_OPENGL_GLU_H)
28 #     #  include <OpenGL/glu.h>
29 #     # else
30 #     #  error no glu.h
31 #     # endif
32 #
33 #   Some implementations (in particular, some versions of Mac OS X) are
34 #   known to treat the GLU tesselator callback function type as "GLvoid
35 #   (*)(...)" rather than the standard "GLvoid (*)()". If the former
36 #   condition is detected, this macro defines "HAVE_VARARGS_GLU_TESSCB".
37 #
38 # LICENSE
39 #
40 #   Copyright (c) 2009 Braden McDaniel <braden@endoframe.com>
41 #   Copyright (c) 2013 Bastien Roucaries <roucaries.bastien+autoconf@gmail.com>
42 #
43 #   This program is free software; you can redistribute it and/or modify it
44 #   under the terms of the GNU General Public License as published by the
45 #   Free Software Foundation; either version 2 of the License, or (at your
46 #   option) any later version.
47 #
48 #   This program is distributed in the hope that it will be useful, but
49 #   WITHOUT ANY WARRANTY; without even the implied warranty of
50 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
51 #   Public License for more details.
52 #
53 #   You should have received a copy of the GNU General Public License along
54 #   with this program. If not, see <http://www.gnu.org/licenses/>.
55 #
56 #   As a special exception, the respective Autoconf Macro's copyright owner
57 #   gives unlimited permission to copy, distribute and modify the configure
58 #   scripts that are the output of Autoconf when processing the Macro. You
59 #   need not follow the terms of the GNU General Public License when using
60 #   or distributing such scripts, even though portions of the text of the
61 #   Macro appear in them. The GNU General Public License (GPL) does govern
62 #   all other use of the material that constitutes the Autoconf Macro.
63 #
64 #   This special exception to the GPL applies to versions of the Autoconf
65 #   Macro released by the Autoconf Archive. When you make and distribute a
66 #   modified version of the Autoconf Macro, you may extend this special
67 #   exception to the GPL to apply to your modified version as well.
68
69 #serial 16
70
71 # exemple program
72 m4_define([_AX_CHECK_GLU_PROGRAM],
73           [AC_LANG_PROGRAM([[
74 # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
75 #   include <windows.h>
76 # endif
77 # ifdef HAVE_GL_GLU_H
78 #   include <GL/glu.h>
79 # elif defined(HAVE_OPENGL_GLU_H)
80 #   include <OpenGL/glu.h>
81 # else
82 #   error no glu.h
83 # endif
84 ]],[[gluBeginCurve(0)]])])
85
86
87 dnl Default include : add windows.h
88 dnl see http://www.opengl.org/wiki/Platform_specifics:_Windows
89 dnl (acceded 20120801)
90 AC_DEFUN([_AX_CHECK_GLU_INCLUDES_DEFAULT],dnl
91 [
92   AC_INCLUDES_DEFAULT
93   [
94   # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
95   #   include <windows.h>
96   # endif
97   ]
98 ])
99
100 dnl local save flags
101 AC_DEFUN([_AX_CHECK_GLU_SAVE_FLAGS],
102 [dnl
103 ax_check_glu_saved_libs="${LIBS}"
104 ax_check_glu_saved_cflags="${CFLAGS}"
105 ax_check_glu_saved_cppflags="${CPPFLAGS}"
106 ax_check_glu_saved_ldflags="${LDFLAGS}"
107 ])
108
109
110 dnl local restore flags
111 AC_DEFUN([_AX_CHECK_GLU_RESTORE_FLAGS],
112 [dnl
113 LIBS="${ax_check_glu_saved_libs}"
114 CFLAGS="${ax_check_glu_saved_cflags}"
115 CPPFLAGS="${ax_check_glu_saved_cppflags}"
116 LDFLAGS="${ax_check_glu_saved_ldflags}"
117 ])
118
119
120 # compile the example program
121 AC_DEFUN([_AX_CHECK_GLU_COMPILE],
122 [dnl
123  AC_LANG_PUSH([C])
124  _AX_CHECK_GLU_SAVE_FLAGS()
125  CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
126  AC_COMPILE_IFELSE([_AX_CHECK_GLU_PROGRAM],
127                    [ax_check_glu_compile_opengl="yes"],
128                    [ax_check_glu_compile_opengl="no"])
129  _AX_CHECK_GLU_RESTORE_FLAGS()
130  AC_LANG_POP([C])
131 ])
132
133 # compile the example program (cache)
134 AC_DEFUN([_AX_CHECK_GLU_COMPILE_CV],
135 [dnl
136  AC_CACHE_CHECK([for compiling a minimal OpenGL Utility (GLU) program],[ax_cv_check_glu_compile_opengl],
137                 [_AX_CHECK_GLU_COMPILE()
138                  ax_cv_check_glu_compile_opengl="${ax_check_glu_compile_opengl}"])
139  ax_check_glu_compile_opengl="${ax_cv_check_glu_compile_opengl}"
140 ])
141
142 # link the example program
143 AC_DEFUN([_AX_CHECK_GLU_LINK],
144 [dnl
145  AC_LANG_PUSH([C])
146  _AX_CHECK_GLU_SAVE_FLAGS()
147  CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
148  LIBS="${GLU_LIBS} ${LIBS}"
149  LDFLAGS="${GLU_LDFLAGS} ${LDFLAGS}"
150  AC_LINK_IFELSE([_AX_CHECK_GLU_PROGRAM],
151                 [ax_check_glu_link_opengl="yes"],
152                 [ax_check_glu_link_opengl="no"])
153  _AX_CHECK_GLU_RESTORE_FLAGS()
154  AC_LANG_POP([C])
155 ])
156
157 # link the example program (cache)
158 AC_DEFUN([_AX_CHECK_GLU_LINK_CV],
159 [dnl
160  AC_CACHE_CHECK([for linking a minimal OpenGL Utility (GLU) program],[ax_cv_check_glu_link_opengl],
161                 [_AX_CHECK_GLU_LINK()
162                  ax_cv_check_glu_link_opengl="${ax_check_glu_link_opengl}"])
163  ax_check_glu_link_opengl="${ax_cv_check_glu_link_opengl}"
164 ])
165
166 dnl Check headers manually (default case)
167 AC_DEFUN([_AX_CHECK_GLU_HEADERS],
168 [AC_LANG_PUSH([C])
169  _AX_CHECK_GLU_SAVE_FLAGS()
170  CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
171  # see comment in _AX_CHECK_GL_INCLUDES_DEFAULT
172  AC_CHECK_HEADERS([windows.h],[],[],[AC_INCLUDES_DEFAULT])
173  AC_CHECK_HEADERS([GL/glu.h OpenGL/glu.h],
174                          [ax_check_glu_have_headers="yes";break],
175                          [ax_check_glu_have_headers_headers="no"],
176                          [_AX_CHECK_GLU_INCLUDES_DEFAULT()])
177  # do not try darwin specific OpenGl/gl.h
178  _AX_CHECK_GLU_RESTORE_FLAGS()
179  AC_LANG_POP([C])
180 ])
181
182 # check tesselation callback function signature.
183 m4_define([_AX_CHECK_GLU_VARARGS_TESSVB_PROGRAM],
184 [AC_LANG_PROGRAM([[
185 # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
186 #   include <windows.h>
187 # endif
188 # ifdef HAVE_GL_GLU_H
189 #   include <GL/glu.h>
190 # elif defined(HAVE_OPENGL_GLU_H)
191 #   include <OpenGL/glu.h>
192 # else
193 #   error no glu.h
194 # endif
195 ]],
196 [[GLvoid (*func)(...); gluTessCallback(0, 0, func)]])
197 ])
198
199 # compile the tesselation callback function program
200 # test with c++
201 AC_DEFUN([_AX_CHECK_GLU_COMPILE_VARARGS_TESSVB_PROGRAM],
202 [AC_REQUIRE([AC_PROG_CXX])dnl
203
204  AC_LANG_PUSH([C++])
205  _AX_CHECK_GLU_SAVE_FLAGS()
206  CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
207  AC_COMPILE_IFELSE([_AX_CHECK_GLU_VARARGS_TESSVB_PROGRAM],
208                    [ax_check_glu_compile_varargs_tessvb_program="yes"],
209                    [ax_check_glu_compile_varargs_tessvb_program="no"])
210  _AX_CHECK_GLU_RESTORE_FLAGS()
211  AC_LANG_POP([C++])
212 ])
213
214
215 #
216 # Some versions of Mac OS X include a broken interpretation of the GLU
217 # tesselation callback function signature.
218 #
219 AC_DEFUN([_AX_CHECK_GLU_VARARGS_TESSVB],
220 [
221 AC_CACHE_CHECK([for varargs OpenGL Utility (GLU) tesselator callback function type],
222                 [ax_cv_varargs_glu_tesscb],
223                 [_AX_CHECK_GLU_COMPILE_VARARGS_TESSVB_PROGRAM
224                  ax_cv_varargs_glu_tesscb="${ax_check_glu_compile_varargs_tessvb_program}"])
225 ax_check_glu_compile_varargs_tessvb_program="${ax_cv_varargs_glu_tesscb}"
226
227 AS_IF([test X$ax_cv_varargs_glu_tesscb = Xyes],
228       [AC_DEFINE([HAVE_VARARGS_GLU_TESSCB], [1],
229                  [Use nonstandard varargs form for the GLU tesselator callback])])
230 ])
231
232
233 # dnl try to found library (generic case)
234 # dnl $1 is set to the library to found
235 AC_DEFUN([_AX_CHECK_GLU_MANUAL_LIBS_GENERIC],
236 [dnl
237  ax_check_glu_manual_libs_generic_extra_libs="$1"
238  AS_IF([test "X$ax_check_glu_manual_libs_generic_extra_libs" = "X"],
239        [AC_MSG_ERROR([AX_CHECK_GLU_MANUAL_LIBS_GENERIC argument must no be empty])])
240
241  AC_LANG_PUSH([C])
242  _AX_CHECK_GLU_SAVE_FLAGS()
243  CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
244  LIBS="${GLU_LIBS} ${LIBS}"
245  AC_SEARCH_LIBS([gluBeginCurve],[$ax_check_glu_manual_libs_generic_extra_libs],
246                 [ax_check_glu_lib_opengl="yes"],
247                 [ax_check_glu_lib_opengl="no"])
248  AS_CASE([$ac_cv_search_gluBeginCurve],
249          ["none required"],[],
250          [no],[],
251          [GLU_LIBS="${ac_cv_search_gluBeginCurve} ${GLU_LIBS}"])
252   _AX_CHECK_GLU_RESTORE_FLAGS()
253   AC_LANG_PUSH([C])
254 ])
255
256
257 dnl Check library manually: subroutine must set
258 dnl $ax_check_gl_lib_opengl={yes,no}
259 AC_DEFUN([_AX_CHECK_GLU_MANUAL_LIBS],
260 [AC_REQUIRE([AC_CANONICAL_HOST])
261  GLU_LIBS="${GLU_LIBS} ${GL_LIBS}"
262  AS_CASE([${host}],
263          # try first cygwin version
264          [*-cygwin*],[_AX_CHECK_GLU_MANUAL_LIBS_GENERIC([GLU glu MesaGLU glu32])],
265          # try first native
266          [*-mingw*],[_AX_CHECK_GLU_MANUAL_LIBS_GENERIC([glu32 GLU glu MesaGLU])],
267          [_AX_CHECK_GLU_MANUAL_LIBS_GENERIC([GLU glu MesaGLU])])
268
269  AC_CACHE_CHECK([for OpenGL Utility (GLU) libraries],[ax_cv_check_glu_lib_opengl],
270                 [ax_cv_check_glu_lib_opengl="${ax_check_glu_lib_opengl}"])
271  ax_check_glu_lib_opengl="${ax_cv_check_glu_lib_opengl}"
272 ])
273
274
275 dnl Manual way to detect GLU
276 AC_DEFUN([_AX_CHECK_GLU_MANUAL],
277 [dnl
278
279 # inherit cflags
280 GLU_CFLAGS="${GLU_CFLAGS} ${GL_CFLAGS}"
281
282 # check headers
283 _AX_CHECK_GLU_HEADERS
284
285 AS_IF([test "X$ax_check_glu_have_headers" = "Xyes"],
286       [_AX_CHECK_GLU_MANUAL_LIBS],
287       [ax_check_glu_lib_opengl="no"])
288
289 AS_IF([test "X$ax_check_glu_lib_opengl" = "Xyes"],
290       [_AX_CHECK_GLU_COMPILE_CV()],
291       [ax_cv_check_glu_compile_opengl="no"])
292
293 AS_IF([test "X$ax_cv_check_glu_compile_opengl" = "Xyes"],
294       [_AX_CHECK_GLU_LINK_CV()],
295       [ax_cv_check_glu_link_opengl="no"])
296
297 AS_IF([test "X$ax_cv_check_glu_link_opengl" = "Xyes"],
298       [no_glu="no"],
299       [no_glu="yes"])
300 ])
301
302 # detect using pkgconfig
303 AC_DEFUN([_AX_CHECK_GLU_PKG_CONFIG],
304 [
305  AC_REQUIRE([PKG_PROG_PKG_CONFIG])
306
307  PKG_CHECK_MODULES([GLU],[glu],[ax_check_glu_pkg_config=yes],[ax_check_glu_pkg_config=no])
308
309  AS_IF([test "X$ax_check_glu_pkg_config" = "Xyes"],[
310         # check headers
311         AC_LANG_PUSH([C])
312         _AX_CHECK_GLU_SAVE_FLAGS()
313         CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
314         AC_CHECK_HEADERS([windows.h],[],[],[AC_INCLUDES_DEFAULT])
315         AC_CHECK_HEADERS([GL/glu.h OpenGL/glu.h],
316                          [ax_check_glu_have_headers="yes";break],
317                          [ax_check_glu_have_headers_headers="no"],
318                          [_AX_CHECK_GLU_INCLUDES_DEFAULT()])
319         _AX_CHECK_GL_RESTORE_FLAGS()
320         AC_LANG_POP([C])
321         AC_CACHE_CHECK([for OpenGL Utility (GLU) headers],[ax_cv_check_glu_have_headers],
322                        [ax_cv_check_glu_have_headers="${ax_check_glu_have_headers}"])
323
324         # pkgconfig library are suposed to work ...
325         AS_IF([test "X$ax_cv_check_glu_have_headers" = "Xno"],
326               [AC_MSG_ERROR("Pkgconfig detected OpenGL Utility (GLU) library has no headers!")])
327
328         _AX_CHECK_GLU_COMPILE_CV()
329         AS_IF([test "X$ax_cv_check_glu_compile_opengl" = "Xno"],
330               [AC_MSG_ERROR("Pkgconfig detected OpenGL Utility (GLU) library could not be used for compiling minimal program!")])
331
332         _AX_CHECK_GLU_LINK_CV()
333         AS_IF([test "X$ax_cv_check_glu_link_opengl" = "Xno"],
334               [AC_MSG_ERROR("Pkgconfig detected OpenGL Utility (GLU) library could not be used for linking minimal program!")])
335   ])
336 ])
337
338 # entry point
339 AC_DEFUN([AX_CHECK_GLU],dnl
340 [
341  AC_REQUIRE([AX_CHECK_GL])
342  AC_REQUIRE([PKG_PROG_PKG_CONFIG])
343
344  # set flags
345  no_glu="yes"
346
347  AC_MSG_CHECKING([for a working OpenGL Utility (GLU) implementation by pkg-config])
348  # try first pkgconfig
349  AS_IF([test "X${PKG_CONFIG}" = "X"],
350        [AC_MSG_RESULT([no])
351         ax_check_glu_pkg_config=no],
352        [AC_MSG_RESULT([yes])
353         _AX_CHECK_GLU_PKG_CONFIG()])
354
355  # if no pkg-config or pkg-config fail try manual way
356  AS_IF([test "X$ax_check_glu_pkg_config" = "Xno"],
357        [_AX_CHECK_GLU_MANUAL()],
358        [no_glu=no])
359
360  # check broken implementation
361  AS_IF([test "X$no_glu" = "Xno"],
362        [_AX_CHECK_GLU_VARARGS_TESSVB],[])
363
364  AC_MSG_CHECKING([for a working OpenGL Utility (GLU) implementation])
365  AS_IF([test "X$no_glu" = "Xno"],
366        [AC_MSG_RESULT([yes])
367         AC_MSG_CHECKING([for CFLAGS needed for OpenGL Utility (GLU)])
368         AC_MSG_RESULT(["${GLU_CFLAGS}"])
369         AC_MSG_CHECKING([for LIBS needed for OpenGL Utility (GLU)])
370         AC_MSG_RESULT(["${GLU_LIBS}"])
371         AC_MSG_CHECKING([for LDFLAGS needed for OpenGL Utility (GLU)])
372         AC_MSG_RESULT(["${GLU_LDFLAGS}"])],
373        [AC_MSG_RESULT([no])
374         GLU_CFLAGS=""
375         GLU_LIBS=""
376         GLU_LDFLAGS=""])
377
378  AC_SUBST([GLU_CFLAGS])
379  AC_SUBST([GLU_LIBS])
380  AC_SUBST([GLU_LDFLAGS])
381
382 ])