# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=iproute2
pkgver=6.11.0
pkgrel=0
pkgdesc="IP Routing Utilities"
url="https://wiki.linuxfoundation.org/networking/iproute2"
arch="all"
license="GPL-2.0-or-later"
install="$pkgname.post-install"
depends="
	$pkgname-minimal
	$pkgname-tc
	$pkgname-ss
	"
makedepends="
	bash
	bison
	elfutils-dev
	flex
	iptables-dev
	libcap-dev
	libmnl-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-dev
	$pkgname-bash-completion
	$pkgname-minimal
	$pkgname-tc
	$pkgname-ss
	$pkgname-rdma
	"
source="https://kernel.org/pub/linux/utils/net/iproute2/iproute2-$pkgver.tar.xz
	0001-libnetlink-fix-build-with-musl-and-gcc-14.patch
	basename.patch
	fix-a-musl-build-issue.patch
	fix-a-further-musl-build-issue.patch
	"
options="!check"  # requires namespaces support and root

# secfixes:
#   5.1.0-r0:
#     - CVE-2019-20795

build() {
	export CFLAGS="$CFLAGS -flto=auto"
	make V=1
}

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

	install -D -m644 include/libnetlink.h "$pkgdir"/usr/include/libnetlink.h
	install -D -m644 lib/libnetlink.a "$pkgdir"/usr/lib/libnetlink.a
}

minimal() {
	pkgdesc="IP Routing Utilities (/sbin/ip only)"
	depends=""
	replaces="$pkgname"  # for backward compatibility (Alpine <3.13)

	amove sbin/ip
	amove usr/share/iproute2
}

tc() {
	pkgdesc="$pkgdesc (traffic control and XDP support)"
	depends=""
	replaces="$pkgname"  # for backward compatibility (Alpine <3.13)

	amove sbin/tc
	amove usr/lib/tc
}

ss() {
	pkgdesc="$pkgdesc (socket statistics tool)"
	depends=""
	replaces="$pkgname"  # for backward compatibility (Alpine <3.13)

	amove sbin/ss
}

rdma() {
	pkgdesc="$pkgdesc (rdma utilities)"
	depends=""

	amove sbin/dcb
	amove sbin/devlink
	amove sbin/rdma
	amove sbin/tipc
	amove sbin/vdpa
}

sha512sums="
06bedd7ae573fe5cf9c72af698987ba03e53dc6fce5f41813bf5bb155b683490e5c75cc835ce5ba4509e491eb6138e96da162204c28ea1b3d80887107997a3b3  iproute2-6.11.0.tar.xz
2e2cb5ee73ac5eda619d64c63f6b05e145e0f5cfd4dfd03c4642469d125959717fde78ccf56013ae94a0172be71d193994b4cea997c5be5a08c0e514b53ae34c  0001-libnetlink-fix-build-with-musl-and-gcc-14.patch
7d38eddfc55a2c02b92a05597d9ff66607a35565caadc788b09ac729e9c3539c7535165265d6a0fa3ed30348cb069b37beb01d212196f36a4ec0b3b23579f17c  basename.patch
c09fd829a616fbb18bf8c5ea29a8cd80d160c806426184760443861a55f73023db40a82885c76a1b1d9b4793da1a9e167b88fa609dc72b9699392d6c66ae2d74  fix-a-musl-build-issue.patch
a32287488b3e2c9cdc38b10e3fb0116cc83c8d29f2c60e078316ae6899fd1013028c7e74dd480de36cec1676b5b4f8917f78e61c5c365f119f0ec440908736de  fix-a-further-musl-build-issue.patch
"
