diff options
Diffstat (limited to 'm4/ax_check_glut.m4')
-rw-r--r-- | m4/ax_check_glut.m4 | 289 |
1 files changed, 112 insertions, 177 deletions
diff --git a/m4/ax_check_glut.m4 b/m4/ax_check_glut.m4 index b839f0d..75addb7 100644 --- a/m4/ax_check_glut.m4 +++ b/m4/ax_check_glut.m4 @@ -4,17 +4,32 @@ # # SYNOPSIS # -# AX_CHECK_GLUT +# AX_CHECK_GLUT([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) # # DESCRIPTION # -# Check for GLUT. If GLUT is found, the required compiler and linker flags -# are included in the output variables "GLUT_CFLAGS" and "GLUT_LIBS", -# respectively. If GLUT is not found, "no_glut" is set to "yes". +# Checks for GLUT. If a valid GLUT implementation is found, the configure +# script would export the C preprocessor symbol "HAVE_GLUT=1". +# +# If either a valid GLUT header or library was not found, by default the +# configure script would exit on error. This behavior can be overwritten +# by providing a custom "ACTION-IF-NOT-FOUND" hook. +# +# If the header, library was found, and been tested for compiling and +# linking the configuration would export the required compiler flags to +# "GLUT_CFLAGS" and "GLUT_LIBS" environment variables. These two variables +# can also be overwritten by defining the environment variables before +# executing the configure program. If it was predefined, configure would +# not try to overwrite it, but it would still perform the compile and link +# test. Only when the tests succeeded does the configure script to export +# "HAVE_GLUT=1" and to run "ACTION-IF-FOUND" hook. +# +# If user didn't specify the "ACTION-IF-FOUND" hook, the configuration +# would prepend "GLUT_CFLAGS" and "GLUT_LIBS" to "CFLAGS" and "LIBS", like +# many other autoconf macros do. # # If the header "GL/glut.h" is found, "HAVE_GL_GLUT_H" is defined. If the -# header "GLUT/glut.h" is found, HAVE_GLUT_GLUT_H is defined. These -# preprocessor definitions may not be mutually exclusive. +# header "GLUT/glut.h" is found, HAVE_GLUT_GLUT_H is defined. # # You should use something like this in your headers: # @@ -29,10 +44,15 @@ # # error no glut.h # # endif # +# On the OSX platform, you can use the option --with-xquartz-gl to use +# X11/Xquartz GLUT implementation instead of the system built in GLUT +# framework. +# # LICENSE # # Copyright (c) 2009 Braden McDaniel <braden@endoframe.com> # Copyright (c) 2013 Bastien Roucaries <roucaries.bastien+autoconf@gmail.com> +# Copyright (c) 2016 Felix Chern <idryman@gmail.com> # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the @@ -60,25 +80,16 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 14 +#serial 15 -dnl local save flags -AC_DEFUN([_AX_CHECK_GLUT_SAVE_FLAGS], -[dnl -ax_check_glut_saved_libs="${LIBS}" -ax_check_glut_saved_cflags="${CFLAGS}" -ax_check_glut_saved_cppflags="${CPPFLAGS}" -ax_check_glut_saved_ldflags="${LDFLAGS}" +AC_DEFUN([_AX_CHECK_GLUT_SAVE_FLAGS], [ + AX_SAVE_FLAGS_WITH_PREFIX([GLUT],[$1]) dnl defined in ax_check_gl + AC_LANG_PUSH([C]) ]) - -dnl local restore flags -AC_DEFUN([_AX_CHECK_GLUT_RESTORE_FLAGS], -[dnl -LIBS="${ax_check_glut_saved_libs}" -CFLAGS="${ax_check_glut_saved_cflags}" -CPPFLAGS="${ax_check_glut_saved_cppflags}" -LDFLAGS="${ax_check_glut_saved_ldflags}" +AC_DEFUN([_AX_CHECK_GLUT_RESTORE_FLAGS], [ + AX_RESTORE_FLAGS_WITH_PREFIX([GLUT],[$1]) dnl defined in ax_check_gl + AC_LANG_POP([C]) ]) dnl Default include : add windows.h @@ -109,167 +120,91 @@ m4_define([_AX_CHECK_GLUT_PROGRAM], [[glutMainLoop()]])]) -dnl Check headers manually (default case) -AC_DEFUN([_AX_CHECK_GLUT_HEADERS], -[AC_LANG_PUSH([C]) - _AX_CHECK_GLUT_SAVE_FLAGS() - CFLAGS="${GLUT_CFLAGS} ${CFLAGS}" - # see comment in _AX_CHECK_GL_INCLUDES_DEFAULT - AC_CHECK_HEADERS([windows.h],[],[],[AC_INCLUDES_DEFAULT]) - AC_CHECK_HEADERS([GL/glut.h OpenGL/glut.h], - [ax_check_glut_have_headers="yes";break], - [ax_check_glut_have_headers_headers="no"], - [_AX_CHECK_GLUT_INCLUDES_DEFAULT()]) - # do not try darwin specific OpenGl/gl.h - _AX_CHECK_GLUT_RESTORE_FLAGS() - AC_LANG_POP([C]) -]) - -# dnl try to found library (generic case) -# dnl $1 is set to the library to found +# _AX_CHECK_GLUT_MANUAL_LIBS_GENERIC(LIST-OF-LIBS) +# ------------------------------------------------ +# Searches libraries provided in $1, and export variable +# $ax_check_glut_lib_glut AC_DEFUN([_AX_CHECK_GLUT_MANUAL_LIBS_GENERIC], -[dnl - ax_check_glut_manual_libs_generic_extra_libs="$1" - AS_IF([test "X$ax_check_glut_manual_libs_generic_extra_libs" = "X"], - [AC_MSG_ERROR([AX_CHECK_GLUT_MANUAL_LIBS_GENERIC argument must no be empty])]) - - AC_LANG_PUSH([C]) - _AX_CHECK_GLUT_SAVE_FLAGS() - CFLAGS="${GLUT_CFLAGS} ${CFLAGS}" - LIBS="${GLUT_LIBS} ${LIBS}" - AC_SEARCH_LIBS([glutMainLoop],[$ax_check_glut_manual_libs_generic_extra_libs], - [ax_check_glut_lib_opengl="yes"], - [ax_check_glut_lib_opengl="no"]) - AS_CASE([$ac_cv_search_glutMainLoop], - ["none required"],[], - [no],[], - [GLUT_LIBS="${ac_cv_search_glutMainLoop} ${GLU_LIBS}"]) - _AX_CHECK_GLUT_RESTORE_FLAGS() - AC_LANG_PUSH([C]) -]) - - -dnl Check library manually: subroutine must set -dnl $ax_check_glut_lib_opengl={yes,no} -dnl for windows part see -dnl - http://www.transmissionzero.co.uk/computing/using-glut-with-mingw/ -dnl - http://user.xmission.com/~nate/glut.html -AC_DEFUN([_AX_CHECK_GLUT_MANUAL_LIBS], -[AC_REQUIRE([AC_CANONICAL_HOST]) - GLUT_LIBS="${GLUT_LIBS} ${GLU_LIBS}" - AS_CASE([${host}], - # try first cygwin version - [*-cygwin*],[_AX_CHECK_GLUT_MANUAL_LIBS_GENERIC([GLUT glut MesaGLUT freeglut freeglut32 glut32])], - # try first native - [*-mingw*],[_AX_CHECK_GLUT_MANUAL_LIBS_GENERIC([glut32 GLUT glut MesaGLUT freeglut freeglut32])], - [_AX_CHECK_GLUT_MANUAL_LIBS_GENERIC([GLUT glut freeglut MesaGLUT])]) - - AC_CACHE_CHECK([for OpenGL Utility Toolkit (GLUT) libraries],[ax_cv_check_glut_lib_opengl], - [ax_cv_check_glut_lib_opengl="${ax_check_glut_lib_opengl}"]) - ax_check_glut_lib_opengl="${ax_cv_check_glut_lib_opengl}" -]) - -# compile the example program -AC_DEFUN([_AX_CHECK_GLUT_COMPILE], -[dnl - AC_LANG_PUSH([C]) - _AX_CHECK_GLUT_SAVE_FLAGS() - CFLAGS="${GLUT_CFLAGS} ${CFLAGS}" - AC_COMPILE_IFELSE([_AX_CHECK_GLUT_PROGRAM], - [ax_check_glut_compile_opengl="yes"], - [ax_check_glut_compile_opengl="no"]) - _AX_CHECK_GLUT_RESTORE_FLAGS() - AC_LANG_POP([C]) -]) - -# compile the example program (cache) -AC_DEFUN([_AX_CHECK_GLUT_COMPILE_CV], -[dnl - AC_CACHE_CHECK([for compiling a minimal OpenGL Utility Toolkit (GLUT) program],[ax_cv_check_glut_compile_opengl], - [_AX_CHECK_GLUT_COMPILE() - ax_cv_check_glut_compile_opengl="${ax_check_glut_compile_opengl}"]) - ax_check_glut_compile_opengl="${ax_cv_check_glut_compile_opengl}" -]) - -# link the example program -AC_DEFUN([_AX_CHECK_GLUT_LINK], -[dnl - AC_LANG_PUSH([C]) - _AX_CHECK_GLUT_SAVE_FLAGS() - CFLAGS="${GLUT_CFLAGS} ${CFLAGS}" - LIBS="${GLUT_LIBS} ${LIBS}" - LDFLAGS="${GLUT_LDFLAGS} ${LDFLAGS}" - AC_LINK_IFELSE([_AX_CHECK_GLUT_PROGRAM], - [ax_check_glut_link_opengl="yes"], - [ax_check_glut_link_opengl="no"]) - _AX_CHECK_GLUT_RESTORE_FLAGS() - AC_LANG_POP([C]) -]) - -# link the example program (cache) -AC_DEFUN([_AX_CHECK_GLUT_LINK_CV], -[dnl - AC_CACHE_CHECK([for linking a minimal OpenGL Utility Toolkit (GLUT) program],[ax_cv_check_glut_link_opengl], - [_AX_CHECK_GLUT_LINK() - ax_cv_check_glut_link_opengl="${ax_check_glut_link_opengl}"]) - ax_check_glut_link_opengl="${ax_cv_check_glut_link_opengl}" -]) - - -# manually check GLUT -AC_DEFUN([_AX_CHECK_GLUT_MANUAL],dnl [ -GLUT_CFLAGS="${GLUT_CFLAGS} ${GLU_CFLAGS}" -_AX_CHECK_GLUT_HEADERS - -AS_IF([test "X$ax_check_glut_have_headers" = "Xyes"], - [_AX_CHECK_GLUT_MANUAL_LIBS], - [ax_check_glut_lib="no"]) - -AS_IF([test "X$ax_check_glut_lib_opengl" = "Xyes"], - [_AX_CHECK_GLUT_COMPILE_CV()], - [ax_cv_check_glut_compile_opengl="no"]) - -AS_IF([test "X$ax_cv_check_glut_compile_opengl" = "Xyes"], - [_AX_CHECK_GLUT_LINK_CV()], - [ax_cv_check_glut_link_opengl="no"]) + _AX_CHECK_GLUT_SAVE_FLAGS([[CFLAGS],[LIBS]]) + AC_SEARCH_LIBS([glutMainLoop],[$1], + [GLUT_LIBS="${GLUT_LIBS:-$ac_cv_search_glutMainLoop}"]) + _AX_CHECK_GLUT_RESTORE_FLAGS([[CFLAGS],[LIBS]]) +]) -AS_IF([test "X$ax_cv_check_glut_link_opengl" = "Xyes"], - [no_glut="no"], - [no_glut="yes"]) +# Wrapper macro to check GLUT header +AC_DEFUN([_AX_CHECK_GLUT_HEADER],[ + _AX_CHECK_GLUT_SAVE_FLAGS([CFLAGS]) + AC_CHECK_HEADERS([$1], + [ax_check_glut_have_headers=yes]) + _AX_CHECK_GLUT_RESTORE_FLAGS([CFLAGS]) ]) -# main entry point +# AX_CHECK_GLUT_LIB([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# --------------------------------------------------------- +# Checks GLUT headers and library and provides hooks for success and failures. AC_DEFUN([AX_CHECK_GLUT], -[dnl - AC_REQUIRE([AX_CHECK_GL])dnl - AC_REQUIRE([AX_CHECK_GLU])dnl - - # set flags - no_glut="yes" - have_GLUT="no" - have_glut="no" - - _AX_CHECK_GLUT_MANUAL - - AC_MSG_CHECKING([for a working OpenGL Utility Toolkit (GLUT) implementation]) - AS_IF([test "X$no_glut" = "Xno"], - [have_GLUT="yes" - have_glut="yes" - AC_MSG_RESULT([yes]) - AC_MSG_CHECKING([for CFLAGS needed for OpenGL Utility Toolkit (GLUT)]) - AC_MSG_RESULT(["${GLUT_CFLAGS}"]) - AC_MSG_CHECKING([for LIBS needed for OpenGL Utility Toolkit (GLUT)]) - AC_MSG_RESULT(["${GLUT_LIBS}"]) - AC_MSG_CHECKING([for LDFLAGS needed for OpenGL Utility Toolkit (GLUT)]) - AC_MSG_RESULT(["${GLUT_LDFLAGS}"])], - [AC_MSG_RESULT([no]) - GLUT_CFLAGS="" - GLUT_LIBS="" - GLUT_LDFLAGS=""]) +[AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([_WITH_XQUARTZ_GL]) + AC_ARG_VAR([GLUT_CFLAGS],[C compiler flags for GLUT, overriding configure script defaults]) + AC_ARG_VAR([GLUT_LIBS],[Linker flags for GLUT, overriding configure script defaults]) + + AS_CASE([${host}], + [*-darwin*],[AS_IF([test "x$with_xquartz_gl" != "xno"], + [GLUT_LIBS="${GLUT_LIBS:--lGLUT}"], + [GLUT_LIBS="${GLUT_LIBS:--framework GLUT}"])], + [*-cygwin*|*-mingw*],[ + _AX_CHECK_GLUT_MANUAL_LIBS_GENERIC([glut32 glut]) + AC_CHECK_HEADERS([windows.h]) + ], + [_AX_CHECK_GLUT_MANUAL_LIBS_GENERIC([glut]) + ]) dnl host specific checks + + dnl checks header + AS_CASE([${host}], + [*-darwin*],[AS_IF([test "x$with_xquartz_gl" = "xno"], + [_AX_CHECK_GLUT_HEADER([GLUT/glut.h])], + [_AX_CHECK_GLUT_HEADER([GL/glut.h])] + )], + [_AX_CHECK_GLUT_HEADER([GL/glut.h])]) + + dnl compile + AS_IF([test "X$ax_check_glut_have_headers" = "Xyes"], + [AC_CACHE_CHECK([for compiling a minimal GLUT program], + [ax_cv_check_glut_compile], + [_AX_CHECK_GLUT_SAVE_FLAGS([CFLAGS]) + AC_COMPILE_IFELSE([_AX_CHECK_GLUT_PROGRAM], + [ax_cv_check_glut_compile="yes"], + [ax_cv_check_glut_compile="no"]) + _AX_CHECK_GLUT_RESTORE_FLAGS([CFLAGS]) + ]) + ]) + + dnl link + AS_IF([test "X$ax_cv_check_glut_compile" = "Xyes"], + [AC_CACHE_CHECK([for linking a minimal GLUT program], + [ax_cv_check_glut_link], + [_AX_CHECK_GLUT_SAVE_FLAGS([[CFLAGS],[LIBS]]) + AC_LINK_IFELSE([_AX_CHECK_GLUT_PROGRAM], + [ax_cv_check_glut_link="yes"], + [ax_cv_check_glut_link="no"]) + _AX_CHECK_GLUT_RESTORE_FLAGS([[CFLAGS],[LIBS]]) + ]) + ]) + + dnl hook + AS_IF([test "X$ax_cv_check_glut_link" = "Xyes"], + [AC_DEFINE([HAVE_GLUT], [1], [Defined if a valid GLUT implementation is found]) + m4_ifval([$1], + [$1], + [CFLAGS="$GLUT_CFLAGS $CFLAGS" + LIBS="$GLUT_LIBS $LIBS"]) + ], + [m4_ifval([$2], + [$2], + [AC_MSG_ERROR([Could not find a valid GLUT implementation])] + ) + ]) - AC_SUBST([GLUT_CFLAGS]) - AC_SUBST([GLUT_LIBS]) - AC_SUBST([GLUT_LDFLAGS]) ]) |