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="Great-OS Team"
maintainer="Great-OS Team"

name=systemd
version=258.3
release=2

great_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=enabled              \
        -Dmode=release               \
        -Ddefault-dnssec=no          \
        -Dfirstboot=false            \
        -Dinstall-tests=false        \
        -Dldconfig=false             \
        -Dsysusers=true              \
        -Dman=disabled               \
        -Dhtml=disabled              \
        -Dhomed=disabled             \
        -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=Great-OS
VERSION=$great_os_version
ID=great-os
VERSION_ID=$great_os_version
PRETTY_NAME="Great-OS $great_os_version"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:Great-OS_project:great-os:$great_os_version"
HOME_URL="https://www.great-os.org/"
BUG_REPORT_URL="https://git.great-os.org/Great-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

}
