# Maintainer: Vitaliy Ognev <vitaliy.ognev@gmail.com>
pkgname=linux-powkiddy-x55
pkgdesc="The $pkgname kernel and modules"
pkgver=6.8.6
pkgrel=0
arch="aarch64"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native pmb:kconfigcheck-community"
makedepends="
	bash
	bison
	findutils
	flex
	gmp-dev
	linux-headers
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
	rsync
	xz
"

_flavor="powkiddy-x55"
_config="config-$_flavor.$arch"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac
_version="$_kernver-$pkgrel.$_flavor"

builddir="$srcdir/linux-$_kernver"
source="
	https://cdn.kernel.org/pub/linux/kernel/v${_kernver%%.*}.x/linux-$_kernver.tar.xz
	rtw88_wifi_fix.patch
	$_config
"

prepare() {
	default_prepare

	cp "$srcdir/config-$_flavor.$arch" .config
	echo "${_version#$_kernver}" > localversion

	make ARCH=arm64 olddefconfig
}

build() {
	unset LDFLAGS
	make ARCH=arm64 Image modules dtbs
}

package() {
	local _modulesdir="$pkgdir/lib/modules/$_version"

	install -Dm644 arch/arm64/boot/Image "$pkgdir"/boot/vmlinuz
	make ARCH=arm64 \
		INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH="$pkgdir" modules_install \
		INSTALL_DTBS_PATH="$pkgdir/boot/dtbs" dtbs_install

	rm -f "$_modulesdir"/source "$_modulesdir"/build

	install -D include/config/kernel.release \
		-t "$pkgdir"/usr/share/kernel/$_flavor/
}

sha512sums="
5da8000a640243d06c456eb4102592134fcc5051785d91c53845fd693d0b0aca9751a7179ab8c8bdc633fc039c7ce8cfbec8357fdca9d01509b2dfb251b2586c  linux-6.8.6.tar.xz
b38ed4cfe0f20b440426c4ba55eb727cfa64f01370f22d7aca486df4f44aceec1c1d0790c29b8984b151bee0d3ef671253d220dc0c7bec9fef6a4ce1b6cf6169  rtw88_wifi_fix.patch
98e005a5d456a6c42dd8ae6b758737ef8a42f15edd3a418b148bfc2bace8157973dc42155c1c547dfe5ba643934bd25fd41a77bbf4838a0bbb30f7f774582b28  config-powkiddy-x55.aarch64
"
