# Maintainer: Sébastien Luttringer
# Maintainer: Christian Heusel <gromit@archlinux.org>
# Contributor: Balwinder S "bsd" Dheeman (bdheeman AT gmail.com)

pkgname=dkms
pkgver=3.4.2
pkgrel=1
pkgdesc='Dynamic Kernel Modules System'
arch=('any')
url='https://github.com/dell/dkms'
license=(GPL-2.0-or-later)
depends=(
  bash
  clang
  coreutils
  gawk
  gcc
  kmod
  lld
  llvm
  make
  patch
  sed
)
makedepends=(
  git
)
optdepends=('linux-headers: build modules against the Arch kernel'
            'linux-lts-headers: build modules against the LTS kernel'
            'linux-zen-headers: build modules against the ZEN kernel'
            'linux-hardened-headers: build modules against the HARDENED kernel')
backup=('etc/dkms/framework.conf')
install=$pkgname.install
source=("git+https://github.com/dell/dkms.git#tag=v$pkgver"
        'hook.install'
        'hook.remove'
        'hook.upgrade'
        'hook.sh')
sha256sums=('e46d352f1ce4852fd61ac55ecec28f4f86fc5e0fd1c0dd046b45ade487852566'
            'acdc5b45cc018cea04ee1aec56fd8fc3a2de62cf7bc41acf53b3790872120998'
            '326515cc7d00f93760beb844434ca7442caf7a9424614aa95a8f6d1ab79e15df'
            '4f8dff7716e73a8bba885638f12e3cdc9e87daec1896f75e700b981527e43870'
            'c1b4a4e2e4e0e0e59ee0887403e79d60b209f3878dbbec6612573f13b90cce01')

package() {
  # alpm hooks
  install -D -m 644 hook.install "$pkgdir/usr/share/libalpm/hooks/70-dkms-install.hook"
  # both upgrade and remove hooks are removing dkms modules.
  # remove always call depmod while upgrade never, as install will later.
  # upgrade is run before remove in order to have the cleanest depmod file,
  # if something goes wrong before the depmod call in install hook.
  install -D -m 644 hook.upgrade "$pkgdir/usr/share/libalpm/hooks/70-dkms-upgrade.hook"
  install -D -m 644 hook.remove "$pkgdir/usr/share/libalpm/hooks/71-dkms-remove.hook"
  # hook helper
  install -D -m 755 hook.sh "$pkgdir/usr/share/libalpm/scripts/dkms"
  # upstream installer
  cd dkms
  # we don't need kconf files and libdir is only for debian stuff, so
  # we install them outside of $pkgdir
  make \
    DESTDIR="$pkgdir" \
    SBIN=/usr/bin \
    KCONF=/../trash \
    LIBDIR=/../trash \
    MODDIR=/usr/lib/modules \
    install
}

# vim:set ts=2 sw=2 et:
