# Contributor: Jeff Bilyk <jbilyk@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=rtpproxy
pkgver=2.0.0
pkgrel=4
pkgdesc="RTP proxy"
url="http://www.rtpproxy.org"
arch="all"
license="BSD"
depends=
depends_dev=
makedepends="$depends_dev libsndfile-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-debug $pkgname-tools"
source="$pkgname-$pkgver.tar.gz::https://github.com/sippy/rtpproxy/archive/v${pkgver}.tar.gz
	0001-Fix-overflow-bug-in-the-RTP-traffic-generator-which-.patch
	musl-fix-headers.patch
	define-byte-order.patch
	prevent-pthread-from-running-macro.patch
	rtpproxy.confd
	rtpproxy.initd"

_builddir="$srcdir/$pkgname-$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
}

build() {
	cd "$_builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		|| return 1
	make || return 1
}

debug() {
	pkgdesc="Debug version of rtpproxy"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/${pkgname}_debug "$subpkgdir"/usr/bin/
}

tools() {
	pkgdesc="User tools for $pkgname"
	mkdir -p "$subpkgdir"/usr/bin
	for _a in extractaudio makeann; do
		mv "$pkgdir"/usr/bin/$_a "$subpkgdir"/usr/bin/
	done
}

package() {
	cd "$_builddir"
	make DESTDIR="$pkgdir" install || return 1
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="d3991643e1e260890ec284a5cb0bacac012063512667215166551a1d534921caa035ab64452e2be7837b306ce4486cc604a9bb552254913f3a920d7756ad3711  rtpproxy-2.0.0.tar.gz
316c5af882b7d69085ac041852f81c19487b746638db6607c1312512806e0089df3972fff60c2207ad8f7314855c9ce585928e2d65c119fc82f025af761dc486  0001-Fix-overflow-bug-in-the-RTP-traffic-generator-which-.patch
bd05f24bfa66cd9491135efe341359cc4b16b80fd9c45fbfc880c7a82ba53ad5f2317dd6bfbaecfd0dd42ba0d54a55041403ba6409b8deff568fcb095892956d  musl-fix-headers.patch
8ab21c20ee87c0d9ef9a113b436eaecd34d93c596d761b2f4b8d746c34946acb41421ab24be6446dd2ad2c0c3e1cd894637d945e945a90e1af1eda091d91306f  define-byte-order.patch
ba54855fd147c8f166939b37a18c0576c55481c762c3f5b9e0ffa45e00eedeeaabb1d3fd4e45fe8f59f43064ecd852d87f83bcc8f746923219e9e3a795cf592e  prevent-pthread-from-running-macro.patch
e2ab3705329ffd10a8a5723ac3a07a2f98547f29b7055e1616ebbd141d6beff9c81d44579af9f3486f7835a7ac7228ecfe49cf09208438ed490843c6b100a104  rtpproxy.confd
84f05c765369aa5ef747361e57c557b2560ac734225f5aad99ba28f4178a73d2c937a316fa45f0d42cab27b1c9d033019d98ec67601f0b272b9b45c9196bf2fb  rtpproxy.initd"
