NAME="networkmanager"
DESC="Co-operative tools that make networking simple and straightforward"
VERSION="1.44.0"
FILES=(
  "https://download.gnome.org/sources/NetworkManager/1.44/NetworkManager-$VERSION.tar.xz"
  "NetworkManager.conf"
  "dhcp.conf"
  "polkit.conf"
)
HASHES=(
  "2a39852cda0f04bd72c9782839b1dc7d"
  "44b048804c7c0b8b3b0c29b8632b6ad613c397d0a1635ec918e10c0fbcdadf21"
  "cd2a4b0079c0726973c1cf226c4e1cb4f2d27d02c16e0e08af7e4d6b8770423c"
  "7410be567871e4dc8ef1e8204f80b7cfd0dd08abfa514408b7d549bdc70dbaba"
)
DEPENDS=(
  "jansson" "libndp" "curl" "dhcpcd"
  "gobject-introspection" "iptables" "newt"
  "nss" "polkit" "pygobject" "systemd"
  "wpa-supplicant" "gnutls"
)

PACKAGE() {
  tar xf NetworkManager-$VERSION.tar.xz
  cd NetworkManager-$VERSION

  grep -rl '^#!.*python$' | xargs sed -i '1s/python/&3/'
  mkdir build
  cd    build

  CXXFLAGS+="-O2 -fPIC"          \
  meson setup ..                 \
      --prefix=/usr              \
      --buildtype=release        \
      -Dlibaudit=no              \
      -Dlibpsl=false             \
      -Dnmtui=true               \
      -Dovs=false                \
      -Dppp=false                \
      -Dselinux=false            \
      -Dqt=false                 \
      -Dsession_tracking=systemd \
      -Dmodem_manager=false     
  ninja && DESTDIR="$ROOTDIR" ninja install
  mv -v "$ROOTDIR/usr/share/doc/NetworkManager"{,-1.44.0}
  for file in $(echo ../man/*.[1578]); do
    section=${file##*.} &&
    install -vdm 755 "$ROOTDIR/usr/share/man/man$section"
    install -vm 644 $file "$ROOTDIR/usr/share/man/man$section/"
  done

  cp "$ROOTDIR/NetworkManager.conf" "$ROOTDIR/etc/NetworkManager/NetworkManager.conf"
  cp "$ROOTDIR/polkit.conf" "$ROOTDIR/etc/NetworkManager/conf.d/polkit.conf"
  cp "$ROOTDIR/dhcp.conf" "$ROOTDIR/etc/NetworkManager/conf.d/dhcp.conf"

  cd ../.. && rm -r NetworkManager-$VERSION
}
