ax_check_library.m4 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_check_library.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_CHECK_LIBRARY(VARIABLE-PREFIX, HEADER-FILE, LIBRARY-FILE,
  8. # [ACTION-IF-FOUND], [ACTION-IF-NOT_FOUND])
  9. #
  10. # DESCRIPTION
  11. #
  12. # Provides a generic test for a given library, similar in concept to the
  13. # PKG_CHECK_MODULES macro used by pkg-config.
  14. #
  15. # Most simplest libraries can be checked against simply through the
  16. # presence of a header file and a library to link to. This macro allows to
  17. # wrap around the test so that it doesn't have to be recreated each time.
  18. #
  19. # Rather than define --with-$LIBRARY arguments, it uses variables in the
  20. # same way that PKG_CHECK_MODULES does. It doesn't, though, use the same
  21. # names, since you shouldn't provide a value for LIBS or CFLAGS but rather
  22. # for LDFLAGS and CPPFLAGS, to tell the linker and compiler where to find
  23. # libraries and headers respectively.
  24. #
  25. # If the library is find, HAVE_PREFIX is defined, and in all cases
  26. # PREFIX_LDFLAGS and PREFIX_CPPFLAGS are substituted.
  27. #
  28. # Example:
  29. #
  30. # AX_CHECK_LIBRARY([LIBEVENT], [event.h], [event], [],
  31. # [AC_MSG_ERROR([Unable to find libevent])])
  32. #
  33. # LICENSE
  34. #
  35. # Copyright (c) 2010 Diego Elio Petteno` <flameeyes@gmail.com>
  36. #
  37. # This program is free software: you can redistribute it and/or modify it
  38. # under the terms of the GNU General Public License as published by the
  39. # Free Software Foundation, either version 3 of the License, or (at your
  40. # option) any later version.
  41. #
  42. # This program is distributed in the hope that it will be useful, but
  43. # WITHOUT ANY WARRANTY; without even the implied warranty of
  44. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  45. # Public License for more details.
  46. #
  47. # You should have received a copy of the GNU General Public License along
  48. # with this program. If not, see <https://www.gnu.org/licenses/>.
  49. #
  50. # As a special exception, the respective Autoconf Macro's copyright owner
  51. # gives unlimited permission to copy, distribute and modify the configure
  52. # scripts that are the output of Autoconf when processing the Macro. You
  53. # need not follow the terms of the GNU General Public License when using
  54. # or distributing such scripts, even though portions of the text of the
  55. # Macro appear in them. The GNU General Public License (GPL) does govern
  56. # all other use of the material that constitutes the Autoconf Macro.
  57. #
  58. # This special exception to the GPL applies to versions of the Autoconf
  59. # Macro released by the Autoconf Archive. When you make and distribute a
  60. # modified version of the Autoconf Macro, you may extend this special
  61. # exception to the GPL to apply to your modified version as well.
  62. #serial 5
  63. AC_DEFUN([AX_CHECK_LIBRARY], [
  64. AC_ARG_VAR($1[_CPPFLAGS], [C preprocessor flags for ]$1[ headers])
  65. AC_ARG_VAR($1[_LDFLAGS], [linker flags for ]$1[ libraries])
  66. AC_CACHE_VAL(AS_TR_SH([ax_cv_have_]$1),
  67. [save_CPPFLAGS="$CPPFLAGS"
  68. save_LDFLAGS="$LDFLAGS"
  69. save_LIBS="$LIBS"
  70. AS_IF([test "x$]$1[_CPPFLAGS" != "x"],
  71. [CPPFLAGS="$CPPFLAGS $]$1[_CPPFLAGS"])
  72. AS_IF([test "x$]$1[_LDFLAGS" != "x"],
  73. [LDFLAGS="$LDFLAGS $]$1[_LDFLAGS"])
  74. AC_CHECK_HEADER($2, [
  75. AC_CHECK_LIB($3, [main],
  76. [AS_TR_SH([ax_cv_have_]$1)=yes],
  77. [AS_TR_SH([ax_cv_have_]$1)=no])
  78. ], [AS_TR_SH([ax_cv_have_]$1)=no])
  79. CPPFLAGS="$save_CPPFLAGS"
  80. LDFLAGS="$save_LDFLAGS"
  81. LIBS="$save_LIBS"
  82. ])
  83. AS_IF([test "$]AS_TR_SH([ax_cv_have_]$1)[" = "yes"],
  84. AC_DEFINE([HAVE_]$1, [1], [Define to 1 if ]$1[ is found])
  85. [$4],
  86. [$5])
  87. ])