# Contributor: Stuart Cardall <developer@it-offshore.co.uk>
# Maintainer: William Pitcock <nenolod@dereferenced.org>
pkgname=networkmanager
pkgver=1.7.2
pkgrel=2
pkgdesc="network management tool"
url="http://projects.gnome.org/NetworkManager/"
arch="all"
license="GPL"
depends="dhcpcd iptables dbus"
depends_dev=
options="!check"
makedepends="$depends_dev
	curl-dev
	dbus-glib-dev
	eudev-dev
	libgudev-dev
	gobject-introspection-dev
	intltool
	libndp-dev
	libnl3-dev
	libsoup-dev
	libteam-dev
	linux-headers
	modemmanager-dev
	newt-dev
	nss-dev
	polkit-dev
	ppp-dev
	readline-dev
	util-linux-dev
	jansson-dev
	vala

	autoconf
	automake
	libtool
	"
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang"
source="https://download.gnome.org/sources/NetworkManager/${pkgver:0:3}/NetworkManager-$pkgver.tar.xz
	$pkgname.conf
	$pkgname.initd
	$pkgname.rules
	disable_set_hostname.patch
	musl-basic.patch
	musl-network-support.patch
	musl-dlopen-configure-ac.patch
	"

_builddir="$srcdir"/NetworkManager-$pkgver
prepare() {
	local i
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done

	autoreconf
}

build() {
	cd "$_builddir"
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--disable-more-warnings \
		--disable-config-plugin-ibft \
		--disable-tests \
		--disable-wimax \
		--disable-introspection \
 		--enable-ifupdown \
		--enable-concheck \
 		--with-dhcpcd=yes \
		--with-systemdsystemunitdir=no \
		--with-crypto=nss \
		--with-modem-manager-1 \
		--with-nmtui=yes \
		--with-wext=yes \
		--with-resolvconf=yes \
		--with-session-tracking=no \
		--with-suspend-resume=upower \
		--without-valgrind \
		|| return 1
	# ourLDFLAGS confuses the gir-scanner
	unset LDFLAGS
	make libnm-core/nm-core-enum-types.h
	make || return 1
}

package() {
	cd "$_builddir"
	make DESTDIR="$pkgdir" install || return 1

	install -m755 -D "$srcdir"/networkmanager.initd \
		"$pkgdir"/etc/init.d/networkmanager || return 1

	install -m644 -D "$srcdir/$pkgname.conf" \
                "$pkgdir/etc/NetworkManager/NetworkManager.conf" || return 1
	# allow plugdev users to modify connections
	install -m644 -D "$srcdir/$pkgname.rules" \
                "$pkgdir/usr/share/polkit-1/rules.d/01-org.freedesktop.NetworkManager.settings.modify.system.rules" || return 1
	mkdir -p "$pkgdir/usr/share/apk-tools/$pkgname"
	# post-install message
	mv "$pkgdir/usr/share/doc/NetworkManager" "$pkgdir/usr/share/doc/$pkgname" || return 1
        cat > $pkgdir/usr/share/doc/$pkgname/README.alpine <<EOF
To modify system network connections without the root password: add your user account to the 'plugdev' group.
EOF
}

sha512sums="9f5a934bb96f4cf714ff485e3452bb13707caa470774de1965d8748e94fd6c1d9165fca51764fd12f4f672d05e650460839abb2fd970d356568264347a893e8a  NetworkManager-1.7.2.tar.xz
a6e507260e2ceffad4cacb2b49a1d4f6b933e5ae8bc50c1bd56f828298c5dc8d9d17aa4be766faeacefbe3c6c0c748e4ef499a55bb5ee40f0f04bbf766fbbc82  networkmanager.conf
80ef470956bc5319f02e8387bff17c5452d4147321f9f997ca86017494d5134d8579bf59566fc796f3e84ee5788a2d49743d3b93e795f4976661866d1f1b1442  networkmanager.initd
9820ed2ead0af689644842de57657bb10330a1eaff0e85b21ae9913f55e399e47d8b41b0a12956f30de80272b4424c6e55f33acbc88e156879003a260bf576f6  networkmanager.rules
cdc8c26720b983f8afb11ee08c87aab863522633d8dc08e8cea080ed8d94378b3534aedf09efc6e7481599cfede6122b5f6a86b0b45e0a8bb653f95d4c5beaf8  disable_set_hostname.patch
b777dd8ff7383d736648bf8190aee7e306f3d699bb30759ed7c726abf27a333937cec0adce77785b19a30f8f168c4170353478069524942a87b940458dbbf14a  musl-basic.patch
1e0c519c101762c251225414e897139eee13d3556910bf9e4e86b58f0a9c298475d880be06420117960036da175fb05a5208c058a8eb4d8c424537703131ca58  musl-network-support.patch
9120208c258f0db6cf9057f21c3b384e7ddc4b6876228cfb20475e3b6f7292025f649a77cdecd170918bec0c86f576718d62bec9dd70ebdd1ab8d48ae65cfb53  musl-dlopen-configure-ac.patch"
