1# ===========================================================================
2#       https://www.gnu.org/software/autoconf-archive/ax_check_glu.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_CHECK_GLU([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
8#
9# DESCRIPTION
10#
11#   Checks for GLUT. If a valid GLU implementation is found, the configure
12#   script would export the C preprocessor symbol "HAVE_GLU=1".
13#
14#   If either a valid GLU header or library was not found, by default the
15#   configure script would exit on error. This behavior can be overwritten
16#   by providing a custom "ACTION-IF-NOT-FOUND" hook.
17#
18#   If the header, library was found, and been tested for compiling and
19#   linking the configuration would export the required compiler flags to
20#   "GLU_CFLAGS" and "GLU_LIBS" environment variables. These two variables
21#   can also be overwritten by defining the environment variables before
22#   executing the configure program. If it was predefined, configure would
23#   not try to overwrite it, but it would still perform the compile and link
24#   test. Only when the tests succeeded does the configure script to export
25#   "HAVE_GLU=1" and to run "ACTION-IF-FOUND" hook.
26#
27#   If user didn't specify the "ACTION-IF-FOUND" hook, the configuration
28#   would prepend "GLU_CFLAGS" and "GLU_LIBS" to "CFLAGS" and "LIBS", like
29#   many other autoconf macros do.
30#
31#   If the header "GL/glu.h" is found, "HAVE_GL_GLU_H" is defined. If the
32#   header "OpenGL/glu.h" is found, HAVE_OPENGL_GLU_H is defined.
33#
34#   You should use something like this in your headers:
35#
36#     # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
37#     #  include <windows.h>
38#     # endif
39#     # if defined(HAVE_GL_GLU_H)
40#     #  include <GL/glu.h>
41#     # elif defined(HAVE_OPENGL_GLU_H)
42#     #  include <OpenGL/glu.h>
43#     # else
44#     #  error no glu.h
45#     # endif
46#
47#   On the OSX platform, you can use the option --with-xquartz-gl to use
48#   X11/Xquartz GLU implementation instead of the system built in GLU
49#   framework.
50#
51#   Some implementations (in particular, some versions of Mac OS X) are
52#   known to treat the GLU tesselator callback function type as "GLvoid
53#   (*)(...)" rather than the standard "GLvoid (*)()". If the former
54#   condition is detected, this macro defines "HAVE_VARARGS_GLU_TESSCB".
55#
56# LICENSE
57#
58#   Copyright (c) 2009 Braden McDaniel <braden@endoframe.com>
59#   Copyright (c) 2013 Bastien Roucaries <roucaries.bastien+autoconf@gmail.com>
60#   Copyright (c) 2016 Felix Chern <idryman@gmail.com>
61#
62#   This program is free software; you can redistribute it and/or modify it
63#   under the terms of the GNU General Public License as published by the
64#   Free Software Foundation; either version 2 of the License, or (at your
65#   option) any later version.
66#
67#   This program is distributed in the hope that it will be useful, but
68#   WITHOUT ANY WARRANTY; without even the implied warranty of
69#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
70#   Public License for more details.
71#
72#   You should have received a copy of the GNU General Public License along
73#   with this program. If not, see <https://www.gnu.org/licenses/>.
74#
75#   As a special exception, the respective Autoconf Macro's copyright owner
76#   gives unlimited permission to copy, distribute and modify the configure
77#   scripts that are the output of Autoconf when processing the Macro. You
78#   need not follow the terms of the GNU General Public License when using
79#   or distributing such scripts, even though portions of the text of the
80#   Macro appear in them. The GNU General Public License (GPL) does govern
81#   all other use of the material that constitutes the Autoconf Macro.
82#
83#   This special exception to the GPL applies to versions of the Autoconf
84#   Macro released by the Autoconf Archive. When you make and distribute a
85#   modified version of the Autoconf Macro, you may extend this special
86#   exception to the GPL to apply to your modified version as well.
87
88#serial 23
89
90# example program
91m4_define([_AX_CHECK_GLU_PROGRAM],
92          [AC_LANG_PROGRAM([[
93# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
94#   include <windows.h>
95# endif
96# ifdef HAVE_GL_GLU_H
97#   include <GL/glu.h>
98# elif defined(HAVE_OPENGL_GLU_H)
99#   include <OpenGL/glu.h>
100# else
101#   error no glu.h
102# endif
103]],[[gluBeginCurve(0)]])])
104
105
106dnl Default include : add windows.h
107dnl see http://www.opengl.org/wiki/Platform_specifics:_Windows
108dnl (acceded 20120801)
109AC_DEFUN([_AX_CHECK_GLU_INCLUDES_DEFAULT],dnl
110[
111  AC_INCLUDES_DEFAULT
112  [
113  # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
114  #   include <windows.h>
115  # endif
116  ]
117])
118
119# check tesselation callback function signature.
120m4_define([_AX_CHECK_GLU_VARARGS_TESSVB_PROGRAM],
121[AC_LANG_PROGRAM([[
122# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
123#   include <windows.h>
124# endif
125# ifdef HAVE_GL_GLU_H
126#   include <GL/glu.h>
127# elif defined(HAVE_OPENGL_GLU_H)
128#   include <OpenGL/glu.h>
129# else
130#   error no glu.h
131# endif
132]],
133[[GLvoid (*func)(...); gluTessCallback(0, 0, func)]])
134])
135
136
137# _AX_CHECK_GLU_SAVE_FLAGS(LIST-OF-FLAGS,[LANG])
138# ----------------------------------------------
139# Save the flags to shell variables.
140# Example: _AX_CHECK_GLU_SAVE_FLAGS([[CFLAGS],[LIBS]]) expands to
141# AC_LANG_PUSH([C])
142# glu_saved_flag_cflags=$CFLAGS
143# glu_saved_flag_libs=$LIBS
144# CFLAGS="$GLU_CFLAGS $CFLAGS"
145# LIBS="$GLU_LIBS $LIBS"
146#
147# Can optionally support other LANG by specifying $2
148AC_DEFUN([_AX_CHECK_GLU_SAVE_FLAGS], [
149 m4_ifval([$2],
150          [AC_LANG_PUSH([$2])],
151          [AC_LANG_PUSH([C])])
152 AX_SAVE_FLAGS_WITH_PREFIX([GLU],[$1]) dnl defined in ax_check_gl
153])
154
155# _AX_CHECK_GLU_RESTORE_FLAGS(LIST-OF-FLAGS)
156# Use this marcro to restore the flags you saved using
157# _AX_CHECK_GLU_SAVE_FLAGS
158#
159# Example: _AX_CHECK_GLU_RESTORE_FLAGS([[CFLAGS],[LIBS]]) expands to
160# CFLAGS="$glu_saved_flag_cflags"
161# LIBS="$glu_saved_flag_libs"
162# AC_LANG_POP([C])
163AC_DEFUN([_AX_CHECK_GLU_RESTORE_FLAGS], [
164 AX_RESTORE_FLAGS_WITH_PREFIX([GLU],[$1]) dnl defined in ax_check_gl
165 m4_ifval([$2],
166          [AC_LANG_POP([$2])],
167          [AC_LANG_POP([C])])
168])
169
170
171# Search headers and export $ax_check_glu_have_headers
172AC_DEFUN([_AX_CHECK_GLU_HEADERS], [
173  _AX_CHECK_GLU_SAVE_FLAGS([CFLAGS])
174  AC_CHECK_HEADERS([$1],
175                   [ax_check_glu_have_headers="yes";],
176                   [],
177                   [_AX_CHECK_GLU_INCLUDES_DEFAULT()])
178  _AX_CHECK_GLU_RESTORE_FLAGS([CFLAGS])
179])
180
181
182# _AX_CHECK_GLU_SEARCH_LIBS(LIBS)
183# -------------------------------
184# Search for a valid GLU lib from $1 and set
185# GLU_LIBS respectively
186AC_DEFUN([_AX_CHECK_GLU_SEARCH_LIBS], [
187 _AX_CHECK_GLU_SAVE_FLAGS([[CFLAGS],[LIBS]])
188 AC_SEARCH_LIBS([gluBeginCurve],[$1],
189 	        [GLU_LIBS="${GLU_LIBS:-$ac_cv_search_gluBeginCurve}"])
190  _AX_CHECK_GLU_RESTORE_FLAGS([[CFLAGS],[LIBS]])
191])
192
193# OSX specific GLU checks
194AC_DEFUN([_AX_CHECK_DARWIN_GLU], [
195  AC_REQUIRE([_WITH_XQUARTZ_GL])
196  AS_IF([test "x$with_xquartz_gl" != "xno"],
197        [GLU_LIBS="${GLU_LIBS:--lGLU}"],
198        [GLU_LIBS="${GLU_LIBS:--framework OpenGL}"])
199])
200
201# AX_CHECK_GLU([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
202# -----------------------------------------------------
203# Checks GLU and provides hooks for success and failures
204AC_DEFUN([AX_CHECK_GLU],[
205  AC_REQUIRE([AC_CANONICAL_HOST])
206  AC_REQUIRE([_WITH_XQUARTZ_GL])
207  AC_REQUIRE([PKG_PROG_PKG_CONFIG])
208  AC_ARG_VAR([GLU_CFLAGS],[C compiler flags for GLU, overriding system check])
209  AC_ARG_VAR([GLU_LIBS],[Linker flags for GLU, overriding system check])
210
211  dnl Setup GLU_CFLAGS and GLU_LIBS
212  AS_CASE([${host}],
213          [*-darwin*],[_AX_CHECK_DARWIN_GLU],
214          [*-cygwin*],[_AX_CHECK_GLU_SEARCH_LIBS([GLU glu MesaGLU glu32])
215                       AC_CHECK_HEADERS([windows.h])],
216          # try first native
217 	  [*-mingw*],[_AX_CHECK_GLU_SEARCH_LIBS([glu32 GLU glu MesaGLU])
218                      AC_CHECK_HEADERS([windows.h])],
219          [PKG_PROG_PKG_CONFIG
220           PKG_CHECK_MODULES([GLU],[glu],
221           [],
222           [_AX_CHECK_GLU_SEARCH_LIBS([GLU glu MesaGLU])])
223          ])
224
225  AS_CASE([$host],
226          [*-darwin*],
227            [AS_IF([test "X$with_xquartz_gl" = "Xno"],
228                   [_AX_CHECK_GLU_HEADERS([OpenGL/glu.h])],
229                   [_AX_CHECK_GLU_HEADERS([GL/glu.h])]
230                   )],
231          [_AX_CHECK_GLU_HEADERS([GL/glu.h])])
232
233  dnl compile test
234  AS_IF([test "X$ax_check_glu_have_headers" = "Xyes"],
235        [AC_CACHE_CHECK([for compiling a minimal OpenGL Utility (GLU) program],
236                        [ax_cv_check_glu_compile],
237                        [_AX_CHECK_GLU_SAVE_FLAGS([CFLAGS])
238                         AC_COMPILE_IFELSE([_AX_CHECK_GLU_PROGRAM],
239                                           [ax_cv_check_glu_compile="yes"],
240                                           [ax_cv_check_glu_compile="no"])
241                         _AX_CHECK_GLU_RESTORE_FLAGS([CFLAGS])])
242         ])
243
244  dnl link test
245  AS_IF([test "X$ax_cv_check_glu_compile" = "Xyes"],
246        [AC_CACHE_CHECK([for linking a minimal GLU program],
247                        [ax_cv_check_glu_link],
248                        [_AX_CHECK_GLU_SAVE_FLAGS([[CFLAGS],[LIBS]])
249                         AC_LINK_IFELSE([_AX_CHECK_GLU_PROGRAM],
250                                        [ax_cv_check_glu_link="yes"],
251                                        [ax_cv_check_glu_link="no"])
252                         _AX_CHECK_GLU_RESTORE_FLAGS([[CFLAGS],[LIBS]])])
253        ])
254
255#
256# Some versions of Mac OS X include a broken interpretation of the GLU
257# tesselation callback function signature.
258  AS_IF([test "X$ax_cv_check_glu_link" = "Xyes"],
259        [AC_CACHE_CHECK([if GLU varargs tesselator is using non-standard form],
260                        [ax_cv_varargs_glu_tesscb],
261                        [_AX_CHECK_GLU_SAVE_FLAGS([CFLAGS],[C++])
262                         AC_COMPILE_IFELSE([_AX_CHECK_GLU_VARARGS_TESSVB_PROGRAM],
263                                           [ax_cv_varargs_glu_tesscb="yes"],
264                                           [ax_cv_varargs_glu_tesscb="no"])
265                         _AX_CHECK_GLU_RESTORE_FLAGS([CFLAGS],[C++])])
266        AS_IF([test "X$ax_cv_varargs_glu_tesscb" = "yes"],
267              [AC_DEFINE([HAVE_VARARGS_GLU_TESSCB], [1],
268                         [Use nonstandard varargs form for the GLU tesselator callback])])
269        ])
270
271  dnl hook
272  AS_IF([test "X$ax_cv_check_glu_link" = "Xyes"],
273        [AC_DEFINE([HAVE_GLU],[1],[Defined if a valid GLU implementation is found.])
274         m4_ifval([$1],
275                  [$1],
276                  [CFLAGS="$GLU_CFLAGS $CFLAGS"
277                   LIBS="$GLU_LIBS $LIBS"])],
278        [m4_ifval([$2],
279                  [$2],
280                  [AC_MSG_ERROR([Could not find a valid GLU implementation])])
281        ])
282])
283