# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=hvtools
pkgver=4.11.9
_kernver=${pkgver%.*}
pkgrel=0
pkgdesc="Hyper-v tools"
url="http://www.kernel.org"
arch="all"
license="GPL2"
makedepends="$depends_dev linux-headers"
source="https://kernel.org/pub/linux/kernel/v4.x/linux-$_kernver.tar.xz
	https://kernel.org/pub/linux/kernel/v4.x/patch-$pkgver.xz
	hv_kvp_daemon.initd
	hv_vss_daemon.initd
	hv_fcopy_daemon.initd
	"

builddir="$srcdir"/linux-${_kernver}

prepare() {
	cd "$builddir"
	if [ "${pkgver%.0}" = "$pkgver" ]; then
		msg "Applying patch-$pkgver.xz"
		unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1 -N
	fi
}

build() {
	cd "$builddir"/tools/hv
	make
}

package() {
	cd "$builddir"/tools/hv
	install -d "$pkgdir"/usr/bin
	install -t "$pkgdir"/usr/bin \
		hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon
	for i in $source; do
		case $i in
		*.initd) install -Dm755 "$srcdir"/$i "$pkgdir"/etc/init.d/${i%.*};;
		esac
	done
}

sha512sums="6610eed97ffb7207c71771198c36179b8244ace7222bebb109507720e26c5f17d918079a56d5febdd8605844d67fb2df0ebe910fa2f2f53690daf6e2a8ad09c3  linux-4.11.tar.xz
0d9474810b175679ae1a6e1c59ea60da8d2c5fafdd736a827cf1abe5bbd99361a31a4584d3bc160ed83322d7876e822dbd537adf12c22a2dcec45acfcd645bca  patch-4.11.9.xz
25590c4253da6ad248875b19e222fbc283216c4557eebfb8e471a2ed3330be19d3bd4b1bc6d7c2aa4ca7a64aa565c80887cbad711fa8e3ec477a7b56ba014166  hv_kvp_daemon.initd
afcdbc83b9c01cb2fd1d6f1844925f0860a8b3352f50e2db2e7ebf8843b338d2aea8f5b1586ef12009022249da11aa9f6cba4fbe438ff59f3a734e2d425306ce  hv_vss_daemon.initd
4f327330eb755ef04d9475a03aab625a0690efcbb8c6f614b333189aa998391d57b3ddae8baec0cfbc3b280ceca1e9271c9cfc5f68c3becb37db0fc85935422a  hv_fcopy_daemon.initd"