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

_flavor=grsec
_kpkg=linux-$_flavor
_kver=3.13.7
_kpkgrel=0
_mypkgrel=0

# verify the kernel version before entering chroot
if [ -f ../linux-${_flavor}/APKBUILD ]; then
	. ../linux-${_flavor}/APKBUILD
fi

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

pkgname=${_realname}-${_flavor}
pkgver=$_kver
# when chaning _bmdver we *must* bump _mypkgrel
_bmdver=9.8
pkgrel=$(( $_kpkgrel + $_mypkgrel ))
pkgdesc="Black Magic Design video driver"
url="http://blackmagicdesign.com"
arch=""
license="GPL"
depends="linux-${_flavor}=${_kpkgver}"
makedepends="linux-${_flavor}-dev=${_kpkgver}"
install=
subpackages=""
source="
http://software.blackmagicdesign.com/DesktopVideo/Blackmagic_Desktop_Video_Linux_$_bmdver.tar.gz
	"

_builddir="$srcdir"/desktopvideo-${_bmdver}a2-x86_64/usr/src/desktopvideo-${_bmdver}a2
prepare() {
	cd "$srcdir"
	local _arch="$CARCH"
	if [ "$CARCH" = "x86" ]; then
		_arch="i386"
	fi
	msg "unpacking desktopvideo-$_bmdver-$_arch.tar.gz"
	tar -zxf desktopvideo-$_bmdver-x86_64.tar.gz
	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"/desktopvideo-*/usr/src/desktopvideo-*/
	make KERNELRELEASE="${_abi_release}" \
		|| return 1
}

package() {
	cd "$srcdir"/desktopvideo-*/usr/src/desktopvideo-*/
	make -C /lib/modules/$_abi_release/build M="$PWD" \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_PATH="$pkgdir"/boot \
		modules_install

}

md5sums="2897ccc96fcf19e887fdf9c8f6d3d4f5  Blackmagic_Desktop_Video_Linux_9.8.tar.gz"
sha256sums="6977360490c806f9952028d50bc10782d5878e5d42bd7c0f5eb070b3b6e1116c  Blackmagic_Desktop_Video_Linux_9.8.tar.gz"
sha512sums="af4ccd5f9732633c4b3756766cd54c3329bf9edeb640462bb316e9c2b782550399806973a51e51c52fa47eaa018a11889b343cc3c1531282cc6524c6f630fce1  Blackmagic_Desktop_Video_Linux_9.8.tar.gz"