# Maintainer:

pkgbase=kata-containers
pkgname=(
  'kata-runtime'
  'kata-agent'
  'kata-containers-docs'
#  'kata-agent-ctl'
#  'kata-osbuilder'
#  'kata-packaging'
#  'kata-trace-forwarder'
)
pkgver=2.1.1
pkgrel=1
pkgdesc="Secure container runtime with lightweight virtual machines"
arch=('x86_64')
url="https://katacontainers.io/"
license=('Apache')
depends=()
makedepends=('go' 'git' 'rust')
checkdepends=()
provides=()
conflicts=()
replaces=()
backup=()
options=()
install=
changelog=
source=("$pkgbase-$pkgver.tar.gz::https://github.com/kata-containers/kata-containers/archive/$pkgver.tar.gz")
b2sums=('32b4b9e7f139cc47ca53d4f4b7dcf7b3a2008f68c98622ddcc846d9c60204b89d8a569f5179033a3504555071c5bb8dd7afc9ba8133c7142e23bfbbceb70e217')

# common make flags for runtime + agent
_RUNTIME_FLAGS=(
  -C "$pkgbase-$pkgver/src/runtime"
  PREFIX=/usr
  LIBEXECDIR=/usr/lib
  PKGLIBEXECDIR=/usr/lib/kata-containers
  DEFAULTSDIR=/usr/share
  LIBC=gnu
)
_AGENT_FLAGS=(
  -C "$pkgbase-$pkgver/src/agent"
  BUILD_TYPE=release
  BINDIR=/usr/bin
  LIBC=gnu
)

prepare() {
  mkdir go cargo
}

build() {
  # runtime
  GOPATH="$srcdir/go" make "${_RUNTIME_FLAGS[@]}"
  # agent
  CARGO_HOME="$srcdir/cargo" make "${_AGENT_FLAGS[@]}"
}

package_kata-runtime() {
  pkgdesc+=" (runtime)"
  optdepends=('bash-completion: for shell auto-completion')
  GOPATH="$srcdir/go" make "${_RUNTIME_FLAGS[@]}" DESTDIR="$pkgdir" install
}

package_kata-agent() {
  pkgdesc+=" (agent)"
  CARGO_HOME="$srcdir/cargo" make "${_AGENT_FLAGS[@]}" DESTDIR="$pkgdir" install
}

package_kata-containers-docs() {
  pkgdesc+=" (documentation)"

  cd "$pkgbase-$pkgver"
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgbase" *.md CODEOWNERS
  cp -rv "$pkgbase-$pkgver/docs" "$pkgdir/usr/share/doc/$pkgbase"
}