# Maintainer: Armin K. <krejzi at email dot com>

pkgname=broadcom-wl_v5
pkgver=5.100.82.112
pkgrel=1
pkgdesc="Broadcom hybrid wireless device driver for Linux"
arch=(i686 x86_64)
url="http://www.broadcom.com/support/802.11/linux_sta.php"
license=('custom')
depends=('linux-headers')
source=("http://ftp.de.debian.org/debian/pool/non-free/b/broadcom-sta/broadcom-sta_${pkgver}.orig.tar.gz"
        distro.patch
        fixes.patch
        modprobe.d)
install=${pkgname}.install
md5sums=('3842465cf117f97445a39cf13d0e3c2f'
         '5ea63d8c69e891c8fff56a25a898c3ab'
         '246b2a67a5592293104615f5e2bacbb7'
         '3600df7db49c759c655bc6a7789b28d4')

if [[ ${CARCH} = "i686" ]]; then
   _arch=i386
else
   _arch=amd64
fi

_kernmajor="$(pacman -Q linux | awk '{print $2}' | cut -d - -f1 | cut -d . -f1,2)"
_extramodules="extramodules-${_kernmajor}-ARCH"
_kernver="$(cat /usr/lib/modules/${_extramodules}/version)"

prepare(){
  cd "broadcom-sta-${pkgver}/${_arch}"

  patch -Np1 -i "${srcdir}/distro.patch"
  patch -Np1 -i "${srcdir}/fixes.patch"
}

build() {
    cd "broadcom-sta-${pkgver}/${_arch}"

    make -C "/usr/lib/modules/${_kernver}/build" M=`pwd`
}

package() {
    cd "broadcom-sta-${pkgver}/${_arch}"

    install -D -m 644 wl.ko "${pkgdir}/usr/lib/modules/${_extramodules}/wl.ko"
    gzip "${pkgdir}/usr/lib/modules/${_extramodules}/wl.ko"

    install -D -m 644 "lib/LICENSE.txt" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
    install -D -m 644 "${srcdir}/modprobe.d" "${pkgdir}/etc/modprobe.d/broadcom-wl.conf"
}
