1 # Copyright 2011-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 if [[ ${PV} == 9999 ]]; then
7 EGIT_REPO_URI="https://github.com/systemd/systemd.git"
13 SRC_URI="https://github.com/systemd/systemd/archive/v${MY_PV}/${MY_P}.tar.gz"
14 KEYWORDS="alpha amd64 arm arm64 ~hppa ia64 ~mips ppc ppc64 sparc x86"
17 PYTHON_COMPAT=( python{3_6,3_7} )
19 inherit bash-completion-r1 linux-info meson multilib-minimal ninja-utils pam python-any-r1 systemd toolchain-funcs udev usr-ldscript
21 DESCRIPTION="System and service manager for Linux"
22 HOMEPAGE="https://www.freedesktop.org/wiki/Software/systemd"
24 LICENSE="GPL-2 LGPL-2.1 MIT public-domain"
26 IUSE="acl apparmor audit build cgroup-hybrid cryptsetup curl dns-over-tls elfutils +gcrypt gnuefi http idn importd +kmod +lz4 lzma nat pam pcre policykit qrcode +resolvconf +seccomp selinux split-usr static-libs +sysv-utils test vanilla xkb"
28 REQUIRED_USE="importd? ( curl gcrypt lzma )"
29 RESTRICT="!test? ( test )"
33 COMMON_DEPEND=">=sys-apps/util-linux-2.30:0=[${MULTILIB_USEDEP}]
34 sys-libs/libcap:0=[${MULTILIB_USEDEP}]
36 acl? ( sys-apps/acl:0= )
37 apparmor? ( sys-libs/libapparmor:0= )
38 audit? ( >=sys-process/audit-2:0= )
39 cryptsetup? ( >=sys-fs/cryptsetup-1.6:0= )
40 curl? ( net-misc/curl:0= )
41 dns-over-tls? ( >=net-libs/gnutls-3.5.3:0= )
42 elfutils? ( >=dev-libs/elfutils-0.158:0= )
43 gcrypt? ( >=dev-libs/libgcrypt-1.4.5:0=[${MULTILIB_USEDEP}] )
45 >=net-libs/libmicrohttpd-0.9.33:0=[epoll(+)]
46 >=net-libs/gnutls-3.1.4:0=
48 idn? ( net-dns/libidn2:= )
53 kmod? ( >=sys-apps/kmod-15:0= )
54 lz4? ( >=app-arch/lz4-0_p131:0=[${MULTILIB_USEDEP}] )
55 lzma? ( >=app-arch/xz-utils-5.0.5-r1:0=[${MULTILIB_USEDEP}] )
56 nat? ( net-firewall/iptables:0= )
57 pam? ( sys-libs/pam:=[${MULTILIB_USEDEP}] )
58 pcre? ( dev-libs/libpcre2 )
59 qrcode? ( media-gfx/qrencode:0= )
60 seccomp? ( >=sys-libs/libseccomp-2.3.3:0= )
61 selinux? ( sys-libs/libselinux:0= )
62 xkb? ( >=x11-libs/libxkbcommon-0.4.1:0= )"
64 # Newer linux-headers needed by ia64, bug #480218
65 DEPEND="${COMMON_DEPEND}
66 >=sys-kernel/linux-headers-${MINKV}
67 gnuefi? ( >=sys-boot/gnu-efi-3.0.2 )
70 # baselayout-2.2 has /run
71 RDEPEND="${COMMON_DEPEND}
86 acct-group/systemd-journal
87 acct-user/systemd-journal-remote
88 acct-user/systemd-coredump
89 acct-user/systemd-network
90 acct-user/systemd-resolve
91 acct-user/systemd-timesync
92 >=sys-apps/baselayout-2.2
93 selinux? ( sec-policy/selinux-base-policy[systemd] )
94 sysv-utils? ( !sys-apps/sysvinit )
95 !sysv-utils? ( sys-apps/sysvinit )
96 resolvconf? ( !net-dns/openresolv )
98 sys-apps/util-linux[kill(-)]
99 sys-process/procps[kill(+)]
100 sys-apps/coreutils[kill(-)]
102 !sys-auth/nss-myhostname
103 !<sys-kernel/dracut-044
108 # sys-apps/dbus: the daemon only (+ build-time lib dep for tests)
109 PDEPEND=">=sys-apps/dbus-1.9.8[systemd]
110 >=sys-apps/hwids-20150417[udev]
111 >=sys-fs/udev-init-scripts-25
112 policykit? ( sys-auth/polkit )
113 !vanilla? ( sys-apps/gentoo-systemd-integration )"
118 >=dev-util/meson-0.46
119 >=dev-util/intltool-0.50
120 >=sys-apps/coreutils-8.16
122 virtual/pkgconfig[${MULTILIB_USEDEP}]
123 test? ( sys-apps/dbus )
124 app-text/docbook-xml-dtd:4.2
125 app-text/docbook-xml-dtd:4.5
126 app-text/docbook-xsl-stylesheets
128 $(python_gen_any_dep 'dev-python/lxml[${PYTHON_USEDEP}]')
132 if [[ ${MERGE_TYPE} != buildonly ]]; then
133 if use test && has pid-sandbox ${FEATURES}; then
134 ewarn "Tests are known to fail with PID sandboxing enabled."
135 ewarn "See https://bugs.gentoo.org/674458."
138 local CONFIG_CHECK="~AUTOFS4_FS ~BLK_DEV_BSG ~CGROUPS
139 ~CHECKPOINT_RESTORE ~DEVTMPFS ~EPOLL ~FANOTIFY ~FHANDLE
140 ~INOTIFY_USER ~IPV6 ~NET ~NET_NS ~PROC_FS ~SIGNALFD ~SYSFS
141 ~TIMERFD ~TMPFS_XATTR ~UNIX
142 ~CRYPTO_HMAC ~CRYPTO_SHA256 ~CRYPTO_USER_API_HASH
143 ~!FW_LOADER_USER_HELPER_FALLBACK ~!GRKERNSEC_PROC ~!IDE ~!SYSFS_DEPRECATED
144 ~!SYSFS_DEPRECATED_V2"
146 use acl && CONFIG_CHECK+=" ~TMPFS_POSIX_ACL"
147 use seccomp && CONFIG_CHECK+=" ~SECCOMP ~SECCOMP_FILTER"
148 kernel_is -lt 3 7 && CONFIG_CHECK+=" ~HOTPLUG"
149 kernel_is -lt 4 7 && CONFIG_CHECK+=" ~DEVPTS_MULTIPLE_INSTANCES"
150 kernel_is -ge 4 10 && CONFIG_CHECK+=" ~CGROUP_BPF"
152 if linux_config_exists; then
153 local uevent_helper_path=$(linux_chkconfig_string UEVENT_HELPER_PATH)
154 if [[ -n ${uevent_helper_path} ]] && [[ ${uevent_helper_path} != '""' ]]; then
155 ewarn "It's recommended to set an empty value to the following kernel config option:"
156 ewarn "CONFIG_UEVENT_HELPER_PATH=${uevent_helper_path}"
158 if linux_chkconfig_present X86; then
159 CONFIG_CHECK+=" ~DMIID"
163 if kernel_is -lt ${MINKV//./ }; then
164 ewarn "Kernel version at least ${MINKV} required"
177 [[ ${PV} != 9999 ]] || git-r3_src_unpack
181 # Do NOT add patches here
184 [[ -d "${WORKDIR}"/patches ]] && PATCHES+=( "${WORKDIR}"/patches )
186 # Add local patches here
188 "${FILESDIR}/243-seccomp.patch"
191 if ! use vanilla; then
193 "${FILESDIR}/gentoo-Dont-enable-audit-by-default.patch"
194 "${FILESDIR}/gentoo-systemd-user-pam.patch"
195 "${FILESDIR}/gentoo-generator-path-r1.patch"
203 # Prevent conflicts with i686 cross toolchain, bug 559726
204 tc-export AR CC NM OBJCOPY RANLIB
208 multilib-minimal_src_configure
216 if multilib_is_native_abi; then
223 meson_multilib_native_use() {
224 if multilib_is_native_abi && use "$1"; then
231 multilib_src_configure() {
233 --localstatedir="${EPREFIX}/var"
234 -Dsupport-url="https://gentoo.org/support/"
235 -Dpamlibdir="$(getpam_mod_dir)"
236 # avoid bash-completion dep
237 -Dbashcompletiondir="$(get_bashcompdir)"
238 # make sure we get /bin:/sbin in PATH
239 -Dsplit-usr=$(usex split-usr true false)
240 -Drootprefix="$(usex split-usr "${EPREFIX:-/}" "${EPREFIX}/usr")"
241 -Drootlibdir="${EPREFIX}/usr/$(get_libdir)"
244 # Avoid infinite exec recursion, bug 642724
245 -Dtelinit-path="${EPREFIX}/lib/sysvinit/telinit"
247 -Defi=$(meson_multilib)
249 -Ddefault-hierarchy=$(usex cgroup-hybrid hybrid unified)
250 # Optional components/dependencies
251 -Dacl=$(meson_multilib_native_use acl)
252 -Dapparmor=$(meson_multilib_native_use apparmor)
253 -Daudit=$(meson_multilib_native_use audit)
254 -Dlibcryptsetup=$(meson_multilib_native_use cryptsetup)
255 -Dlibcurl=$(meson_multilib_native_use curl)
256 -Ddns-over-tls=$(meson_multilib_native_use dns-over-tls)
257 -Delfutils=$(meson_multilib_native_use elfutils)
258 -Dgcrypt=$(meson_use gcrypt)
259 -Dgnu-efi=$(meson_multilib_native_use gnuefi)
260 -Defi-libdir="${ESYSROOT}/usr/$(get_libdir)"
261 -Dmicrohttpd=$(meson_multilib_native_use http)
262 -Didn=$(meson_multilib_native_use idn)
263 -Dimportd=$(meson_multilib_native_use importd)
264 -Dbzip2=$(meson_multilib_native_use importd)
265 -Dzlib=$(meson_multilib_native_use importd)
266 -Dkmod=$(meson_multilib_native_use kmod)
267 -Dlz4=$(meson_use lz4)
268 -Dxz=$(meson_use lzma)
269 -Dlibiptc=$(meson_multilib_native_use nat)
270 -Dpam=$(meson_use pam)
271 -Dpcre2=$(meson_multilib_native_use pcre)
272 -Dpolkit=$(meson_multilib_native_use policykit)
273 -Dqrencode=$(meson_multilib_native_use qrcode)
274 -Dseccomp=$(meson_multilib_native_use seccomp)
275 -Dselinux=$(meson_multilib_native_use selinux)
276 -Ddbus=$(meson_multilib_native_use test)
277 -Dxkbcommon=$(meson_multilib_native_use xkb)
278 -Dntp-servers="0.gentoo.pool.ntp.org 1.gentoo.pool.ntp.org 2.gentoo.pool.ntp.org 3.gentoo.pool.ntp.org"
279 # Breaks screen, tmux, etc.
280 -Ddefault-kill-user-processes=false
281 -Dcreate-log-dirs=false
284 -Dbacklight=$(meson_multilib)
285 -Dbinfmt=$(meson_multilib)
286 -Dcoredump=$(meson_multilib)
287 -Denvironment-d=$(meson_multilib)
288 -Dfirstboot=$(meson_multilib)
289 -Dhibernate=$(meson_multilib)
290 -Dhostnamed=$(meson_multilib)
291 -Dhwdb=$(meson_multilib)
292 -Dldconfig=$(meson_multilib)
293 -Dlocaled=$(meson_multilib)
294 -Dman=$(meson_multilib)
295 -Dnetworkd=$(meson_multilib)
296 -Dquotacheck=$(meson_multilib)
297 -Drandomseed=$(meson_multilib)
298 -Drfkill=$(meson_multilib)
299 -Dsysusers=$(meson_multilib)
300 -Dtimedated=$(meson_multilib)
301 -Dtimesyncd=$(meson_multilib)
302 -Dtmpfiles=$(meson_multilib)
303 -Dvconsole=$(meson_multilib)
306 -Dstatic-libsystemd=$(usex static-libs true false)
307 -Dstatic-libudev=$(usex static-libs true false)
310 meson_src_configure "${myconf[@]}"
313 multilib_src_compile() {
317 multilib_src_test() {
318 unset DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR
322 multilib_src_install() {
323 DESTDIR="${D}" eninja install
326 multilib_src_install_all() {
327 local rootprefix=$(usex split-usr '' /usr)
329 # meson doesn't know about docdir
330 mv "${ED}"/usr/share/doc/{systemd,${PF}} || die
333 dodoc "${FILESDIR}"/nsswitch.conf
335 if ! use resolvconf; then
336 rm -f "${ED}${rootprefix}"/sbin/resolvconf || die
339 if ! use sysv-utils; then
340 rm "${ED}${rootprefix}"/sbin/{halt,init,poweroff,reboot,runlevel,shutdown,telinit} || die
341 rm "${ED}"/usr/share/man/man1/init.1 || die
342 rm "${ED}"/usr/share/man/man8/{halt,poweroff,reboot,runlevel,shutdown,telinit}.8 || die
345 if ! use resolvconf && ! use sysv-utils; then
346 rmdir "${ED}${rootprefix}"/sbin || die
349 # Preserve empty dirs in /etc & /var, bug #437008
350 keepdir /etc/{binfmt.d,modules-load.d,tmpfiles.d}
351 keepdir /etc/kernel/install.d
352 keepdir /etc/systemd/{network,system,user}
353 keepdir /etc/udev/{hwdb.d,rules.d}
354 keepdir "${rootprefix}"/lib/systemd/{system-sleep,system-shutdown}
355 keepdir /usr/lib/{binfmt.d,modules-load.d}
356 keepdir /usr/lib/systemd/user-generators
357 keepdir /var/lib/systemd
358 keepdir /var/log/journal
360 # Symlink /etc/sysctl.conf for easy migration.
361 dosym ../sysctl.conf /etc/sysctl.d/99-sysctl.conf
363 rm -r "${ED}${rootprefix}"/lib/udev/hwdb.d || die
365 if use split-usr; then
366 # Avoid breaking boot/reboot
367 dosym ../../../lib/systemd/systemd /usr/lib/systemd/systemd
368 dosym ../../../lib/systemd/systemd-shutdown /usr/lib/systemd/systemd-shutdown
371 gen_usr_ldscript -a systemd udev
375 local envd_locale_def="${EROOT}/etc/env.d/02locale"
376 local envd_locale=( "${EROOT}"/etc/env.d/??locale )
377 local locale_conf="${EROOT}/etc/locale.conf"
379 if [[ ! -L ${locale_conf} && ! -e ${locale_conf} ]]; then
380 # If locale.conf does not exist...
381 if [[ -e ${envd_locale} ]]; then
382 # ...either copy env.d/??locale if there's one
383 ebegin "Moving ${envd_locale} to ${locale_conf}"
384 mv "${envd_locale}" "${locale_conf}"
387 # ...or create a dummy default
388 ebegin "Creating ${locale_conf}"
389 cat > "${locale_conf}" <<-EOF
390 # This file has been created by the sys-apps/systemd ebuild.
391 # See locale.conf(5) and localectl(1).
399 if [[ ! -L ${envd_locale} ]]; then
400 # now, if env.d/??locale is not a symlink (to locale.conf)...
401 if [[ -e ${envd_locale} ]]; then
402 # ...warn the user that he has duplicate locale settings
404 ewarn "To ensure consistent behavior, you should replace ${envd_locale}"
405 ewarn "with a symlink to ${locale_conf}. Please migrate your settings"
406 ewarn "and create the symlink with the following command:"
407 ewarn "ln -s -n -f ../locale.conf ${envd_locale}"
410 # ...or just create the symlink if there's nothing here
411 ebegin "Creating ${envd_locale_def} -> ../locale.conf symlink"
412 ln -n -s ../locale.conf "${envd_locale_def}"
418 save_enabled_units() {
420 type systemctl &>/dev/null || return
422 if systemctl --quiet --root="${ROOT:-/}" is-enabled "${x}"; then
423 ENABLED_UNITS+=( "${x}" )
429 save_enabled_units {machines,remote-{cryptsetup,fs}}.target getty@tty1.service
431 if ! use split-usr; then
433 for dir in bin sbin lib; do
434 if [[ ! ${EROOT}/${dir} -ef ${EROOT}/usr/${dir} ]]; then
435 eerror "\"${EROOT}/${dir}\" and \"${EROOT}/usr/${dir}\" are not merged."
436 eerror "One of them should be a symbolic link to the other one."
440 if [[ ${FAIL} ]]; then
441 eerror "Migration to system layout with merged directories must be performed before"
442 eerror "rebuilding ${CATEGORY}/${PN} with USE=\"-split-usr\" to avoid run-time breakage."
443 die "System layout with split directories still used"
449 systemd_update_catalog
451 # Keep this here in case the database format changes so it gets updated
452 # when required. Despite that this file is owned by sys-apps/hwids.
453 if has_version "sys-apps/hwids[udev]"; then
454 udevadm hwdb --update --root="${EROOT}"
457 udev_reload || FAIL=1
459 # Bug 465468, make sure locales are respect, and ensure consistency
460 # between OpenRC & systemd
463 systemd_reenable systemd-networkd.service systemd-resolved.service
465 if [[ ${ENABLED_UNITS[@]} ]]; then
466 systemctl --root="${ROOT:-/}" enable "${ENABLED_UNITS[@]}"
469 if [[ -z ${REPLACING_VERSIONS} ]]; then
470 if type systemctl &>/dev/null; then
471 systemctl --root="${ROOT:-/}" enable getty@.service remote-fs.target || FAIL=1
473 elog "To enable a useful set of services, run the following:"
474 elog " systemctl preset-all --preset-mode=enable-only"
477 if [[ -L ${EROOT}/var/lib/systemd/timesync ]]; then
478 rm "${EROOT}/var/lib/systemd/timesync"
481 if [[ -z ${ROOT} && -d /run/systemd/system ]]; then
482 ebegin "Reexecuting system manager"
483 systemctl daemon-reexec
487 if [[ ${FAIL} ]]; then
488 eerror "One of the postinst commands failed. Please check the postinst output"
489 eerror "for errors. You may need to clean up your system and/or try installing"
490 eerror "systemd again."
496 # If removing systemd completely, remove the catalog database.
497 if [[ ! ${REPLACED_BY_VERSION} ]]; then
498 rm -f -v "${EROOT}"/var/lib/systemd/catalog/database