# Template file for 'NetworkManager'
pkgname=NetworkManager
version=1.48.10
revision=1
build_style=meson
build_helper="gir qemu"
configure_args="-Dsystemd_journal=false
 -Dlibaudit=no -Dovs=false -Dselinux=false
 -Dmodify_system=true -Dsystemdsystemunitdir=no
 -Dpppd=/usr/bin/pppd -Dqt=false
 -Dsession_tracking_consolekit=false
 -Dresolvconf=/usr/bin/resolvconf
 -Ddhclient=/usr/bin/dhclient -Dkernel_firmware_dir=/usr/lib/firmware
 -Ddnsmasq=/usr/bin/dnsmasq -Ddbus_conf_dir=/etc/dbus-1/system.d
 -Ddhcpcd=/usr/bin/dhcpcd -Diptables=/usr/bin/iptables -Dnft=/usr/bin/nft
 -Diwd=true -Dudev_dir=/usr/lib/udev -Ddocs=true
 $(vopt_bool gir introspection) $(vopt_bool gir vapi)
 -Dsession_tracking=$(vopt_if elogind elogind no)
 -Dsuspend_resume=$(vopt_if elogind elogind upower)
 -Dconfig_dhcp_default=internal"
hostmakedepends="gettext-devel glib-devel libxslt-devel pkg-config
 dbus-glib-devel docbook-xsl gtk-doc polkit-devel perl
 $(vopt_if gir 'vala python3-gobject')"
makedepends="libuuid-devel nss-devel dbus-glib-devel libgudev-devel
 libnl3-devel polkit-devel ppp-devel libcurl-devel
 ModemManager-devel readline-devel libndp-devel newt-devel jansson-devel
 libpsl-devel eudev-libudev-devel mobile-broadband-provider-info gnutls-devel
 $(vopt_if gir 'libgirepository-devel python3-gobject')
 $(vopt_if elogind elogind-devel)"
depends="dbus iproute2 openresolv wpa_supplicant mobile-broadband-provider-info"
checkdepends="python3-dbus"
short_desc="Network Management daemon"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="GPL-2.0-or-later"
homepage="https://wiki.gnome.org/Projects/NetworkManager"
changelog="https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/raw/nm-1-48/NEWS"
distfiles="${GNOME_SITE}/NetworkManager/${version%.*}/NetworkManager-${version}.tar.xz"
checksum=5dc188fdffcf2d23c89d34b1e6319a6b20203e12eaec24b30037b7ea8ac8c613
# TODO: Some tests require network namespaces to run.
make_check=extended
lib32disabled=yes
conf_files="/etc/NetworkManager/NetworkManager.conf"
make_dirs="
 /etc/NetworkManager/system-connections 0755 root root
 /etc/NetworkManager/dispatcher.d/pre-up.d 0750 root root
 /etc/NetworkManager/dispatcher.d/pre-down.d 0750 root root
 /etc/NetworkManager/VPN 0755 root root
 /var/lib/NetworkManager 0755 root root
"

# Package build options
build_options="gir elogind"
build_options_default="gir elogind"

post_patch() {
	if [ "$CROSS_BUILD" ]; then
		# Replace the values from our patch into the system itself
		vsed -i \
			-e "s|@XBPS_CROSS_BASE@|${XBPS_CROSS_BASE}|g" \
			-e "s|@XBPS_TARGET_QEMU_MACHINE@|${XBPS_TARGET_QEMU_MACHINE}|" \
			src/libnm-client-impl/meson.build
		# https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/955
		vsed -e "s#jansson_dep.get_variable(pkgconfig: 'libdir')#'${XBPS_CROSS_BASE}/usr/lib'#" \
			-i meson.build
	fi
}

pre_check() {
	# machine-id is a random, non-zero value
	echo 'dcb30309cd6c8b7cc20383d85a5c7012' > /etc/machine-id
}

post_check() {
	rm /etc/machine-id
}

post_install() {
	vinstall ${FILESDIR}/NetworkManager.conf 644 etc/NetworkManager
	vinstall ${FILESDIR}/50-org.freedesktop.NetworkManager.rules 644 \
		/usr/share/polkit-1/rules.d
	vsv NetworkManager
}

libnm_package() {
	short_desc+=" - shared libraries"
	pkg_install() {
		vmove "usr/lib/*.so.*"
		if [ "$build_option_gir" ]; then
			vmove usr/lib/girepository-1.0
		fi
	}
}
NetworkManager-devel_package() {
	depends="dbus-glib-devel libnm-${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/pkgconfig
		vmove "usr/lib/*.so"
		if [ "$build_option_gir" ]; then
			vmove usr/share/gir-1.0
			vmove usr/share/vala
		fi
	}
}
