# Contributor: Matthieu Baerts (NGI0) <matttbe@kernel.org>
# Maintainer: Matthieu Baerts (NGI0) <matttbe@kernel.org>
pkgname=mptcpd
pkgver=0.13
pkgrel=1
pkgdesc="Multipath TCP Daemon"
url="https://mptcpd.mptcp.dev"
arch="all"
license="BSD-3-Clause"
makedepends="
	argp-standalone
	automake
	autoconf-archive
	ell-dev
	libtool
	linux-headers
	"
options="!check" # the tests require the libc
subpackages="
	$pkgname-dbg
	$pkgname-dev
	$pkgname-doc
	$pkgname-openrc
	mptcpize
	mptcpize-dbg:mptcpize_dbg
	mptcpize-doc:mptcpize_doc:noarch
	mptcp-get-debug:mptcp_get_debug:noarch
	"
source="https://github.com/multipath-tcp/mptcpd/releases/download/v$pkgver/mptcpd-$pkgver.tar.gz
	0001-include-define-__bswap_constant_-16-32-if-needed.patch
	0002-mptcpize-define-error-if-not-available.patch
	0003-config-special-case-for-default-logger.patch
	0004-scripts-use-short-stat-options.patch
	mptcpd.initd
	mptcpd.confd
	"

build() {
	# can be removed when 0002-mptcpize-define-error-if-not-available.patch
	# is dropped, same for 'automake', 'autoconf-archive' and 'libtool' deps
	autoreconf --install --symlink --force

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--with-kernel=upstream
	make
}

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

	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

mptcpize() {
	pkgdesc="Force apps to use MPTCP instead of TCP"
	amove usr/bin/mptcpize
	amove usr/lib/mptcpize
}

mptcpize_dbg() {
	pkgdesc="Force apps to use MPTCP instead of TCP (dbg)"

	mkdir -p "$subpkgdir"/usr/lib/debug/usr/bin/
	mv -v "$pkgdir"-dbg/usr/lib/debug/usr/bin/mptcpize.debug \
		"$subpkgdir"/usr/lib/debug/usr/bin/
	mkdir -p "$subpkgdir"/usr/lib/debug/usr/lib/
	mv -v "$pkgdir"-dbg/usr/lib/debug/usr/lib/mptcpize \
		"$subpkgdir"/usr/lib/debug/usr/lib/
}

mptcpize_doc() {
	pkgdesc="Force apps to use MPTCP instead of TCP (doc)"
	depends=""

	mkdir -p "$subpkgdir"/usr/share/man/man8/
	mv -v "$pkgdir"-doc/usr/share/man/man8/mptcpize.8* \
		"$subpkgdir"/usr/share/man/man8/
}

mptcp_get_debug() {
	pkgdesc="MPTCP debug info script"
	depends="iproute2"

	amove usr/libexec/mptcp-get-debug
}

sha512sums="
5dd53c9e1c92a3242ad84d93642116e77acb24c997219c98fe30a4c6d80b283de8878bcc84a6ac4eaf51ff6dd32cff5ed2a40a869c8304faa835f3b300dbca37  mptcpd-0.13.tar.gz
e5d8f61dc2fd34abc1b6b97bac5129638ec0677c69e0cd4003d0e6e78468d1a8528e4f981972c84c116f4158694ba8e25ad3c1d3c8851484cafbb7a5e333fe2c  0001-include-define-__bswap_constant_-16-32-if-needed.patch
15ae5d2149d82784b839e99e9be34dc8f3c9f04ff367e97f8eb36c2e0d210b1c0db653e7d3f920d621b20c95ea86604a8b77304333e698123252b7e5dda53262  0002-mptcpize-define-error-if-not-available.patch
f881425ee08885be1246f36dea30ddef83292df1f6bdd5d6d3263fbe4479ed8d70854e26b4c97d5f4da5d3cb43f931194ca6b7ff818f5c6081dbec1e55cd0c53  0003-config-special-case-for-default-logger.patch
4a9ae1f877d7f4bb463fd7659e25b2f52c233524c5643a9ba3b454d77a3ffdbaadc4aa344982168d8a66809f762fd9997b0ec365263cc49967f39bbab4943ee2  0004-scripts-use-short-stat-options.patch
cc210ec33c5b047aeeb60f687176dcd3cc62be5218275be595a5367faeff108b099446ecc2a0b0bb9f21ab20d0c408fb7e9c827cc3283c7bd127ad4677ae488b  mptcpd.initd
097109e69e6f8d51c2e40ea21ac18c6e9a4ee09e52bf7761b9cbd8e4a6be5a7b550f3a17df556a1597b8d3260a27c5d7b53f47b1027bfb6e431d655b6de5e4c7  mptcpd.confd
"
