makedepends=(python-jinja2 gnu-efi libxcrypt)

description="Init system to control boot, execution and halt of a linux system"
url="http://www.freedesktop.org/wiki/Software/systemd/"

packager="Grat-OS Team"
maintainer="Grat-OS Team"

name=systemd
version=256
release=4

grat_os_version=1.0-RC1

PKGMK_DEPENDS=(util-linux pam)
PKGMK_KEEP_SOURCES="no"
PKGMK_IGNORE_RUNTIMEDEPS="yes"

source=(https://github.com/systemd/systemd/archive/refs/tags/v$version.tar.gz)

build() {

  cd $name-$version

  sed '/bus_message_type_from_string/s/_pure_//' -i src/libsystemd/sd-bus/bus-internal.h
  sed '/devt_hash_func/s/_pure_//'  -i src/basic/hash-funcs.h
  sed '/job_get_timeout/s/_pure_//' -i src/core/job.h
      
  sed -i -e 's/GROUP="render"/GROUP="video"/' \
            -e 's/GROUP="sgx", //' rules.d/50-udev-default.rules.in

  [ -d /tools ] && \
  for file in /tools/lib/lib{blkid,mount,uuid}.so*; do
      ln -svf $file /usr/lib/
  done

  mkdir -pv ../build
  cd ../build

  PKG_CONFIG_PATH="/usr/lib/pkgconfig:/tools/lib/pkgconfig" \
  LANG=en_US.UTF-8                   \
  CFLAGS+=" -Wno-format-overflow"     \
  meson --prefix=/usr                \
        --libdir=/usr/lib            \
        --sysconfdir=/etc            \
        --localstatedir=/var         \
        -Dblkid=true                 \
        -Dmode=release               \
        -Ddefault-dnssec=no          \
        -Dfirstboot=false            \
        -Dinstall-tests=false        \
        -Dldconfig=false             \
        -Dsysusers=true              \
        -Dsplit-usr=false            \
        -Dman=false                  \
        -Dhtml=false                 \
        -Dhomed=false                \
        -Duserdb=false               \
        -Dpamconfdir=/etc/pam.d      \
        -Defi=true                   \
        ../$name-$version

  LANG="en_US.utf8" ninja
  DESTDIR=$PKG LANG="en_US.utf8" ninja install

  rm -fv /usr/bin/xsltproc

  # Disable service systemd-networkd
  #unlink $PKG/etc/systemd/system/dbus-org.freedesktop.network1.service
  #unlink $PKG/etc/systemd/system/multi-user.target.wants/systemd-networkd.service
  #unlink $PKG/etc/systemd/system/sockets.target.wants/systemd-networkd.socket
  #unlink $PKG/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service

  # Disable service systemd-resolved
  #unlink $PKG/etc/systemd/system/dbus-org.freedesktop.resolve1.service
  #unlink $PKG/etc/systemd/system/multi-user.target.wants/systemd-resolved.service

  rm -f $PKG/usr/lib/tmpfiles.d/systemd-nologin.conf

  chmod 755 $PKG/usr/lib/systemd/systemd-user-sessions

  rm $PKG/usr/lib/tmpfiles.d/home.conf

  rm -f $PKG/usr/lib/sysctl.d/50-pid-max.conf

  cat > $PKG/usr/lib/os-release <<EOF
# Begin /etc/os-release

NAME=Grat-OS
VERSION=$grat_os_version
ID=grat-os
VERSION_ID=$grat_os_version
PRETTY_NAME="Grat-OS $grat_os_version"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:Grat-OS_project:grat-os:$grat_os_version"
HOME_URL="https://www.grat-os.fr/"
BUG_REPORT_URL="https://code.grat-os.fr/Grat-OS/"

# End /etc/os-release
EOF

  cat >> $PKG/usr/share/factory/etc/issue <<"EOF"
╔═══╗         ╔╗      ╔═══╗╔═══╗                            ╔╗     
║╔═╗║        ╔╝╚╗     ║╔═╗║║╔═╗║                            ║║     
║║ ╚╝╔═╗╔══╗ ╚╗╔╝     ║║ ║║║╚══╗    ╔╗╔══╗    ╔═╗╔══╗╔══╗ ╔═╝║╔╗ ╔╗
║║╔═╗║╔╝╚ ╗║  ║║ ╔═══╗║║ ║║╚══╗║    ╠╣║══╣    ║╔╝║╔╗║╚ ╗║ ║╔╗║║║ ║║
║╚╩═║║║ ║╚╝╚╗ ║╚╗╚═══╝║╚═╝║║╚═╝║    ║║╠══║    ║║ ║║═╣║╚╝╚╗║╚╝║║╚═╝║
╚═══╝╚╝ ╚═══╝ ╚═╝     ╚═══╝╚═══╝    ╚╝╚══╝    ╚╝ ╚══╝╚═══╝╚══╝╚═╗╔╝
                                                              ╔═╝║ 
                                                              ╚══╝ 
EOF


  if [ -d /tools ]; then rm -fv /usr/lib/lib{blkid,uuid,mount}.so*; fi

}
