find.c: Remove some "flag" variable usage in DRCFind()
[geda-pcb/pcjc2.git] / m4 / ax_check_gl.m4
blob808e0f43347f34a8a22d416766f7e15ade2c4649
1 # -*- mode: autoconf -*-
3 # AX_CHECK_GL
5 # Check for an OpenGL implementation.  If GL is found, the required compiler
6 # and linker flags are included in the output variables "GL_CFLAGS" and
7 # "GL_LIBS", respectively.  If no usable GL implementation is found, "no_gl"
8 # is set to "yes".
10 # If the header "GL/gl.h" is found, "HAVE_GL_GL_H" is defined.  If the header
11 # "OpenGL/gl.h" is found, HAVE_OPENGL_GL_H is defined.  These preprocessor
12 # definitions may not be mutually exclusive.
14 # version: 2.6
15 # author: Braden McDaniel <braden@endoframe.com>
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2, or (at your option)
20 # any later version.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 # GNU General Public License for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write to the Free Software
29 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 # 02110-1301, USA.
32 # As a special exception, the you may copy, distribute and modify the
33 # configure scripts that are the output of Autoconf when processing
34 # the Macro.  You need not follow the terms of the GNU General Public
35 # License when using or distributing such scripts.
37 AC_DEFUN([AX_CHECK_GL],
38 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
39 AC_REQUIRE([AC_PATH_X])dnl
40 AC_REQUIRE([AC_PROG_SED])dnl
41 AC_REQUIRE([AX_PTHREAD])dnl
43 AC_LANG_PUSH([C])
44 AX_LANG_COMPILER_MS
45 AS_IF([test X$ax_compiler_ms = Xno],
46       [GL_CFLAGS="${PTHREAD_CFLAGS}"; GL_LIBS="${PTHREAD_LIBS}"])
49 # Use x_includes and x_libraries if they have been set (presumably by
50 # AC_PATH_X).
52 AS_IF([test X$no_x != Xyes -a -n "$x_includes"],
53       [GL_CFLAGS="-I$x_includes $GL_CFLAGS"])
55 AC_CHECK_HEADERS([windows.h])
57 ax_save_CPPFLAGS=$CPPFLAGS
58 CPPFLAGS="$GL_CFLAGS $CPPFLAGS"
59 AC_CHECK_HEADERS([GL/gl.h OpenGL/gl.h], , , [
60 # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
61 #   include <windows.h>
62 # endif
64 CPPFLAGS=$ax_save_CPPFLAGS
66 m4_define([AX_CHECK_GL_PROGRAM],
67           [AC_LANG_PROGRAM([[
68 # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
69 #   include <windows.h>
70 # endif
71 # ifdef HAVE_GL_GL_H
72 #   include <GL/gl.h>
73 # elif defined(HAVE_OPENGL_GL_H)
74 #   include <OpenGL/gl.h>
75 # else
76 #   error no gl.h
77 # endif]],
78                            [[glBegin(0)]])])
80 m4_define([AX_CHECK_GL_GLX_PROGRAM],
81           [AC_LANG_PROGRAM([[
82 # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
83 #   include <windows.h>
84 # endif
85 # ifdef HAVE_GL_GL_H
86 #   include <GL/gl.h>
87 # elif defined(HAVE_OPENGL_GL_H)
88 #   include <OpenGL/gl.h>
89 # else
90 #   error no gl.h
91 # endif]],
92                            [[glXQueryVersion(0, 0, 0)]])])
94 AC_CACHE_CHECK([for OpenGL library], [ax_cv_check_gl_libgl],
95 [ax_cv_check_gl_libgl=no
96 case $host_cpu in
97   x86_64) ax_check_gl_libdir=lib64 ;;
98   *)      ax_check_gl_libdir=lib ;;
99 esac
100 ax_save_CPPFLAGS=$CPPFLAGS
101 CPPFLAGS="$CPPFLAGS $GL_CFLAGS"
102 ax_save_LDFLAGS=$LDFLAGS
103 AS_IF([test X$no_x != Xyes -a -n "$x_libraries"],
104       [LDFLAGS="$LDFLAGS -L$x_libraries"])
105 ax_save_LIBS=$LIBS
106 ax_check_libs="-lopengl32 -lGL"
107 for ax_lib in $ax_check_libs; do
108   AS_IF([test X$ax_compiler_ms = Xyes],
109         [ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`],
110         [ax_try_lib=$ax_lib])
111   LDFLAGS="$ax_save_LDFLAGS $GL_LIBS"
112   LIBS="$ax_try_lib $ax_save_LIBS"
113 AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM],
114                [ax_cv_check_gl_libgl=$ax_try_lib; break],
115                [ax_check_gl_nvidia_flags="-L/usr/$ax_check_gl_libdir/nvidia"
116                 LDFLAGS="$ax_save_LDFLAGS $GL_LIBS $ax_check_gl_nvidia_flags"
117                 AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM],
118                                [ax_cv_check_gl_libgl="$ax_check_gl_nvidia_flags $ax_try_lib"; break],
119                                [ax_check_gl_dylib_flag='-dylib_file /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib'
120                                 LDFLAGS="$ax_save_LDFLAGS $GL_LIBS $ax_check_gl_dylib_flag"
121                                 AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM],
122                                                [ax_cv_check_gl_libgl="$ax_check_gl_dylib_flag $ax_try_lib"; break])])])
123 done
126 # If no_x is "yes", we don't want to wind up using a libGL that is
127 # linked with X11.  Test to see if the found libGL includes GLX
128 # functions.  If it does and no_x is "yes", we want to reset
129 # ax_cv_check_gl_libgl back to "no".
131 # Note that LDFLAGS and LIBS should still have whatever values they
132 # had when we broke out of the test loop above; use that.
134 AS_IF([test "X$ax_cv_check_gl_libgl" != Xno],
135       [AC_LINK_IFELSE([AX_CHECK_GL_GLX_PROGRAM],
136                       [AS_IF([test X$no_x = Xyes],
137                              [ax_cv_check_gl_libgl=no])])])
139 LIBS=$ax_save_LIBS
140 AS_IF([test "X$ax_cv_check_gl_libgl" = Xno -a X$no_x = Xyes],
141       [LDFLAGS="$ax_save_LDFLAGS -framework OpenGL"
142       AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM],
143                      [ax_cv_check_gl_libgl='-framework OpenGL'])])
145 LDFLAGS=$ax_save_LDFLAGS
146 CPPFLAGS=$ax_save_CPPFLAGS])
148 AS_IF([test "X$ax_cv_check_gl_libgl" = Xno],
149       [no_gl=yes; GL_CFLAGS=""; GL_LIBS=""],
150       [GL_LIBS="$ax_cv_check_gl_libgl $GL_LIBS"])
151 AC_LANG_POP([C])
153 AC_SUBST([GL_CFLAGS])
154 AC_SUBST([GL_LIBS])
155 ])dnl