# Maintainer: BinaryCraft <keep.it.sns@gmail.com>
# Co-Maintainer: Jenneron <jenneron@protonmail.com>
# Based on https://github.com/hexdump0815/linux-mainline-mediatek-mt81xx-kernel
pkgname=linux-postmarketos-mediatek-mt8183
pkgver=6.1.28
pkgrel=1
pkgdesc="Mainline kernel for mediatek mt8183"
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
	devicepkg-dev
	findutils
	flex
	postmarketos-installkernel
	openssl-dev
	perl
	rsync
	gzip
	xz
	gmp-dev
	mpc1-dev
	mpfr-dev
	lz4
	zstd
"
replaces="linux-postmarketos-mtk-mt8183"

_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
	01-RESEND-v2-1-2-drm-panel-Add-inx-Himax8279d-MIPI-DSI-LCD-panel-driver.patch
	03-v2-1-4-arm64-dts-mt8183-Add-katsu-board.patch
	04-v2-2-4-arm64-dts-mt8183-Add-kukui-jacuzzi-makomo-board.patch
	05-v2-3-4-dt-bindings-arm64-dts-mediatek-Add-mt8183-kukui-katsu.patch
	06-v2-4-4-dt-bindings-arm64-dts-mediatek-Add-mt8183-kukui-jacuzzi-makomo.patch
	07-1-2-arm64-dts-mt8183-Add-kukui-jacuzzi-cerise-board.patch
	08-2-2-dt-bindings-arm64-dts-mediatek-Add-mt8183-kukui-jacuzzi-cerise.patch
	09-add-new-dtbs-to-makefile.patch
	CHROMIUM-ARM64-dts-add-vdec-venc-h264-dtsi.patch
	mt8183-cadmium-kukui.enable-ite.patch
	mt8183-fix-audio-module-loading.patch
	mt8183-fix-bluetooth.patch
	mt8183-kukui-disable-unsupported-thermal-zones.patch
	mt8183-kukui-jacuzzi-fennel14-rt1015p-sound.patch
	mt8183-kukui-jacuzzi-fix-display-resume.patch
	mt8183-kukui-jacuzzi-hack-dpms-resume.patch
	mt81xx-fix-low-speed-usb-devices.patch
	mt81xx-usb-02.patch
	config-$_flavor.aarch64
"
builddir="$srcdir/linux-$_kernver"

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

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

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

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


sha512sums="
7215e62df10847e8bce432880e0756e8a5f56eb8b8abb54f9e1eb8871ce7bd56d765be0f9a40a8dae4d135b2f9a0dab7f6b3d2691d73b0c47f05811194dee8bd  linux-6.1.28.tar.xz
06e901fd36d4c3a8b51673ed6682a51229856259a4a0c83e65ed10a234c24a4a8828e9f6ed3101713470a25db10af9d5bab29c480b7f5c87af6bd7e81d8c0fe7  01-RESEND-v2-1-2-drm-panel-Add-inx-Himax8279d-MIPI-DSI-LCD-panel-driver.patch
4c7a89fd1e3e7b4589fe3c2addc7c4963cec7ebabf49413b1d6db92386b4b2ba7bf25c961aaa53fc344a4684871b4132806aa4b8c1a63e091651e548bab750ef  03-v2-1-4-arm64-dts-mt8183-Add-katsu-board.patch
a0742fa788d13c836d9dc8827c55a14e804ce77234627f2689fd511b14e5fba17b00f5a8cebd9ae4fa4c644d87cc98d4f18eba385ec4f57bb6fe07d3aff057fd  04-v2-2-4-arm64-dts-mt8183-Add-kukui-jacuzzi-makomo-board.patch
7d29cefe1e338868c6f31516dcff73ef1fdb5e50353ffd0874018bee1c9c116dea65b0bea6e9a5d31f416958ff025a685234e684557705f4675ad4710709e197  05-v2-3-4-dt-bindings-arm64-dts-mediatek-Add-mt8183-kukui-katsu.patch
53279b9019c4aa94488405a823c501734f536acc6f68c7d89f3f76fba04cde897c229ab59d22e97acd68f8ab9fc75ad39bb74fef777a1dbbdf1788bf19ae52c4  06-v2-4-4-dt-bindings-arm64-dts-mediatek-Add-mt8183-kukui-jacuzzi-makomo.patch
20be60004e19068e652010f18353f93a289b109a4b13cfa85184401a13f02417aea644e29accf5c21d6cf511044f2024e3872b211512d15e301ca34613ee0077  07-1-2-arm64-dts-mt8183-Add-kukui-jacuzzi-cerise-board.patch
27e1e536f446dc278ce8a9dd9bd64e5ec6678589b2ca276be7bab5e0a80f119052e9109e6834357a57bbffe30fda48e03d24531f53ad0225f42ad075142f3a37  08-2-2-dt-bindings-arm64-dts-mediatek-Add-mt8183-kukui-jacuzzi-cerise.patch
604fb37887786a2919e93648fb3fd002ce4b948b35a915931e3f2bf3f3a1451fad4f6e042cd0fd9aa7f11bba5864f1b95c9be9ab6aed57a63652c49a7a145a3e  09-add-new-dtbs-to-makefile.patch
2553c147c7b9a387678e5c2508182417346b6acb94f9d22aec10f4aa3e66bb7d84b83ddc0c39f1f3e0dd2137e906891aef349de9da89ce63b3f43c4f42b5e933  CHROMIUM-ARM64-dts-add-vdec-venc-h264-dtsi.patch
4216543acf0ffea0c91b2b7c112cd333be838414f2902cea9f07f5811b96ab5da0e09954086966359316fe0632ac0af65add154b9df0aa11d05962429954e362  mt8183-cadmium-kukui.enable-ite.patch
b9a9e2f620d229ca8acf2df764d6406a304fd51f435929f78c4dfd7f52cd6f1f298f031bb6d7bb7fc8ea360dd8bbd4584bb298f9351100dfb20707de50076244  mt8183-fix-audio-module-loading.patch
d74da1231181835bec82015da1b3f5b08a1fe9c3c35dd712e285891094d94d9427ceac75d32f74be3a635e17d93ad82b37adf97db8176efc91aed17535023fc2  mt8183-fix-bluetooth.patch
a5e99ea30bbdde3a5f0f9745306c9f58876a60489c3cbeacd783cf7e47a013d47c9fb77e4a9dbbd34ec6307d40e64a3623e3cece2f254f734979987f5a22e700  mt8183-kukui-disable-unsupported-thermal-zones.patch
9b8707de42635734031495da055c5860addeb656051540f1a14404b10aa8b501168d8b0e274b37bce989db3bc050e9beef722189556f6d782b92cc907731488d  mt8183-kukui-jacuzzi-fennel14-rt1015p-sound.patch
519b6468bca78d0e315c826592ae40dddca9daeba7c2b451a20ca996494cca45721833b9138fefbb543f53e0b9257c78ec4fec54de2a160aa8df730daf3ac996  mt8183-kukui-jacuzzi-fix-display-resume.patch
e9a128a8ddd98c6c8957ba45186afa2ea8ebeac83d4f2db3ff9ee8a5dd8027af90868c334a7b456bfe7dce793517f27ad63efa220bc933e3407f6362da6d7b2a  mt8183-kukui-jacuzzi-hack-dpms-resume.patch
ca1eec5277c3cd8afc2e6079fd4ccfe2f3937cdc8296cafac1d61bb14ca7acdde6e97d561f5a80a919b01fbc06ec991767d3ea1ff4bc34c1d9033993f2689130  mt81xx-fix-low-speed-usb-devices.patch
5db854d3cb1bad58e93eba86014deb1e2cf3b79a1a74561e22832dccf5cd79f6f0c42cc6210926e0dfc4ca9c939b666018cb2ce5612eb49ad84a8b285dc63e07  mt81xx-usb-02.patch
d7ed719bcb8edd394d268a8a9989d8d0c37443ca79f48dc8a1d829cd22925ed1a19f3240089a998d22fa407e92984e66b33facce47463e0475a5d407c747139d  config-postmarketos-mediatek-mt8183.aarch64
"
