# Maintainer: Sébastien Luttringer
# Contributor: Balwinder S "bsd" Dheeman (bdheeman AT gmail.com)

pkgname=dkms
pkgver=2.7.1
pkgrel=1
pkgdesc='Dynamic Kernel Modules System'
arch=('any')
url='https://github.com/dell/dkms'
license=('GPL2')
depends=('bash' 'kmod' 'gcc' 'make' 'patch')
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.sh'
        '0001-Revert-Make-newly-installed-modules-available-immedi.patch')
md5sums=('SKIP'
         '90f1486e0af9aab85e8c60d456802c63'
         '2e8ffd0c2ddec02872d0234befd129fd'
         '80632f6a454b35bcade2bed287f13c7b'
         'd3b91ef709f567a375f4bbdbd3291d2b')

prepare() {
  cd dkms

  # apply patch from the source array (should be a pacman feature)
  local filename
  for filename in "${source[@]}"; do
    if [[ "$filename" =~ \.patch$ ]]; then
      msg2 "Applying patch ${filename##*/}"
      patch -p1 -N -i "$srcdir/${filename##*/}"
    fi
  done

  # /usr move
  msg2 '/usr move patching'
  for i in dkms{,_framework.conf,.bash-completion,.8,_common.postinst}; do
    sed -ri 's,/lib/modules,/usr/lib/modules,g' "$i"
  done
}

package() {
  # alpm hook
  install -D -m 644 hook.install "$pkgdir/usr/share/libalpm/hooks/70-dkms-install.hook"
  install -D -m 644 hook.remove "$pkgdir/usr/share/libalpm/hooks/70-dkms-remove.hook"
  install -D -m 755 hook.sh "$pkgdir/usr/lib/dkms/alpm-hook"
  # upstream installer
  cd dkms
  # we don't need kconf files, so we install them outside $pkgdir
  make \
    DESTDIR="$pkgdir" \
    SBIN="$pkgdir/usr/bin" \
    BASHDIR="$pkgdir/usr/share/bash-completion/completions" \
    KCONF="$srcdir"/kconf \
    install
}

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