1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_check_library.html
3 # ===========================================================================
7 # AX_CHECK_LIBRARY(VARIABLE-PREFIX, HEADER-FILE, LIBRARY-FILE,
8 # [ACTION-IF-FOUND], [ACTION-IF-NOT_FOUND])
12 # Provides a generic test for a given library, similar in concept to the
13 # PKG_CHECK_MODULES macro used by pkg-config.
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.
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.
25 # If the library is find, HAVE_PREFIX is defined, and in all cases
26 # PREFIX_LDFLAGS and PREFIX_CPPFLAGS are substituted.
30 # AX_CHECK_LIBRARY([LIBEVENT], [event.h], [event], [],
31 # [AC_MSG_ERROR([Unable to find libevent])])
35 # Copyright (c) 2010 Diego Elio Petteno` <flameeyes@gmail.com>
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.
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.
47 # You should have received a copy of the GNU General Public License along
48 # with this program. If not, see <http://www.gnu.org/licenses/>.
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.
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.
65 AC_DEFUN([AX_CHECK_LIBRARY], [
66 AC_ARG_VAR($1[_CPPFLAGS], [C preprocessor flags for ]$1[ headers])
67 AC_ARG_VAR($1[_LDFLAGS], [linker flags for ]$1[ libraries])
69 AC_CACHE_VAL(AS_TR_SH([ax_cv_have_]$1),
70 [save_CPPFLAGS="$CPPFLAGS"
71 save_LDFLAGS="$LDFLAGS"
74 AS_IF([test "x$]$1[_CPPFLAGS" != "x"],
75 [CPPFLAGS="$CPPFLAGS $]$1[_CPPFLAGS"])
77 AS_IF([test "x$]$1[_LDFLAGS" != "x"],
78 [LDFLAGS="$LDFLAGS $]$1[_LDFLAGS"])
81 AC_CHECK_LIB($3, [main],
82 [AS_TR_SH([ax_cv_have_]$1)=yes],
83 [AS_TR_SH([ax_cv_have_]$1)=no])
84 ], [AS_TR_SH([ax_cv_have_]$1)=no])
86 CPPFLAGS="$save_CPPFLAGS"
87 LDFLAGS="$save_LDFLAGS"
91 AS_IF([test "$]AS_TR_SH([ax_cv_have_]$1)[" = "yes"],
92 AC_DEFINE([HAVE_]$1, [1], [Define to 1 if ]$1[ is found])
93 m4_ifnblank([$4], [$4]),
94 m4_ifnblank([$5], [$5]))