# Maintainer: Christian Hesse <eworm@archlinux.org>

pkgname='virtualbox-host-modules-arch'
pkgver=7.2.8
pkgrel=13
pkgdesc='Virtualbox host kernel modules for Arch Kernel'
arch=('x86_64')
url='https://virtualbox.org/'
license=('GPL')
makedepends=('linux-headers' "virtualbox-host-dkms=$pkgver")
replaces=('virtualbox-modules' 'virtualbox-host-modules')
conflicts=('virtualbox-modules' 'virtualbox-host-modules'
           'virtualbox-host-dkms')
provides=('VIRTUALBOX-HOST-MODULES')

build() {
  _kernver="$(</usr/src/linux/version)"

  fakeroot dkms build --dkmstree "$srcdir" -m vboxhost/${pkgver}_OSE -k ${_kernver}
}

package(){
  depends=('linux')

  _kernver="$(</usr/src/linux/version)"

  install -Dt "$pkgdir/usr/lib/modules/$_kernver/extramodules" -m0644 \
    vboxhost/${pkgver}_OSE/${_kernver}/${CARCH}/module/*.ko

  # compress each module individually
  find "${pkgdir}" -name '*.ko' -exec zstd --rm -19 {} +

  # systemd module loading
  printf '%s\n' vboxdrv vboxnetadp vboxnetflt |
    install -D -m0644 /dev/stdin "$pkgdir/usr/lib/modules-load.d/$pkgname.conf"
}
