pkgname=netperf
pkgver=2.7
pkgrel=0
arch=('i386' 'x86_64')
url="https://github.com/HewlettPackard/netperf"
license=('GPL')
source=("https://github.com/HewlettPackard/netperf/archive/netperf-$pkgver.$pkgrel.tar.gz")
md5sums=('e0d45b5bca1eee2aef0155de82366202')

build()
{
	cd "$srcdir/$pkgname-$pkgname-$pkgver.$pkgrel"
	
	# the orginal config.guess is too old to guess new system type
	# so download latest version if it guess failed
	./config.guess > /dev/null 2>&1 || {
		curl -s -o config.guess 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'
		curl -s -o config.sub 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'
	}

	# sendfile_tcp_stream() misses assignment of len and it is possible
	# for random len to trigger the following issue, so fix it.
	# stderr: netperf: data send error: sendfile: No space left on device
	# stderr: len was -1847701200 send_size was 5120
	sed -i 's/(netperf_sendfile/(len = netperf_sendfile/g' src/nettest_bsd.c

	local configure_flags=(
				--prefix="$pkgdir/lkp/benchmarks/$pkgname"
				--enable-demo
				--enable-unixdomain
				--enable-sctp
				--enable-dccp
				--enable-burst
	)

	CFLAGS="-std=gnu89" ./configure "${configure_flags[@]}"
	make
}

package() {
	cd "$srcdir/$pkgname-$pkgname-$pkgver.$pkgrel"
	make install
}
