pkgname="systemd"
pkgver=257.8
pkgdesc="system and service manager"
homepage="https://www.freedesktop.org/wiki/Software/systemd/"
license=("LGPL-2.1-or-laterC" "C0-1.0" "GPL-2.0-or-later" "MIT-0")
sources=("${pkgname}-${pkgver}.tar.gz"
  "${pkgname}-man-pages-${pkgver}.tar.xz"
  "30-systemd-daemon-reload-system.HOOK"
  "30-systemd-daemon-reload-user.HOOK"
)
urls=("https://github.com/systemd/systemd/archive/v${pkgver}/${sources[0]}"
  "https://anduin.linuxfromscratch.org/LFS/${sources[1]}"
  "30-systemd-daemon-reload-system.HOOK"
  "30-systemd-daemon-reload-user.HOOK"
)
md5sums=("25fe5d328e22641254761f1baa74cee0"
  "a44063e2ec0cf4adfd2ed5c9e9e095c5"
  "49ffd7e5c810f8b3cf14fb9535d6a4c5"
  "e38543ca711f6ff063174b82afe3cbb3"
)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  sed -e 's/GROUP="render"/GROUP="video"/' \
    -e 's/GROUP="sgx", //'               \
    -i rules.d/50-udev-default.rules.in
}

src_build() {
  mkdir -p build
  cd       build

  meson setup ..                \
        --prefix=/usr           \
        --libdir=/usr/lib       \
        --buildtype=release     \
        -D default-dnssec=no    \
        -D firstboot=false      \
        -D install-tests=false  \
        -D ldconfig=false       \
        -D sysusers=false       \
        -D rpmmacrosdir=no      \
        -D homed=disabled       \
        -D userdb=false         \
        -D man=disabled         \
        -D mode=release         \
        -D pamconfdir=no        \
        -D dev-kvm-mode=0660    \
        -D nobody-group=nogroup \
        -D sysupdate=disabled   \
        -D ukify=disabled       \
        -D default-kill-user-processes=false  \
        -D default-locale='C.UTF-8'           \
        -D docdir=/usr/share/doc/systemd-${pkgver}

  ninja
  cd ..
}

src_check() {
  pushd build &&
  if [[ ! -f /etc/os-release ]]; then
    echo 'NAME="Linux From Scratch"' > /etc/os-release
  fi
  ninja test &&
  popd
}

src_install() {
  pushd build
  DESTDIR=$pkgdir ninja install
  leaf_install_hook ${filedir}/${sources[2]}
  leaf_install_hook ${filedir}/${sources[3]}
  install -d -v -m755 ${pkgdir}/usr/share/man
  tar -xf ${distdir}/${sources[1]} \
    --no-same-owner --strip-components=1     \
    -C ${pkgdir}/usr/share/man
  popd
}

src_postinstall() {
  if [[ ! -f /etc/machine-id ]]; then
    systemd-machine-id-setup
    systemctl preset-all
  fi
}

