# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgbase=libcap-ng
pkgname=(
  libcap-ng
  python-capng
)
pkgver=%version%
pkgrel=%release%
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=('3e640ba4bfa2d5b5d0eb463abca3b2c745b10e929571c0ec32eb068bdc41fd95e19f7131893a22ceebb4d1f1083d3d87d9a32f0808442d594ac5940791152acf')
b2sums=('f4ea9780b87cdd4f9fa85d4ad3960afe654bc8aa6f5aa298ec87b7d90c87dd981f81577e5113ed76d83aa39c959160bf4deee57be9b458a98f8715e6f7b8dd33')

_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:
