# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgname=libteam
pkgver=1.31
pkgrel=3
pkgdesc="Library for controlling team network device"
arch=(x86_64)
url="http://libteam.org/"
license=(LGPL)
depends=(libnl libdaemon jansson libdbus bash zeromq)
makedepends=(python swig git doxygen graphviz)
_commit=3ee12c6d569977cf1cd30d0da77807a07aa77158  # tags/v1.31
source=("git+https://github.com/jpirko/libteam#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^v//;s/-/+/g'
}

prepare() {
  cd $pkgname

  # https://bugs.archlinux.org/task/68486
  git cherry-pick -n 61efd6de2fbb8ee077863ee5a355ac3dfd9365b9

  NOCONFIGURE=1 ./autogen.sh
}

build() {
  cd $pkgname
  ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
    --disable-static --libexecdir=/usr/lib
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make all html

  cd binding/python
  python setup.py build
}

check() {
  cd $pkgname
  make check
}

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

  install -Dt "$pkgdir/usr/lib/systemd/system" -m644 teamd/redhat/systemd/teamd@.service
  install -Dt "$pkgdir/usr/share/dbus-1/system.d" -m644 teamd/dbus/teamd.conf

  mkdir -p "$pkgdir/usr/share/doc/$pkgname"
  cp -a doc/api "$pkgdir/usr/share/doc/$pkgname"

  cd binding/python
  python setup.py install --root="$pkgdir" --optimize=1 --skip-build
}
