# Co-Maintainer: Alicja Michalska <ellyqw@mainlining.org>
# Co-Maintainer: Ingo Reitz <9l@9lo.re>
maintainer="WeirdTreeThing <bradyn127@protonmail.com>"
pkgname=linux-postmarketos-mediatek-mt81
pkgver=6.18.36
pkgrel=2
pkgdesc="Mainline kernel for mediatek mt8183/mt8192/mt8195/mt8186"
arch="aarch64"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	"
makedepends="
	bison
	clang
	devicepkg-dev
	elfutils-dev
	findutils
	flex
	linux-headers
	gzip
	lld
	llvm
	lz4
	openssl-dev
	pahole
	perl
	postmarketos-installkernel
	python3
	rsync
	xz
	zstd
"
replaces="linux-postmarketos-mtk-mt8183 linux-postmarketos-mediatek-mt8183 linux-postmarketos-mediatek-mt81xx"

_carch="arm64"

# Source
_config="config-$_flavor.$CARCH"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac

source="
	https://cdn.kernel.org/pub/linux/kernel/v${_kernver%%.*}.x/linux-$_kernver.tar.xz
	mt8183-fix-bluetooth.patch
	mt8186-enable-dpi.patch
	mt8186-ASoC-hdmi-codec-Add-event-handler-for-hdmi-TX.patch
	mt8186-SoC-mediatek-mt8186-correct-the-HDMI-widgets.patch
	mt8186-drm-bridge-it6505-Add-audio-support.patch
	mt8186-ASoC-mediatek-mt8186-make-FE-nonatomic-and-no_pcm.patch
	mtk-pmdomain.patch
	config-$_flavor.aarch64
"
builddir="$srcdir/linux-$_kernver"

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

build() {
	unset LDFLAGS
	make ARCH="$_carch" LLVM=1 \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	mkdir -p "$pkgdir"/boot

	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		LLVM=1 \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir"/usr \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

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


sha512sums="
533cafd1779ccde4fe9c0bd705d3b2b7a0f84ef1d15d72c82180d0f2d4c23c10c732e81ccaa1d0e4a0bdea55a708761021f777c48f5d2cadcb04c96dcb33ad83  linux-6.18.36.tar.xz
d74da1231181835bec82015da1b3f5b08a1fe9c3c35dd712e285891094d94d9427ceac75d32f74be3a635e17d93ad82b37adf97db8176efc91aed17535023fc2  mt8183-fix-bluetooth.patch
e4eaff9d3ec1a56ae2503dd353ad57bf072219e68c26ba8b894feb90d6ccb01bd131cdde8d238451258679aca1203a9ebdd888f01ee2a118d46f981ff4bcf54c  mt8186-enable-dpi.patch
2c282b7cd4f72c998d65e4160b9d1f9122676a6392ef45f734dbd5428754eccc06404a057ea19ea097bf6237e27b3483c271c1ed15b20e359419ab9fb61b8d83  mt8186-ASoC-hdmi-codec-Add-event-handler-for-hdmi-TX.patch
b2dcf3e3b9f80d185f587972ab6fc1f07e8ec7c7dbe3aa75c53ff6d3c7380ff4c3e6f394792976589d5e786923939a0860c70b486ae78925d0f122a5bf2516e0  mt8186-SoC-mediatek-mt8186-correct-the-HDMI-widgets.patch
e09b8fc578742b0efcfb7e4419b30de39feecf3303def62576110c98e3a7101c68c78d1276f885e585ee21536df1f2474df5816f0dffa8f99ea1df1c787fe2c6  mt8186-drm-bridge-it6505-Add-audio-support.patch
b4c005f705bbae87b93dd061b4d02f982f2dbce1c59635a02b501def1eb784b057d1555c2c11e868f81a91365dcd1c0fbecf85034b6da701011cb2b68ecb3404  mt8186-ASoC-mediatek-mt8186-make-FE-nonatomic-and-no_pcm.patch
06539b9c5cdaa41e4e0a4bfb8e300548cf95387db716a2f896062690075f07419e9e211c0cb5537caaa046cfae646e47413e12fde0a3c71c9f94868f464de208  mtk-pmdomain.patch
1b1a08e5d83493d29d9b7452fede88ca81b3756da1eedb1a2efcd937844f8d2284e6200d83ed0cb2a9f9a14c6b21bd0b1b6a7372f9c4782fdc15ceebac5692cf  config-postmarketos-mediatek-mt81.aarch64
"
