]>
Commit | Line | Data |
---|---|---|
7e9c43b4 PL |
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], [ | |
56d30a9c | 39 | AX_ARG_DEFAULT_DISABLE([systemd], [Enable systemd support], [$1]) |
7e9c43b4 PL |
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], [ | |
56d30a9c | 127 | AX_ALLOW_SYSTEMD_OPTS([, but will be enabled when libraries are found]) |
7e9c43b4 PL |
128 | AX_CHECK_SYSTEMD_DETECT_AND_ENABLE() |
129 | AX_CHECK_SYSTEMD() | |
130 | ]) | |
a3dfb540 RG |
131 | |
132 | AC_DEFUN([AX_CHECK_SYSTEMD_FEATURES], [ | |
1f988403 PL |
133 | AS_IF([test x"$systemd" = "xy"], [ |
134 | AC_PATH_PROG([SYSTEMCTL], [systemctl], [no]) | |
135 | AS_IF([test "$SYSTEMCTL" = "no"], | |
136 | [AC_MSG_ERROR([systemctl not found])], [ | |
137 | _systemd_version=`${SYSTEMCTL} --version|head -1 |cut -d" " -f 2` | |
138 | if test $_systemd_version -ge 183; then | |
139 | systemd_private_tmp=y | |
140 | fi | |
141 | if test $_systemd_version -ge 209; then | |
142 | systemd_system_call_architectures=y | |
143 | systemd_private_devices=y | |
144 | fi | |
145 | if test $_systemd_version -ge 211; then | |
146 | systemd_restrict_address_families=y | |
147 | fi | |
148 | if test $_systemd_version -ge 214; then | |
149 | systemd_protect_system=y | |
150 | systemd_protect_home=y | |
151 | fi | |
152 | if test $_systemd_version -ge 231; then | |
153 | systemd_restrict_realtime=y | |
154 | systemd_memory_deny_write_execute=y | |
155 | fi | |
156 | if test $_systemd_version -ge 232; then | |
157 | systemd_protect_control_groups=y | |
158 | systemd_protect_kernel_modules=y | |
159 | systemd_protect_kernel_tunables=y | |
160 | systemd_remove_ipc=y | |
161 | systemd_dynamic_user=y | |
162 | systemd_private_users=y | |
163 | systemd_protect_system_strict=y | |
164 | fi | |
165 | if test $_systemd_version -ge 233; then | |
166 | systemd_restrict_namespaces=y | |
167 | fi | |
168 | if test $_systemd_version -ge 235; then | |
169 | systemd_lock_personality=y | |
170 | # while SystemCallFilter is technically available starting with 187, | |
171 | # we use the pre-defined call filter sets that have been introduced later. | |
172 | # Initial support for these landed in 231 | |
173 | # @filesystem @reboot @swap in 233 | |
174 | # @aio, @sync, @chown, @setuid, @memlock, @signal and @timer in 235 | |
175 | systemd_system_call_filter=y | |
176 | fi | |
177 | ]) | |
178 | ]) | |
a3dfb540 RG |
179 | AM_CONDITIONAL([HAVE_SYSTEMD_DYNAMIC_USER], [ test x"$systemd_dynamic_user" = "xy" ]) |
180 | AM_CONDITIONAL([HAVE_SYSTEMD_LOCK_PERSONALITY], [ test x"$systemd_lock_personality" = "xy" ]) | |
181 | AM_CONDITIONAL([HAVE_SYSTEMD_MEMORY_DENY_WRITE_EXECUTE], [ test x"$systemd_memory_deny_write_execute" = "xy" ]) | |
182 | AM_CONDITIONAL([HAVE_SYSTEMD_PRIVATE_DEVICES], [ test x"$systemd_private_devices" = "xy" ]) | |
183 | AM_CONDITIONAL([HAVE_SYSTEMD_PRIVATE_TMP], [ test x"$systemd_private_tmp" = "xy" ]) | |
184 | AM_CONDITIONAL([HAVE_SYSTEMD_PRIVATE_USERS], [ test x"$systemd_private_users" = "xy" ]) | |
185 | AM_CONDITIONAL([HAVE_SYSTEMD_PROTECT_CONTROL_GROUPS], [ test x"$systemd_protect_control_groups" = "xy" ]) | |
186 | AM_CONDITIONAL([HAVE_SYSTEMD_PROTECT_HOME], [ test x"$systemd_protect_home" = "xy" ]) | |
187 | AM_CONDITIONAL([HAVE_SYSTEMD_PROTECT_KERNEL_MODULES], [ test x"$systemd_protect_kernel_modules" = "xy" ]) | |
188 | AM_CONDITIONAL([HAVE_SYSTEMD_PROTECT_KERNEL_TUNABLES], [ test x"$systemd_protect_kernel_tunables" = "xy" ]) | |
189 | AM_CONDITIONAL([HAVE_SYSTEMD_PROTECT_SYSTEM], [ test x"$systemd_protect_system" = "xy" ]) | |
190 | AM_CONDITIONAL([HAVE_SYSTEMD_PROTECT_SYSTEM_STRICT], [ test x"$systemd_protect_system_strict" = "xy" ]) | |
191 | AM_CONDITIONAL([HAVE_SYSTEMD_REMOVE_IPC], [ test x"$systemd_remove_ipc" = "xy" ]) | |
192 | AM_CONDITIONAL([HAVE_SYSTEMD_RESTRICT_ADDRESS_FAMILIES], [ test x"$systemd_restrict_address_families" = "xy" ]) | |
193 | AM_CONDITIONAL([HAVE_SYSTEMD_RESTRICT_NAMESPACES], [ test x"$systemd_restrict_namespaces" = "xy" ]) | |
194 | AM_CONDITIONAL([HAVE_SYSTEMD_RESTRICT_REALTIME], [ test x"$systemd_restrict_realtime" = "xy" ]) | |
195 | AM_CONDITIONAL([HAVE_SYSTEMD_SYSTEM_CALL_ARCHITECTURES], [ test x"$systemd_system_call_architectures" = "xy" ]) | |
196 | AM_CONDITIONAL([HAVE_SYSTEMD_SYSTEM_CALL_FILTER], [ test x"$systemd_system_call_filter" = "xy" ]) | |
197 | ]) |