# $Id: PKGBUILD 74362 2012-07-25 19:30:22Z seblu $
# Maintainer: Sébastien Luttringer <seblu@aur.archlinux.org>
# Contributor: Balwinder S "bsd" Dheeman (bdheeman AT gmail.com)

pkgname=dkms
pkgver=2.2.0.3
pkgrel=10
pkgdesc='Dynamic Kernel Modules System'
arch=('any')
url='http://linux.dell.com/dkms/'
license=('GPL2')
depends=('linux-headers' 'kmod')
backup=('etc/dkms/framework.conf' "etc/conf.d/$pkgname")
source=("http://linux.dell.com/$pkgname/permalink/$pkgname-$pkgver.tar.gz"
        "$pkgname.rc"
        "$pkgname.conf"
        "$pkgname.service"
        "$pkgname.systemd"
        '01-broken-uninstall.patch')
md5sums=('11a8aaade2ebec2803653837c7593030'
         '814c4b9a9c2e59521e4dc6eaa5cb16e3'
         '8be6746da3df4dcb61cd2b1459974fce'
         '02e9744e3fdc3d2f68e46966fb32e260'
         '51c80e29c0ca600b4737c573d3311dbc'
         '2dfd8656dc79afd229c1481a90fb645b')

build() {
  patches=("$srcdir"/*.patch)
  cd $pkgname-$pkgver
  for p in "${patches[@]}"; do
    msg2 "Apply patch: ${p##*/}"
    patch -p1 -i "$p"
  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() {
  # upstream installer
  pushd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  popd
  # fix hardcoded paths
  sed -i "s|/sbin/depmod|depmod|" $pkgdir/usr/sbin/dkms
  # remove debian specific
  rm -r "$pkgdir/etc/kernel"
  # move bash completion in right place
  install -d -m 755 "$pkgdir/usr/share/bash-completion"
  mv "$pkgdir/etc/bash_completion.d" "$pkgdir/usr/share/bash-completion/completions"
  # add initscripts
  install -D -m 755 $pkgname.rc "$pkgdir/etc/rc.d/$pkgname"
  install -D -m 644 $pkgname.conf "$pkgdir/etc/conf.d/$pkgname"
  # add systemd
  install -D -m 644 $pkgname.service "$pkgdir/usr/lib/systemd/system/$pkgname.service"
  install -D -m 755 $pkgname.systemd "$pkgdir/usr/lib/systemd/scripts/$pkgname"
}

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