add simple test for command()
[nsca-ng.git] / m4 / systemd.m4
blobbc251c0a95b6f32537bfae8fc91f82d3efc5f910
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_SYSTEMD
26 # ----------------
27 # Check the availability of systemd.  If the systemd (or the old systemd-daemon)
28 # library is found, we define HAVE_SYSTEMD_SD_DAEMON_H to 1.  We then also set
29 # the output variables SYSTEMDCPPFLAGS, SYSTEMDLDFLAGS, and SYSTEMDLIBS to
30 # appropriate values.  (Why are there no underscores in these variable names?
31 # Because Automake treats names like "foo_CPPFLAGS" specially.)
32 AC_DEFUN([NSCA_LIB_SYSTEMD],
34   nsca_save_CPPFLAGS=$CPPFLAGS
35   nsca_save_LDFLAGS=$LDFLAGS
36   nsca_systemd_dir=unknown
37   AC_ARG_WITH([systemd],
38     [AS_HELP_STRING([--with-systemd=PATH],
39       [use the systemd library in PATH])],
40     [nsca_with_systemd=$with_systemd],
41     [nsca_with_systemd=maybe])
42   AC_MSG_CHECKING([whether systemd is desired])
43   AS_CASE([$nsca_with_systemd],
44     [no],
45       [AC_MSG_RESULT([no])],
46     [yes|maybe],
47       [AC_MSG_RESULT([$nsca_with_systemd])
48        AC_MSG_CHECKING([for the location of systemd])
49        for _nsca_systemd_dir in "$ac_pwd/lib/systemd" /usr /usr/local /usr/pkg
50        do dnl Solaris 10 doesn't have "test -e".
51          AS_IF([test -r "$_nsca_systemd_dir/include/systemd/sd-daemon.h"],
52            [nsca_systemd_dir=$_nsca_systemd_dir
53             break])
54        done
55        AS_IF([test "x$nsca_systemd_dir" != xunknown],
56          [AC_MSG_RESULT([$nsca_systemd_dir])
57           AS_IF([test "x$nsca_with_systemd" = xmaybe],
58             [nsca_with_systemd=yes])],
59          [AC_MSG_RESULT([not found])
60           AS_IF([test "x$nsca_with_systemd" = xmaybe],
61             [nsca_with_systemd=no])])],
62     [AC_MSG_RESULT([yes])
63      nsca_with_systemd=yes
64      nsca_systemd_dir=$nsca_with_systemd])
65   AS_IF([test "x$nsca_with_systemd" = xyes],
66     [AS_IF([test "x$nsca_systemd_dir" != xunknown &&
67       test "x$nsca_systemd_dir" != x/usr],
68       [SYSTEMDCPPFLAGS="-I$nsca_systemd_dir/include"
69        SYSTEMDLDFLAGS="-L$nsca_systemd_dir/lib"
70        CPPFLAGS="$SYSTEMDCPPFLAGS $CPPFLAGS"
71        LDFLAGS="$SYSTEMDLDFLAGS $LDFLAGS"])
72      AC_CHECK_HEADERS([systemd/sd-daemon.h], [],
73        [AC_MSG_ERROR([systemd header file not found])])
74      AC_CHECK_LIB([systemd], [sd_notify],
75        [SYSTEMDLIBS='-lsystemd'],
76        [AC_CHECK_LIB([systemd-daemon], [sd_notify],
77          [SYSTEMDLIBS='-lsystemd-daemon'],
78          [AC_MSG_FAILURE([cannot link with systemd-daemon library])])])])
79   AC_SUBST([SYSTEMDCPPFLAGS])
80   AC_SUBST([SYSTEMDLDFLAGS])
81   AC_SUBST([SYSTEMDLIBS])
82   CPPFLAGS=$nsca_save_CPPFLAGS
83   LDFLAGS=$nsca_save_LDFLAGS
84 ])# NSCA_LIB_SYSTEMD
86 dnl vim:set joinspaces textwidth=80: