# Template file for 'NetworkManager'
pkgname=NetworkManager
version=1.8.0
revision=1
build_style=gnu-configure
configure_args="--without-dhcpcd --with-dhclient=/usr/bin/dhclient
 --with-system-ca-path=/etc/ssl/certs --enable-more-warnings=no
 --with-crypto=gnutls --disable-static --enable-ppp --with-nmtui
 --with-udev-dir=/usr/lib/udev $(vopt_enable gir introspection)
 --with-kernel-firmware-dir=/usr/lib/firmware
 --with-pppd-plugin-dir=/usr/lib/pppd/2.4.7 --enable-modify-system
 --with-modem-manager-1 --with-resolvconf=/usr/bin/resolvconf
 --with-session-tracking=$(vopt_if elogind logind consolekit)
 --with-suspend-resume=upower
 --with-systemdsystemunitdir=no --enable-polkit-agent --enable-tests=no
 --with-systemd-journal=no --with-systemd-logind=no --disable-gtk-doc
 --with-dbus-sys-dir=/etc/dbus-1/system.d
 --sbindir=/usr/bin --enable-concheck
 ac_cv_file__etc_redhat_release=no ac_cv_file__etc_gentoo_release=no
 ac_cv_file__etc_fedora_release=no ac_cv_file__etc_mandriva_release=no
 ac_cv_file__etc_SuSE_release=no ac_cv_file__etc_debian_version=no"
short_desc="Network Management daemon"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
homepage="https://wiki.gnome.org/Projects/NetworkManager"
license="GPL-2"
distfiles="${GNOME_SITE}/$pkgname/${version%.*}/$pkgname-$version.tar.xz"
checksum=fa5a5c6a36cdf95b12df34cc575bd61a74f297ede9be22cac4807a1aff3cf69e

# gtk-doc generation is disabled but gtkdocisze is required by autogen.sh
hostmakedepends="
 automake libtool pkg-config intltool gnutls-devel glib-devel dbus-glib-devel
 gettext-devel gtk-doc dbus iproute2 dhclient wpa_supplicant bluez iptables
 $(vopt_if gir gobject-introspection) $(vopt_if gir python-gobject)"
makedepends="libuuid-devel gnutls-devel dbus-glib-devel libgudev-devel
 libnl3-devel polkit-devel ppp-devel iptables-devel libcurl-devel
 ModemManager-devel readline-devel libndp-devel newt-devel jansson-devel
 $(vopt_if gir libgirepository-devel) $(vopt_if elogind elogind-devel)"

lib32disabled=yes
depends="dbus iproute2 dhclient wpa_supplicant openresolv"
conf_files="/etc/${pkgname}/${pkgname}.conf"
make_dirs="
 /etc/NetworkManager/system-connections 0750 root root
 /etc/NetworkManager/dispatcher.d/pre-up.d 0750 root root
 /etc/NetworkManager/dispatcher.d/pre-down.d 0750 root root
"
case "$XBPS_TARGET_MACHINE" in
	*-musl) CFLAGS+=" -DHAVE_SECURE_GETENV -Dsecure_getenv=getenv -D__USE_POSIX199309"
		;;
esac

# Package build options
build_options="gir elogind"
if [ -z "$CROSS_BUILD" ]; then
	build_options_default+=" gir"
fi

pre_configure() {
	NOCONFIGURE=1 ./autogen.sh

	# Full switch to /run to not depend on /var/run being a symlink.
	sed -e 's,^nmrundir=.*$,nmrundir=\"/run/\$PACKAGE\",' -i configure

	sed -e "s/HAVE_LIBSYSTEMD/0/" -i src/devices/wwan/nm-modem-manager.c
}

post_install() {
	vinstall ${FILESDIR}/${pkgname}.conf 644 etc/${pkgname}
	# remove unused stuff
	rm -rf ${DESTDIR}/etc/init.d
	vsv ${pkgname}
}

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
		fi
	}
}
