# Packager = Tuxcore <dev@tuxcore.org> 
pkgbase=libcap-ng
pkgname=(
  libcap-ng
  python-capng
)
pkgver=0.8.5
pkgrel=2
pkgdesc='A library for Linux that makes using posix capabilities easy'
arch=(x86_64)
url='https://people.redhat.com/sgrubb/libcap-ng/'
license=(
  GPL-2.0-or-later
  LGPL-2.1-or-later
)
depends=(glibc)
makedepends=(
  python
  swig
)
source=(
  https://github.com/stevegrubb/libcap-ng/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz
)
sha512sums=('3bd868c7f263b77edd2feda831470b407f1086b434618e54336fb78bbf8bf3bad53f4c006a2118fb594b16554f8f7ec2acb76e08be5586d0261684e9ba139231')
b2sums=('70d70da50aff6423cf98cc87512d691308ec73e4143b4deb4bbc32e764db856af60d2aab2fed6ead2c5662adccb1ebf3a72bc1a8990261e104b28d2b9225cf92')

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

prepare() {
  cd $pkgbase-$pkgver
  # make stupid autotools happy -_-
  touch NEWS
  autoreconf -fiv
}

build() {
  local configure_options=(
    --enable-static=no
    --prefix=/usr
    --with-python3
    --without-python
  )

  cd $pkgbase-$pkgver
  ./configure "${configure_options[@]}"
  make
}

check() {
  make check -C $pkgbase-$pkgver
}

package_libcap-ng() {
  provides=(
    libcap-ng.so
    libdrop_ambient.so
  )

  make DESTDIR="$pkgdir" install -C $pkgbase-$pkgver

  (
    cd "$pkgdir"
    _pick python-capng usr/lib/python*
  )
}

package_python-capng() {
  pkgdesc+=' (Python bindings)'
  depends+=(
    libcap-ng libcap-ng.so
    python
  )
  provides=(
    python-libcap-ng
  )

  mv -v python-capng/* "$pkgdir"
}

# vim: ts=2 sw=2 et:
