# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Carl Smedstad <carsme@archlinux.org>
# Contributor: Pavel Borzenkov <pavel@voidptr.ru>
# Contributor: aksr <aksr at t-com dot me>

pkgname=criu
pkgver=4.0
pkgrel=2
pkgdesc='Utilities to checkpoint and restore processes in userspace'
arch=('x86_64' 'aarch64')
url='https://criu.org'
license=(
  'GPL-2.0-only'
  'LGPL-2.1-only'
)
depends=(
  'gcc-libs'
  'glibc'
  'gnutls'
  'libbpf'
  'libbsd'
  'libdrm'
  'libnet'
  'libnl'
  'nftables'
  'protobuf-c'
  'python'
  'python-protobuf'
)
makedepends=(
  'asciidoc'
  'git'
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
  'xmlto'
)
# Can't run tests (only unit tests) due to privilege escalation required.
# https://github.com/checkpoint-restore/criu/issues/434
# checkdepends=(
#   'libaio'
#   'python-yaml'
# )
provides=(
  'libcompel.so'
  'libcriu.so'
)
options=('!lto')
source=("git+https://github.com/checkpoint-restore/criu#tag=v$pkgver")
sha512sums=('cdfaebfe37c2e1111383444a0575499bb4a6b7618a944921d8c2bfa7c2a72831557bc568f8457c70ea0d94b0e70549ed5f4d43134e0c58baa5ffab3c1b3e40c6')
b2sums=('4cf22e25a848007e5c7230aa1a60216f4ba98423be47442a00fd7d5c0079ac86901bfcd5c82d2ee7f4ab243bc1eb431328848317dc24c3c45d81250318bc9e21')

build() {
  cd "$pkgname"

  # shellcheck disable=SC2001
  export CFLAGS=$(echo "$CFLAGS" | sed 's/-Wp,-D_FORTIFY_SOURCE=[0-9]//g')
  make criu crit amdgpu_plugin docs
  python -m build --wheel --no-isolation crit
  python -m build --wheel --no-isolation --skip-dependency-check lib
}

check() {
  cd "$pkgname"

  make unittest
  # make test
}

package() {
  cd "$pkgname"

  make \
    DESTDIR="$pkgdir" \
    PREFIX=/usr \
    SBINDIR=/usr/bin \
    LIBDIR=/usr/lib \
    LIBEXECDIR=/usr/lib \
    install
  python -m installer --destdir="$pkgdir" crit/dist/*.whl
  python -m installer --destdir="$pkgdir" lib/dist/*.whl
  # Remove empty directory to silence namcap warning.
  rm -r "$pkgdir/usr/include/compel/common/asm"
}
