# Maintainer: Mike Crute <mike@crute.us>

_name=aws-ena-driver
_flavor=${FLAVOR:-vanilla}
_kpkg=linux-$_flavor
_kver=4.14.30
_krel=0

_kpkgver="$_kver-r$_krel"
_kabi="$_kver-$_krel-$_flavor"

_flavor="${FLAVOR:-vanilla}"
_ver=1.5.0
_rel=0

pkgname=$_name-$_flavor
pkgver=$_kver
pkgrel=$(( $_krel + $_rel ))
pkgdesc="Linux Kernel driver for Elastic Network Adapter (ENA) family"
url="https://github.com/amzn/amzn-drivers"
arch="x86 x86_64"
license="GPL-2.0"
# Upstream has no tests
options="!strip !check"
depends=
makedepends="linux-${_flavor}-dev=${_kver}-r${_krel}"
install=
source="https://github.com/amzn/amzn-drivers/archive/ena_linux_${_ver}.tar.gz ena.conf"
builddir="$srcdir/amzn-drivers-ena_linux_${_ver}"

prepare() {
	default_prepare
	# verify the kernel version
	local _kapkbuild=../../main/linux-$_pkgver/APKBUILD
	if [ -f $_kapkbuild ]; then
		(	. $_kapkbuild
			pkgname=$_name-$_flavor
			[ "$_kver" != "$pkgver" ] && die "please update _kver to $pkgver"
			[ "$_krel" != "$pkgrel" ] && die "please update _krel to $pkgrel"
			return 0
		)
	fi
}

build() {
	cd "$builddir/kernel/linux/ena"
	make BUILD_KERNEL="$_kabi"
}

package() {
	cd "$builddir/kernel/linux/ena"
	install -Dm644 "$srcdir"/ena.conf "$pkgdir"/etc/modules-load.d/ena.conf
	install -Dm644 ena.ko \
		"$pkgdir/lib/modules/${_kabi}/kernel/drivers/net/ethernet/amazon/ena/ena.ko"
}

sha512sums="32c3aee0aa806ffd1c6f78e3ce95c73699fd5fb0871a749d4ba54aba03390793ef92b4f76017d660bdf0907c91337d82b9570fffa93232f42becc240970310fa  ena_linux_1.5.0.tar.gz
479a96de0284c815cb4bc60ee129be831f97424f121ede3c14c3dfead162ebb5a3f16c535cc412caf0bdcf2de70c6c3f6cc1c83ff2d4aae1f5e3848279f927d2  ena.conf"
