# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=libnl3
pkgver=3.11.0
pkgrel=0
pkgdesc="Library for applications dealing with netlink sockets"
url="http://www.infradead.org/~tgr/libnl/"
arch="all"
license="LGPL-2.1-or-later"
makedepends="linux-headers flex bison libtool autoconf automake"
checkdepends="check-dev"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc $pkgname-cli"
# XXX: Since 3.6.0, the tests modify the process namespace.
# Many of these operations are not allowed by our CI sandbox.
# The tests should pass locally.
#
# See: https://github.com/thom311/libnl/commit/9102872ac24c71f5ac48b6a1f09115c872b5793b
options="!check"
source="https://github.com/thom311/libnl/releases/download/libnl${pkgver//./_}/libnl-$pkgver.tar.gz
	libnl3-musl.patch
	"

builddir="$srcdir"/libnl-$pkgver
prepare() {
	default_prepare
	autoreconf -vif
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-static \
		--enable-unit-tests
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
}

cli() {
	pkgdesc="Command line interface utils for libnl3"
	mkdir -p "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/libnl-cli*.so.* \
		"$pkgdir"/usr/lib/libnl \
		"$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
}

sha512sums="
69ecec6e792fc7b9c443fff8742cf45782af5c5c4664687440942eaeb616ba7b4ed2b606e33c5d86e44e6b49a9c79a1fed4b7c77781a059e13cf6a844d94530e  libnl-3.11.0.tar.gz
d5fc23646225a63da557edb672c33a4fce88d71f0d18d0c5aedba95dbe26ca3d3be58b7626543307a6c5419b8439f49687e3dd92acc0c6cf3b34bf13a81b1df5  libnl3-musl.patch
"