]> git.ipfire.org Git - thirdparty/pdns.git/blob - m4/systemd.m4
Merge pull request #4195 from zeha/api-nameservers-or-ns-rrset
[thirdparty/pdns.git] / m4 / systemd.m4
1 # systemd.m4 - Macros to check for and enable systemd -*- Autoconf -*-
2 #
3 # Copyright (C) 2014 Luis R. Rodriguez <mcgrof@suse.com>
4 # Copyright (C) 2016 Pieter Lexis <pieter.lexis@powerdns.com>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 #serial 2
21
22 dnl Some optional path options
23 AC_DEFUN([AX_SYSTEMD_OPTIONS], [
24 AC_ARG_WITH(systemd, [ --with-systemd set directory for systemd service files],
25 SYSTEMD_DIR="$withval", SYSTEMD_DIR="")
26 AC_SUBST(SYSTEMD_DIR)
27
28 AC_ARG_WITH(systemd, [ --with-systemd-modules-load set directory for systemd modules load files],
29 SYSTEMD_MODULES_LOAD="$withval", SYSTEMD_MODULES_LOAD="")
30 AC_SUBST(SYSTEMD_MODULES_LOAD)
31 ])
32
33 AC_DEFUN([AX_ENABLE_SYSTEMD_OPTS], [
34 AX_ARG_DEFAULT_ENABLE([systemd], [Disable systemd support])
35 AX_SYSTEMD_OPTIONS()
36 ])
37
38 AC_DEFUN([AX_ALLOW_SYSTEMD_OPTS], [
39 AX_ARG_DEFAULT_DISABLE([systemd], [Enable systemd support], [$1])
40 AX_SYSTEMD_OPTIONS()
41 ])
42
43 AC_DEFUN([AX_CHECK_SYSTEMD_LIBS], [
44 AC_REQUIRE([AX_CHECK_SYSTEMD_DETECT_AND_ENABLE])
45 AS_IF([test "x$libsystemd" = x], [
46 AC_MSG_ERROR([Unable to find a suitable libsystemd library])
47 ])
48
49 PKG_CHECK_MODULES([SYSTEMD], [$libsystemd_daemon])
50 dnl pkg-config older than 0.24 does not set these for
51 dnl PKG_CHECK_MODULES() worth also noting is that as of version 208
52 dnl of systemd pkg-config --cflags currently yields no extra flags yet.
53 AC_SUBST([SYSTEMD_CFLAGS])
54 AC_SUBST([SYSTEMD_LIBS])
55
56 AS_IF([test "x$SYSTEMD_DIR" = x], [
57 dnl In order to use the line below we need to fix upstream systemd
58 dnl to properly ${prefix} for child variables in
59 dnl src/core/systemd.pc.in but this is a bit complex at the
60 dnl moment as they depend on another rootprefix, which can vary
61 dnl from prefix in practice. We provide our own definition as we
62 dnl *know* where systemd will dump this to, but this does limit
63 dnl us to stick to a non custom systemdsystemunitdir, dnl to work
64 dnl around this we provide the additional configure option
65 dnl --with-systemd where you can specify the directory for the unit
66 dnl files. It would also be best to just extend the upstream
67 dnl pkg-config pkg.m4 with an AC_DEFUN() to do this neatly.
68 dnl SYSTEMD_DIR="`$PKG_CONFIG --define-variable=prefix=$PREFIX --variable=systemdsystemunitdir systemd`"
69 SYSTEMD_DIR="\$(prefix)/lib/systemd/system/"
70 ], [])
71
72 AS_IF([test "x$SYSTEMD_DIR" = x], [
73 AC_MSG_ERROR([SYSTEMD_DIR is unset])
74 ], [])
75
76 dnl There is no variable for this yet for some reason
77 AS_IF([test "x$SYSTEMD_MODULES_LOAD" = x], [
78 SYSTEMD_MODULES_LOAD="\$(prefix)/lib/modules-load.d/"
79 ], [])
80
81 AS_IF([test "x$SYSTEMD_MODULES_LOAD" = x], [
82 AC_MSG_ERROR([SYSTEMD_MODULES_LOAD is unset])
83 ], [])
84 ])
85
86 AC_DEFUN([AX_CHECK_SYSTEMD], [
87 dnl Respect user override to disable
88 AS_IF([test "x$enable_systemd" != "xno"], [
89 AS_IF([test "x$systemd" = "xy" ], [
90 AC_DEFINE([HAVE_SYSTEMD], [1], [Systemd available and enabled])
91 systemd=y
92 AX_CHECK_SYSTEMD_LIBS()
93 ],[systemd=n])
94 ],[systemd=n])
95 ])
96
97 AC_DEFUN([AX_CHECK_SYSTEMD_DETECT_AND_ENABLE], [
98 AC_CHECK_HEADER([systemd/sd-daemon.h], [
99 for libname in systemd-daemon systemd; do
100 AC_CHECK_LIB([$libname], [sd_listen_fds], [
101 libsystemd_daemon="lib$libname"
102 systemd=y
103 libsystemd=y
104 ])
105 done
106 ])
107 ])
108
109 dnl Enables systemd by default and requires a --disable-systemd option flag
110 dnl to configure if you want to disable.
111 AC_DEFUN([AX_ENABLE_SYSTEMD], [
112 AX_ENABLE_SYSTEMD_OPTS()
113 AX_CHECK_SYSTEMD()
114 ])
115
116 dnl Systemd will be disabled by default and requires you to run configure with
117 dnl --enable-systemd to look for and enable systemd.
118 AC_DEFUN([AX_ALLOW_SYSTEMD], [
119 AX_ALLOW_SYSTEMD_OPTS()
120 AX_CHECK_SYSTEMD()
121 ])
122
123 dnl Systemd will be disabled by default but if your build system is detected
124 dnl to have systemd build libraries it will be enabled. You can always force
125 dnl disable with --disable-systemd
126 AC_DEFUN([AX_AVAILABLE_SYSTEMD], [
127 AX_ALLOW_SYSTEMD_OPTS([, but will be enabled when libraries are found])
128 AX_CHECK_SYSTEMD_DETECT_AND_ENABLE()
129 AX_CHECK_SYSTEMD()
130 ])