# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
# Contributor: Bob Fanger < bfanger(at)gmail >
# Contributor: Filip <fila pruda com>, Det < nimetonmaili(at)gmail >

pkgname=r8168
pkgver=8.047.04
pkgrel=1
pkgdesc="A kernel module for Realtek 8168 network cards"
url="http://www.realtek.com.tw"
license=("GPL")
arch=('x86_64')
depends=('glibc' 'linux')
makedepends=('linux-headers')
source=(https://github.com/mtorromeo/r8168/archive/$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('4a201c7691b66e47f19172367c70a14b8b38d600f0739719c57dba9c0cf3f17a')

build() {
	KERNEL_VERSION=$(</usr/lib/modules/extramodules-ARCH/version)
	msg2 "Kernel = $KERNEL_VERSION"

	cd "$pkgname-$pkgver"
	# avoid using the Makefile directly -- it doesn't understand
	# any kernel but the current.
	make -C /usr/lib/modules/$KERNEL_VERSION/build \
			SUBDIRS="$srcdir/$pkgname-$pkgver/src" \
			EXTRA_CFLAGS="-DCONFIG_R8168_NAPI -DCONFIG_R8168_VLAN" \
			modules
}

package() {
	cd "$pkgname-$pkgver"
	install -Dt "$pkgdir/usr/lib/modules/extramodules-ARCH" -m644 src/*.ko
	find "$pkgdir" -name '*.ko' -exec xz {} +

	echo "blacklist r8169" | \
		install -Dm644 /dev/stdin "$pkgdir/usr/lib/modprobe.d/r8168.conf"
}
