# Description: Network configuration tool
# URL: https://wiki.gnome.org/Projects/NetworkManager/
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: curl dbus gnutls libndp libnewt libxslt nss polkit python3-gobject
# Optional: ppp avahi bash-completion dbus libnl jansson libteam dnsmasq wireguard-tools

name=networkmanager
version=1.42.8
release=1
source=(https://download.gnome.org/sources/NetworkManager/${version::4}/NetworkManager-$version.tar.xz
  networkmanager.rc NetworkManager.conf polkit.conf dhcp.conf org.freedesktop.NetworkManager.rules)

build() {
  prt-get isinst ppp || PKGMK_NM+=' -D ppp=false'
  prt-get isinst jansson || PKGMK_NM+=' -D ovs=false'
  prt-get isinst libpsl || PKGMK_NM+=' -D libpsl=false'

  meson setup NetworkManager-$version build $PKGMK_NM \
    --prefix /usr \
    --sysconfdir /etc \
    --localstatedir /var \
    --libexecdir /usr/lib/networkmanager \
    --buildtype=plain \
    --wrap-mode nodownload \
    -D b_lto=false \
    -D b_pie=true \
    -D crypto=nss \
    -D dbus_conf_dir=/usr/share/dbus-1/system.d \
    -D udev_dir=/lib/udev \
    -D resolvconf=true \
    -D config_dns_rc_manager_default=resolvconf \
    -D modify_system=true \
    -D ifupdown=true \
    -D docs=false \
    -D selinux=false \
    -D session_tracking=no \
    -D libaudit=no \
    -D modem_manager=false \
    -D more_logging=false \
    -D qt=false \
    -D systemdsystemunitdir=no \
    -D systemd_journal=false
  meson compile -C build
  DESTDIR=$PKG meson install -C build

  # Install config file
  install -Dm 644 $SRC/NetworkManager.conf $PKG/etc/NetworkManager/NetworkManager.conf
  install -Dm 644 $SRC/dhcp.conf $PKG/etc/NetworkManager/conf.d/dhcp.conf

  # install polkit rules
  install -Dm 644 $SRC/org.freedesktop.NetworkManager.rules $PKG/usr/share/polkit-1/rules.d/org.freedesktop.NetworkManager.rules
  install -Dm 644 $SRC/polkit.conf $PKG/etc/NetworkManager/conf.d/polkit.conf

  # Install startup script
  install -Dm 755 $SRC/$name.rc $PKG/etc/rc.d/$name

  # Remove rundir etc
  rm -rf $PKG/var/run $PKG/usr/share/{gtk-,}doc $PKG/usr/share/man/man5/nmcli-examples.5 $PKG/usr/share/locale

  # cleanup
  rm -rf $PKG/usr/lib/firewalld
  prt-get isinst bash-completion || rm -rf $PKG/usr/share/bash-completion
}
