# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: maz-1 <loveayawaka@gmail.com>

pkgname=ndiswrapper-arch
pkgver=1.61
_extramodules=extramodules-ARCH
pkgrel=65
pkgdesc="Module for NDIS (Windows Network Drivers) drivers supplied by vendors, kernel module for Arch kernel"
arch=('x86_64')
url="https://sourceforge.net/projects/ndiswrapper/"
license=('GPL')
depends=('linux')
makedepends=('linux-headers')
provides=('NDISWRAPPER-MODULE')
replaces=('ndiswrapper-module')
source=("ndiswrapper-$pkgver.tar.gz::https://github.com/pgiri/ndiswrapper/archive/v$pkgver.tar.gz"
        'linux-4.11.patch' 'linux-4.13.patch' 'linux-4.15.patch' 'linux-5.0.patch' 'linux-5.3.patch')
sha512sums=('85f550f2952137529e0e9855f4d94b7bbc64cbf8a84a31c1b75a4be09d97478a997e64fa6e1ff4e0d29a97a79fc3d4dab1ebdaa9edb3d627a215f47aa4d52823'
            '5350308406457658fb31c378d6f3dd2a34c7331aebe5bdc80744bf955f1144e88181441704ccc7532f55d6fbe8d410440fb8838c2955d688dde4b55f74fc6ba5'
            'de026a271cbfbefee99bc00a13c50be87294e5e2c5407d23cff6ce2d2a0c853542ce4f7e3e150741c7e8e32466fb1ab7cab266957da5bcca8376fb0f38e94482'
            '4296e7488d8c0cd971d70a81c01f24ab8e01c8611934024e2438181f0fb7c39a2c8201d48ab04659af2a8897ae93fb0810332e89c2a09a8140e216aed56db34b'
            '4918dcebd62ae577401469719f1a8866edd3dc97667aa3de287af1530aa68f50dc2508c883ecd2c9d1fe20f226ecd342b04b08f7a2cace0e531e5f49bbc12f2c'
            'c404f35280534b172235c5c578657d7a30ac2253c7c2abedd65a183d09390e95e7c3030cb409accb4d198ff0411482f8029f8664418c99d5672f92e9c733801d')

prepare() {
  cd ndiswrapper-$pkgver
  patch --no-backup-if-mismatch -p1 -i "$srcdir"/linux-4.11.patch
  patch --no-backup-if-mismatch -p1 -i "$srcdir"/linux-4.13.patch
  patch --no-backup-if-mismatch -p1 -i "$srcdir"/linux-4.15.patch
  patch --no-backup-if-mismatch -p1 -i "$srcdir"/linux-5.0.patch
  patch --no-backup-if-mismatch -p1 -i "$srcdir"/linux-5.3.patch
}

build() {
  _kernver="$(cat /usr/lib/modules/$_extramodules/version)"

  cd ndiswrapper-$pkgver/ndiswrapper
  make -C driver KVERS_UNAME="$_kernver"
}

package() {
  cd ndiswrapper-$pkgver/ndiswrapper
  install -Dt "$pkgdir/usr/lib/modules/$_extramodules" -m644 driver/*.ko
  find "$pkgdir" -name '*.ko' -exec xz {} +
}
