# Description: container namespace cgroup virtualisation for linux guests
# URL: https://linuxcontainers.org/lxc
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends: libseccomp meson ninja
# Optional: dnsmasq gnupg lua

name=lxc
version=5.0.3
release=1
source=(https://linuxcontainers.org/downloads/$name/$name-$version.tar.gz
  default.conf lxc-usernet lxc-users-setup lxc-users lxc-cgroups lxc-net)

build() {

  # fix pam_libdir
  sed "/pam_security/s/libdir/'\/', 'lib'/" -i $name-$version/meson.build

  prt-get isinst docbook2x && PKGMK_LXC+=' -D man=true' || PKGMK_LXC+=' -D man=false'

  meson setup $name-$version build $PKGMK_LXC \
    --prefix=/usr \
    --sysconfdir=/etc \
    --libexecdir=lib \
    --localstatedir=/var \
    -D distrosysconfdir=/etc/default \
    -D data-path=/var/lib/lxc \
    -D log-path=/var/log/lxc \
    -D rootfs-mount-path=/usr/lib/lxc/rootfs \
    -D runtime-path=/run \
    --buildtype=plain \
    --wrap-mode nodownload \
    -D b_lto=true \
    -D b_pie=true \
    -D init-script=sysvinit \
    -D pam-cgroup=true \
    -D apparmor=false

  meson compile -C build
  DESTDIR=$PKG meson install -C build

  install -d $PKG/etc/{default,rc.d}
  install -d $PKG/var/lib/misc

  install -m 0755 $SRC/lxc-users-setup $PKG/usr/sbin/

  rm -rf $PKG/usr/lib/lxc/rootfs/README \
    $PKG/usr/lib/lxc/lxc-apparmor-load \
    $PKG/usr/share/doc \
    $PKG/usr/share/lxc/config/common.conf.d/README

  mv $PKG/etc/init.d/* $PKG/etc/rc.d/
  install -m755 $SRC/lxc-cgroups $PKG/etc/rc.d/
  install -m755 $SRC/lxc-users $PKG/etc/rc.d/
  rmdir $PKG/etc/init.d/
  install -m644 $SRC/lxc-net $PKG/etc/default/
  rm $PKG/etc/lxc/default.conf
  install -m644 $SRC/default.conf $PKG/etc/lxc/
  install -m644 $SRC/lxc-usernet $PKG/etc/lxc/

  prt-get isinst bash-completion || rm -fr $PKG/etc/bash_completion.d \
    $PKG/usr/share/bash-completion
}
