add simple test for command()
[nsca-ng.git] / m4 / ev.m4
blob5927381fc861f2530f3cd20962c7b8212e4c1de8
1 # Copyright (c) 2013 Holger Weiss <holger@weiss.in-berlin.de>
2 # All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
7 # 1. Redistributions of source code must retain the above copyright notice, this
8 #    list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright notice,
11 #    this list of conditions and the following disclaimer in the documentation
12 #    and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 # DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 # NSCA_LIB_EV
26 # -----------
27 # Check the availability of libev 4.00 or newer.  If it's not found, or if the
28 # user specified "--with-ev=embedded", we use our internal copy of libev and set
29 # $nsca_lib_ev_embedded to "yes".  Otherwise, we set $nsca_lib_ev_embedded to
30 # "no".  Either way, we set the output variables EVCPPFLAGS, EVLDFLAGS, and
31 # EVLIBS to appropriate values.  (Why are there no underscores in these variable
32 # names?  Because Automake treats names like "foo_CPPFLAGS" specially.)
33 AC_DEFUN([NSCA_LIB_EV],
35   nsca_save_CPPFLAGS=$CPPFLAGS
36   nsca_save_LDFLAGS=$LDFLAGS
37   nsca_lib_ev_embedded=maybe
38   AC_ARG_WITH([ev],
39     [AS_HELP_STRING([--with-ev=PATH],
40       [use the libev library in PATH])],
41     [nsca_ev_dir=$with_ev],
42     [nsca_ev_dir=yes])
43   AC_MSG_CHECKING([whether libev is desired])
44   AS_CASE([$nsca_ev_dir],
45     [no],
46       [AC_MSG_RESULT([no])
47        AC_MSG_ERROR([building without libev is not supported])],
48     [yes|external],
49       [AS_IF([test "x$nsca_ev_dir" = xexternal], [nsca_lib_ev_embedded=no])
50        AC_MSG_RESULT([yes])
51        AC_MSG_CHECKING([for the location of libev])
52        nsca_ev_dir=unknown
53        for _nsca_ev_dir in /usr /usr/local /usr/pkg
54        do dnl Solaris 10 doesn't have "test -e".
55          AS_IF([test -r "$_nsca_ev_dir/include/ev.h"],
56            [nsca_ev_dir=$_nsca_ev_dir
57             break])
58        done
59       AS_IF([test "x$nsca_ev_dir" != xunknown],
60         [AC_MSG_RESULT([$nsca_ev_dir])],
61         [AC_MSG_RESULT([not found, continuing anyway])])],
62     [embedded],
63       [AC_MSG_RESULT([yes, the bundled copy])
64        _NSCA_LIB_EV_EMBEDDED
65        nsca_lib_ev_embedded=yes],
66     [AC_MSG_RESULT([yes])
67      nsca_lib_ev_embedded=no])
68   AS_IF([test "x$nsca_ev_dir" != xembedded &&
69     test "x$nsca_ev_dir" != xunknown &&
70     test "x$nsca_ev_dir" != x/usr],
71     [EVCPPFLAGS="-I$nsca_ev_dir/include"
72      EVLDFLAGS="-L$nsca_ev_dir/lib"
73      CPPFLAGS="$EVCPPFLAGS $CPPFLAGS"
74      LDFLAGS="$EVLDFLAGS $LDFLAGS"])
75   AS_IF([test "x$nsca_lib_ev_embedded" != xyes],
76     [AC_CHECK_HEADER([ev.h],
77       [AC_CHECK_LIB([ev], [ev_version_major],
78         [EVLIBS="-lev"
79          AC_CHECK_LIB([ev], [ev_run], [:],
80            [_NSCA_LIB_EV_ERROR([libev too old], [$nsca_lib_ev_embedded])
81             nsca_lib_ev_embedded=yes])],
82         [_NSCA_LIB_EV_ERROR([cannot link with libev], [$nsca_lib_ev_embedded])
83          nsca_lib_ev_embedded=yes])],
84       [_NSCA_LIB_EV_ERROR([libev header not found], [$nsca_lib_ev_embedded])
85        nsca_lib_ev_embedded=yes])])
86   AS_IF([test "x$nsca_lib_ev_embedded" = xyes],
87     [unset EVCPPFLAGS EVLDFLAGS EVLIBS],
88     [nsca_lib_ev_embedded=no])
89   AC_SUBST([EVCPPFLAGS])
90   AC_SUBST([EVLDFLAGS])
91   AC_SUBST([EVLIBS])
92   AC_DEFINE([EV_COMPAT3], [0],
93     [Define to 1 if libev 3.x compatibility is desired.])
94   CPPFLAGS=$nsca_save_CPPFLAGS
95   LDFLAGS=$nsca_save_LDFLAGS
96 ])# NSCA_LIB_EV
98 # _NSCA_LIB_EV_EMBEDDED
99 # ---------------------
100 # Arrange for using the bundled copy of libev.
101 AC_DEFUN([_NSCA_LIB_EV_EMBEDDED],
103   dnl Why don't we use m4_include?  The difference is that m4_include warns
104   dnl against multiple inclusions, while the builtin does not.  Multiple
105   dnl inclusions yield unexpected results if the included file calls m4_define
106   dnl without quoting the first argument.  However, lib/ev/libev.m4 doesn't do
107   dnl that, so it should be safe to include it more than once.
108   m4_builtin([include], [lib/ev/libev.m4])
109   AC_DEFINE([EV_MULTIPLICITY], [0],
110     [Define to 1 if the bundled libev should support multiple event loops.])
111   AC_DEFINE([EV_MINPRI], [-1],
112     [Define to the smallest allowed priority in the bundled libev.])
113   AC_DEFINE([EV_MAXPRI], [1],
114     [Define to the largest allowed priority in the bundled libev.])
115   AC_DEFINE([EV_VERIFY], [0],
116     [Define to the desired internal verification level of the bundled libev.])
117   AC_DEFINE([ECB_AVOID_PTHREADS], [1], dnl Otherwise, building on AIX will fail.
118     [Define to 1 if memory fences aren't needed for the bundled libev.])
119 ])# _NSCA_LIB_EV_EMBEDDED
121 # _NSCA_LIB_EV_ERROR(MESSAGE, USE_EMBEDDED_EV)
122 # --------------------------------------------
123 # If USE_EMBEDDED_EV is set to "no", bail out with the specified error MESSAGE.
124 # Otherwise, spit out the specified MESSAGE and a note that we're going to use
125 # the included copy of libev, and then call _NSCA_LIB_EV_EMBEDDED.
126 AC_DEFUN([_NSCA_LIB_EV_ERROR],
128   AS_IF([test "x$2" = xno],
129     [AC_MSG_ERROR([$1])],
130     [AC_MSG_NOTICE([$1, using bundled copy])
131      _NSCA_LIB_EV_EMBEDDED])
132 ])# _NSCA_LIB_EV_ERROR
134 dnl vim:set joinspaces textwidth=80: