# Maintainer: Michael Tremer <michael.tremer@ipfire.org>
#
# This builds the package from the source tree that this file is in:
#
#   cd contrib/archlinux && makepkg --syncdeps

pkgname=fireperf
pkgver=0.3.0
pkgrel=1
pkgdesc="Network benchmarking tool that tests what is in between, like a firewall"
arch=("x86_64")
url="https://www.ipfire.org/"
license=("GPL-3.0-or-later")
depends=(
	glibc
	liburing
	ncurses
)
makedepends=(
	asciidoc
	autoconf
	automake
	docbook-xsl
	git
	intltool
	libtool
	libxslt
	pkgconf
)
checkdepends=(
	iperf
	iperf3
	python
)

# The root of the source tree
_srcdir="${startdir}/../.."

pkgver() {
	cd "${_srcdir}"

	# Fetch the version from configure.ac
	local version="$(sed -n '/^AC_INIT/,/)/ s/^\s*\[\([0-9][0-9.]*\)\],$/\1/p' configure.ac)"

	# A release is being called what it is
	if git describe --exact-match --tags HEAD &>/dev/null; then
		printf "%s" "${version}"

	# Append the number of commits and the commit ID if we are building from Git
	elif git rev-parse --git-dir &>/dev/null; then
		printf "%s.r%s.g%s" "${version}" \
			"$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"

	else
		printf "%s" "${version}"
	fi
}

build() {
	cd "${_srcdir}"

	./autogen.sh
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc

	make
}

check() {
	cd "${_srcdir}"

	make check
}

package() {
	cd "${_srcdir}"
	make DESTDIR="${pkgdir}" install

	install -Dm644 COPYING -t "${pkgdir}/usr/share/licenses/${pkgname}"
}
