ax_check_library.m4 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # ===========================================================================
  2. # http://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) 2012 Brian Aker <brian@tangent.org>
  36. # Copyright (c) 2010 Diego Elio Petteno` <flameeyes@gmail.com>
  37. #
  38. # This program is free software: you can redistribute it and/or modify it
  39. # under the terms of the GNU General Public License as published by the
  40. # Free Software Foundation, either version 3 of the License, or (at your
  41. # option) any later version.
  42. #
  43. # This program is distributed in the hope that it will be useful, but
  44. # WITHOUT ANY WARRANTY; without even the implied warranty of
  45. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  46. # Public License for more details.
  47. #
  48. # You should have received a copy of the GNU General Public License along
  49. # with this program. If not, see <http://www.gnu.org/licenses/>.
  50. #
  51. # As a special exception, the respective Autoconf Macro's copyright owner
  52. # gives unlimited permission to copy, distribute and modify the configure
  53. # scripts that are the output of Autoconf when processing the Macro. You
  54. # need not follow the terms of the GNU General Public License when using
  55. # or distributing such scripts, even though portions of the text of the
  56. # Macro appear in them. The GNU General Public License (GPL) does govern
  57. # all other use of the material that constitutes the Autoconf Macro.
  58. #
  59. # This special exception to the GPL applies to versions of the Autoconf
  60. # Macro released by the Autoconf Archive. When you make and distribute a
  61. # modified version of the Autoconf Macro, you may extend this special
  62. # exception to the GPL to apply to your modified version as well.
  63. #serial 7
  64. AC_DEFUN([AX_CHECK_LIBRARY],
  65. [AC_ARG_VAR($1[_CPPFLAGS],[C preprocessor flags for ]$1[ headers])
  66. AC_ARG_VAR($1[_LDFLAGS],[linker flags for ]$1[ libraries])
  67. AC_CACHE_VAL(AS_TR_SH([ax_cv_have_]$1),
  68. [AX_SAVE_FLAGS
  69. AS_IF([test "x$]$1[_CPPFLAGS" != "x"],
  70. [CPPFLAGS="$CPPFLAGS $]$1[_CPPFLAGS"])
  71. AS_IF([test "x$]$1[_LDFLAGS" != "x"],
  72. [LDFLAGS="$LDFLAGS $]$1[_LDFLAGS"])
  73. AC_CHECK_HEADER($2, [
  74. AC_CHECK_LIB($3, [main],
  75. [AS_TR_SH([ax_cv_have_]$1)=yes],
  76. [AS_TR_SH([ax_cv_have_]$1)=no])
  77. ], [AS_TR_SH([ax_cv_have_]$1)=no])
  78. AX_RESTORE_FLAGS
  79. ])
  80. AS_IF([test "$]AS_TR_SH([ax_cv_have_]$1)[" = "yes"],
  81. [AC_DEFINE([HAVE_]$1, [1], [Define to 1 if ]$1[ is found])
  82. AC_SUBST($1[_CPPFLAGS])
  83. AC_SUBST($1[_LDFLAGS])
  84. AC_SUBST($1[_LIB],[-l]$3)
  85. ifelse([$4], , :, [$4])],
  86. [ifelse([$5], , :, [$5])])
  87. ])