# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Zsolt Varadi <sysop_xxl@fibermail.hu>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - patch arch-x86_64.patch for AArch64

pkgname=netbrake
pkgver=0.2
pkgrel=7
pkgdesc="Netbrake is an utility to limit the bandwidth used by a process"
arch=(x86_64)
url="http://www.hping.org/netbrake/"
license=('GPL')
depends=(glibc)
makedepends=()
source=($url/$pkgname-$pkgver.tar.gz
	arch-x86_64.patch)
sha512sums=('be19e7a85a10060874048cfce2715fa0766f477f584ba958fcee05737302f21ed658660f62d55c844440fa61e99689bcf3c3a6454638f11f0e68d52cd850fde5'
            '74067212147f05a36d59549cf90d4639e8e9f85393c8e2062438b62eb84fb5fd6a72a79edbb452aac20aa8d6742edc45f60c5314b49830ccfcf0ac9ae18cacfa')

build() {
  cd "$srcdir"/$pkgname

  [ $CARCH == "x86_64" -o $CARCH == "aarch64" ] && patch -Np1 <../arch-x86_64.patch

  cp Makefile.in Makefile
  sed -i -e 's|LIBPATH=@LIBPATH@|LIBPATH=/usr/lib|g' Makefile
  sed -i -e 's|BINPATH=@BINPATH@|BINPATH=/usr/bin|g' Makefile
  sed -i -e 's|COMPILE_TIME=@COMPILE_TIME@|COMPILE_TIME=-DNB_HTTPFS|g' Makefile

  cp netbrake.h.in netbrake.h
  sed -i -e 's|#define LIBPATH "@LIBPATH@"|#define LIBPATH "/usr/lib"|g' netbrake.h

  make
}

package() {
  cd "$srcdir"/$pkgname

  mkdir -p "$pkgdir"/usr/bin
  mkdir -p "$pkgdir"/usr/lib

  install -m 755 netbrake "$pkgdir"/usr/bin
  install -m 755 libnetbrake.so.0.1 "$pkgdir"/usr/lib
}