# Maintainer: Sébastien "Seblu" Luttringer <seblu@archlinux.org>

pkgname=nftables
epoch=1
pkgver=1.1.6
pkgrel=1
pkgdesc='Netfilter tables userspace tools'
arch=('x86_64' 'aarch64')
url='https://netfilter.org/projects/nftables/'
license=('GPL-2.0-only')
depends=('libmnl' 'libnftnl' 'gmp' 'readline' 'ncurses' 'jansson')
optdepends=('python: Python bindings'
            'python-jsonschema: Python bindings')
makedepends=('asciidoc' 'python' 'python-setuptools' 'python-build'
             'git' 'python-installer' 'python-wheel')
backup=('etc/nftables.conf')
validpgpkeys=('8C5F7146A1757A65E2422A94D70D1A666ACF2B21') # Netfilter Core Team
source=("https://www.netfilter.org/pub/nftables/nftables-${pkgver}.tar.xz"{,.sig}
        'nftables.conf'
        'nftables.service')
install=nftables.install
sha256sums=('372931bda8556b310636a2f9020adc710f9bab66f47efe0ce90bff800ac2530c'
            'SKIP'
            'f83d6f2f99f306866850c60ff0e343bbd9bc0c989d333ebe288563f7be4afe20'
            'deffeef36fe658867dd9203ec13dec85047a6d224ea63334dcf60db97e1809ea')

prepare() {
  cd $pkgname-$pkgver

  autoreconf -fiv
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --sysconfdir=/usr/share \
    --with-json \
    --with-cli=readline \
    --disable-python \
    --disable-debug
  make

  # Building the Python module separately due to the automatic build resulting
  # in an incorrect directory structure and unimportable module (see FS#79229)
  cd py
  python -m build --wheel --no-isolation
}

package() {
  pushd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  python -m installer --destdir="$pkgdir" py/dist/*.whl
  popd
  # basic safe firewall config
  install -Dm644 nftables.conf "$pkgdir/etc/nftables.conf"
  # systemd
  install -Dm644 nftables.service "$pkgdir/usr/lib/systemd/system/nftables.service"
}
