description="Programs for controlling the startup, running, and shutdown of the system."
url="https://www.freedesktop.org/wiki/Software/systemd/"

packager="tnut <tnut@nutyx.org>"

# Those dependencies are need to compile the package
# but not listed to avoid circular dependencies:
# When rebuild systemd:
# 1/ rebuild dbus first without systemd --disable-systemd in dbus package
# 2/ remove all the systemd archives cards.tar packages
# 3/ build systemd with dbus that has no systemd libs
# 4/ rebuild dbus with systemd so that dbus gets links to systemd

PKGMK_DEPENDS=(python python-markupsafe python-jinja meson ninja util-linux dbus)

makedepends=(acl libcap kmod m4 gperf pam)

name=systemd
version=252.4
release=2

PKGMK_IGNORE_FOOTPRINT='no'
PKGMK_IGNORE_RUNTIMEDEPS='yes'
PKGMK_GROUPS=(devel doc man lib)

source=(consolidate.patch
        http://download.tuxfamily.org/nutyx/files/$name-man-pages-$version.tar.xz
	https://github.com/systemd/systemd/archive/v${version:0:3}/systemd-$version.tar.gz)

prepare() {
ln -sf /bin/true /usr/bin/xsltproc
cd $name-stable-$version
patch -Np1 -i ../consolidate.patch
}
build() {
cd $name-stable-$version

mkdir build
cd    build

meson --prefix=/usr           \
--sysconfdir=/etc             \
--localstatedir=/var          \
-Dfirstboot=false             \
-Dinstall-tests=false         \
-Dkmod-path=/bin/kmod         \
-Dmount-path=/bin/mount       \
-Dsplit-usr=true              \
-Drpmmacrosdir=no             \
-Dsulogin-path=/sbin/sulogin  \
-Dumount-path=/bin/umount     \
-Dman=false                   \
-Dresolve=false               \
-Dsysvinit-path=              \
-Dsysvrcnd-path=              \
-Dtimesyncd=false             \
-Dsysusers=false              \
-Duserdb=false                \
-Dlocaled=false               \
-Dpam=true                    \
-Dpamconfdir=/etc/pam.d       \
-Dmode=release                \
..

ninja

DESTDIR=$PKG ninja install

mkdir -p $PKG/usr/share/man
for i in 1 3 5 7 8
do
  mv ../../man$i \
   $PKG/usr/share/man
done


# systemd-initclt hack
cp ../units/systemd-initctl.socket \
$PKG/lib/systemd/system
sed s@{{ROOTLIBEXECDIR}}@/lib/systemd@ \
 ../units/systemd-initctl.service.in \
> $PKG/lib/systemd/system/systemd-initctl.service
ln -sv ../systemd-initctl.socket  \
$PKG/lib/systemd/system/sockets.target.wants/systemd-initctl.socket

# Figure out what this file was for
# install -m0644 ../tmpfiles.d/legacy.conf $PKG/usr/lib/tmpfiles.d

mv $PKG/{,s}bin/udevadm
ln -sv ../lib/systemd/systemd $PKG/sbin/systemd-init
ln -svf ../../sbin/udevadm $PKG/lib/systemd/systemd-udevd

# eudev Package files
rm $PKG/sbin/udevadm
rm -r $PKG/{lib,etc}/udev
rm $PKG/usr/include/libudev.h
rm $PKG/usr/lib/pkgconfig/libudev.pc
rm $PKG/usr/share/pkgconfig/udev.pc
rm $PKG/lib/libudev*
rm $PKG/lib/systemd/network/99-default.link
rm $PKG/usr/share/bash-completion/completions/udevadm
rm $PKG/usr/share/zsh/site-functions/_udevadm

# sysvinit package files
rm $PKG/sbin/{halt,init,poweroff,reboot,shutdown}

# Prevent systemd from resetting the maximum PID value
rm -f $PKG/usr/lib/sysctl.d/50-pid-max.conf

rm /usr/bin/xsltproc

# elogind package files
rm $PKG/{bin/loginctl,usr/bin/busctl}
rm $PKG/usr/share/bash-completion/completions/loginctl
rm $PKG/usr/share/dbus-1/system-services/org.freedesktop.login1.service
rm -r $PKG/usr/share/factory/etc/pam.d
rm $PKG/usr/share/polkit-1/actions/org.freedesktop.login1.policy
rm $PKG/usr/share/zsh/site-functions/_loginctl
rm $PKG/lib/systemd/system/multi-user.target.wants/systemd-logind.service
rm $PKG/lib/systemd/system/systemd-logind.service
}
lib() {
cd $PKG
bsdtar -cf \
$PKGMK_PACKAGE_DIR/$name.lib${PKGMK_BUILDVER}${PKGMK_ARCH}.cards.tar \
lib/lib* lib/systemd/libsystemd-shared*

rm lib/lib* lib/systemd/libsystemd-shared*
rm -d lib || true
}
