# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=rtpengine
pkgver=12.2.1.4
pkgrel=0
pkgdesc="Proxy for RTP traffic and other UDP based media traffic"
url="https://github.com/sipwise/rtpengine"
arch="all"
license="GPL-3.0-only"
makedepends="
	curl-dev
	ffmpeg-dev
	gperf
	glib-dev
	hiredis-dev
	iptables-dev
	json-glib-dev
	libevent-dev
	libmnl-dev
	libnftnl-dev
	libpcap-dev
	libwebsockets-dev
	mariadb-dev
	openssl-dev>3
	opus-dev
	pcre-dev
	perl
	spandsp-dev
	xmlrpc-c-dev
	zlib-dev
	"
# checkdepends="perl-bencode perl-net-interface perl-socket6"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc $pkgname-recording"
pkgusers="rtpengine"
pkggroups="rtpengine"
source="$pkgname-$pkgver.tar.gz::https://github.com/sipwise/rtpengine/archive/mr$pkgver.tar.gz
	$pkgname.initd

	README.alpine

	fix-default-config.patch
	0001-do-not-build-man-pages.patch
	"
builddir="$srcdir"/$pkgname-mr$pkgver

build() {
	export CFLAGS="-fomit-frame-pointer"
	export RTPENGINE_VERSION="$pkgver"
	make
}

# TODO: There's a real test suite available,
# but some needed packages are missing
check() {
	./daemon/rtpengine --version
	# make check
}

package() {
	install -Dm644 LICENSE "$pkgdir"/usr/share/doc/$pkgname/LICENSE
	install -Dm644 "$srcdir"/README.alpine "$pkgdir"/usr/share/doc/$pkgname/README.alpine

	install -Dm755 daemon/rtpengine "$pkgdir"/usr/bin/rtpengine
	install -Dm644 etc/$pkgname.conf "$pkgdir"/etc/rtpengine/rtpengine.conf
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	ln -s rtpengine "$pkgdir"/etc/init.d/$pkgname-recording

	#install -d "$pkgdir"/usr/share/man/man1
	#gzip -c daemon/rtpengine.8 > "$pkgdir"/usr/share/man/man1/rtpengine.1.gz
	#gzip -c recording-daemon/rtpengine-recording.8 \
	#	> "$pkgdir"/usr/share/man/man1/rtpengine-recording.1.gz
}

recording() {
	depends="$pkgname"

	install -Dm755 "$builddir"/recording-daemon/rtpengine-recording \
		"$subpkgdir"/usr/bin/rtpengine-recording
	install -Dm644 "$builddir"/etc/rtpengine-recording.conf \
		"$subpkgdir"/etc/$pkgname/rtpengine-recording.conf

	local dir
	for dir in lib spool; do
		install -d -o rtpengine -g rtpengine "$subpkgdir"/var/$dir/$pkgname
	done
}

sha512sums="
6dea7c37b83c88a822b695a9b1e174450d40dbb85982418d8d092f184c1856b7c4cd49b67c6906ce923e774830b90eb7188c978c9624df79c04734b6c78cdf5f  rtpengine-12.2.1.4.tar.gz
a696277b8ef477420db13e4628818b728f318a8ba52f727ce8b7969f5f0182f9389f3b931eb4542ce1fe1a6fbc4dcdc3d6959090de76b1981f434b3fafebc224  rtpengine.initd
25777a5deb0d4c3c00fc74c752b5f0539a8026f90e5c6cf15d01fe46d93b35ea17b5a5729dcb98f1b4de87c148df128eaba6a03490a2e528cd873a714953f63b  README.alpine
73a93ccc287982092691e97eb743600332d842ba7d87336dcee20604bb638b9b349333072249a616f01b47dded38452263769252eca7172f954591e6306fd9d6  fix-default-config.patch
7c6adeed8bd1bd3a75304a5da6835a748ba63bb9af1fd9fe72a0efb68d0bfe7c6401d44db66da966abf8b8d97d54aafdd8d064c047bfeca927b38bfcb7aeff65  0001-do-not-build-man-pages.patch
"
