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

pkgname=nftables
epoch=1
pkgver=1.1.5
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')
makedepends=('asciidoc' 'python' 'python-setuptools' 'python-build'
             'git' 'python-installer' 'python-wheel')
backup=('etc/nftables.conf')
validpgpkeys=('8C5F7146A1757A65E2422A94D70D1A666ACF2B21') # Netfilter Core Team
source=("git+https://git.netfilter.org/nftables.git#tag=v${pkgver}?signed"
        'nftables.conf'
        'nftables.service')
install=nftables.install
sha256sums=('5a257ae8eb39044e7f618be1ce8f21ab4713ee9ced933fe066d1e08f873eadf4'
            'f83d6f2f99f306866850c60ff0e343bbd9bc0c989d333ebe288563f7be4afe20'
            'deffeef36fe658867dd9203ec13dec85047a6d224ea63334dcf60db97e1809ea')

prepare() {
  cd $pkgname

  autoreconf -fiv
}

build() {
  cd $pkgname
  ./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
  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"
}
