Cleanup around the timeout code.
[awesomized/libmemcached] / m4 / ax_check_library.m4
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
64 #serial 7
65
66 AC_DEFUN([AX_CHECK_LIBRARY],
67 [AC_ARG_VAR($1[_CPPFLAGS],[C preprocessor flags for ]$1[ headers])
68 AC_ARG_VAR($1[_LDFLAGS],[linker flags for ]$1[ libraries])
69
70 AC_CACHE_VAL(AS_TR_SH([ax_cv_have_]$1),
71 [AX_SAVE_FLAGS
72
73 AS_IF([test "x$]$1[_CPPFLAGS" != "x"],
74 [CPPFLAGS="$CPPFLAGS $]$1[_CPPFLAGS"])
75
76 AS_IF([test "x$]$1[_LDFLAGS" != "x"],
77 [LDFLAGS="$LDFLAGS $]$1[_LDFLAGS"])
78
79 AC_CHECK_HEADER($2, [
80 AC_CHECK_LIB($3, [main],
81 [AS_TR_SH([ax_cv_have_]$1)=yes],
82 [AS_TR_SH([ax_cv_have_]$1)=no])
83 ], [AS_TR_SH([ax_cv_have_]$1)=no])
84
85 AX_RESTORE_FLAGS
86 ])
87
88 AS_IF([test "$]AS_TR_SH([ax_cv_have_]$1)[" = "yes"],
89 [AC_DEFINE([HAVE_]$1, [1], [Define to 1 if ]$1[ is found])
90 AC_SUBST($1[_CPPFLAGS])
91 AC_SUBST($1[_LDFLAGS])
92 AC_SUBST($1[_LIB],[-l]$3)
93 ifelse([$4], , :, [$4])],
94 [ifelse([$5], , :, [$5])])
95 ])