# Maintainer: Natanael Copa <ncopa@alpinelinux.org>

_flavor=hardened
_kpkg=linux-$_flavor
_kver=4.9.73
_kpkgrel=0
_mypkgrel=0

_kpkgver="$_kver-r$_kpkgrel"
_abi_release=${_kver}-${_kpkgrel}-${_flavor}
_realname=devicemaster-linux

pkgname=${_realname}-${_flavor}
pkgver=$_kver
# when changing _realver we *must* bump _mypkgrel
_realver=7.15
pkgrel=$(( $_kpkgrel + $_mypkgrel ))
pkgdesc="NS-Link Device Drivers $_realver for linux-$_flavor"
url="http://www.comtrol.com/resources/product-resources-white-papers/ns-link-device-drivers"
arch="x86 x86_64 armhf"
license="GPL"
depends="linux-${_flavor}=${_kpkgver}"
makedepends="linux-${_flavor}-dev=${_kpkgver} linux-headers"
install=
install_if="$_kpkg=$_kpkgver $_realname"
subpackages=""
provides="${_realname}-grsec=${pkgver}-r${pkgrel}"
source="http://dev.alpinelinux.org/archive/devicemaster-linux/devicemaster-linux-$_realver.tar.gz
	nslink.patch
	"

prepare() {
	# verify the kernel version
	(if [ -f ../../main/linux-${_flavor}/APKBUILD ]; then
		_name=$pkgname
		. ../../main/linux-${_flavor}/APKBUILD
		pkgname=$_name
		[ "$_kver" != "$pkgver" ] \
			&& die "please update _kver to $pkgver"
		[ "$_kpkgrel" != "$pkgrel" ] \
			&& die "please update _kpkgrel to $pkgrel"
	fi) || return 1

	cd "$srcdir/$_realname-$_realver"
	for i in $source; do
		case $i in
		*.patch|*.diff)
			msg "Applying $i"
			patch -p1 -i "$srcdir"/$i || return 1
			;;
		esac
	done
}

build() {
	cd "$srcdir/$_realname-$_realver"
	make -C /lib/modules/$_abi_release/build SUBDIRS="$PWD" modules \
		V=1 || return 1
}

package() {
	cd "$srcdir/$_realname-$_realver"
	mkdir -p "$pkgdir/lib/modules/${_abi_release}/misc/"
	cp *.ko "$pkgdir/lib/modules/${_abi_release}/misc/" || return 1
}

sha512sums="794f680613db6462f1452e32f17ab7e30e637d0a77d4c7c5cf43650776f5ec0d3c5144ebdf92fc5bf0f2f0fba456c2710d2cd2280981a208ff936b472388c3ba  devicemaster-linux-7.15.tar.gz
1af5aa054c19f25d6090bc00d7df38edfa764e9bb6105ba89c0952740379d2d3af9df53ea4e8a6cc5044835630d53552bdf9c025af602deaf6c241cab1836cc5  nslink.patch"
