# Maintainer: Jenneron <jenneron@protonmail.com>
# Co-Maintainer: Segfault <awarnecke002@hotmail.com>
pkgname=linux-google-nyan
pkgver=6.1.27
pkgrel=0
pkgdesc="Mainline kernel fork for Google Nyan Chromebooks"
arch="armv7"
_carch="arm"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
"
makedepends="
	bison
	findutils
	flex
	installkernel
	openssl-dev
	perl
	gmp-dev
	mpc1-dev
	mpfr-dev
	xz
"

# Source
_config="config-$_flavor.$arch"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac
source="
	https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-${pkgver//_/-}.tar.xz
	$_config
	0001-ARM-dts-tegra-nyan-add-mmc-aliases.patch
	0002-ARM-tegra-nyan-fix-mic-jack-detection.patch
"
builddir="$srcdir/linux-${_kernver//_/-}"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$CARCH" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	# Prevent kernel self-decompression from overwriting initramfs
	truncate -s 10M "$pkgdir"/boot/vmlinuz

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

sha512sums="
657c241c8e4d62dabf7f1789c342352f757655129b8b21d92d3a90859d24f5f05f33aa39491851f690f7d9b0ba9234c47907ae05e1cb32a8d00fcf11ff71c61b  linux-6.1.27.tar.xz
af051de016dab75d91aad84bf02a0f877018330728b2afd50166da8c076c33fbb2d9ecc0b25fa787305713277e3a82560052db8947a32e75d1810327acebf817  config-google-nyan.armv7
be21d145f39d334e37f8dd79b78474c072e54502ba5c9ae63163f0ce30ffaa3a3448b05d153205ba8af7a761952ecddb3ae1a5b348902b4ce5f4f72138937fdb  0001-ARM-dts-tegra-nyan-add-mmc-aliases.patch
4ec3bc3bce229ba664ad98251dbcad9d224a3792d3149cc64b5a1eee0801f1a366b83447b55a02cb0915bd3ef63f42260dd55a286f68c727fcfc4d46bba4363a  0002-ARM-tegra-nyan-fix-mic-jack-detection.patch
"
