# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Maintainer: Frederik Schwan <freswa at archlinux dot org>
# Contributor: Sébastien "Seblu" Luttringer

pkgname=runc
pkgver=1.2.4
pkgrel=1
pkgdesc='CLI tool for managing OCI compliant containers'
arch=(x86_64 powerpc64le riscv64)
url='https://runc.io/'
license=(Apache)
provides=('oci-runtime')
depends=(libseccomp)
makedepends=(git go go-md2man)
optdepends=(
  'criu: checkpoint support'
)
options=(!lto)
source=("${pkgname}-${pkgver}.tar.xz::https://github.com/opencontainers/runc/releases/download/v${pkgver}/runc.tar.xz"
        "${pkgname}-${pkgver}.tar.xz.sig::https://github.com/opencontainers/runc/releases/download/v${pkgver}/runc.tar.xz.asc")
validpgpkeys=(
  "5F36C6C61B5460124A75F5A69E18AA267DDB8DB4"
  "C9C370B246B09F6DBCFC744C34401015D1D2D386"
  "C2428CD75720FACDCF76B6EA17DE5ECB75A1100E"
  "C9C370B246B09F6DBCFC744C34401015D1D2D386"
)
sha256sums=('86c087a141c233ce02dab089c1b9ec88ecbc0fedc1cc581989f6e53701323a65'
            'SKIP')

prepare() {
  mkdir -p src/github.com/opencontainers
  cp -r runc-${pkgver} src/github.com/opencontainers/runc
}

build() {
  cd src/github.com/opencontainers/runc
  export GOPATH="$srcdir"
  export BUILDTAGS='seccomp apparmor'
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-trimpath -mod=readonly -modcacherw"

  case "${CARCH}" in
    powerpc64) sed 's/-linkmode external//g' -i Makefile ;;
  esac
  make runc man
}

package() {
  cd src/github.com/opencontainers/runc

  install -Dm755 runc "$pkgdir/usr/bin/runc"
  install -Dm644 contrib/completions/bash/runc \
    "$pkgdir/usr/share/bash-completion/completions/runc"

  install -d "$pkgdir/usr/share/man/man8"
  install -m644 man/man8/*.8 "$pkgdir/usr/share/man/man8"
}
