# Maintainer: WeirdTreeThing <bradyn127@protonmail.com>
# Co-Maintainer: Jenneron <jenneron@protonmail.com>
pkgname=linux-postmarketos-mediatek-mt8183
pkgver=6.6.25
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
	arm64-dts-mediatek-mt8183-Add-missing-GPU-clocks.patch
	arm64-dts-mediatek-mt8183-Add-missing-syscon-power-d.patch
	arm64-dts-mediatek-mt8183-Add-video-encoder-decoder.patch
	arm64-dts-mediatek-mt8183-Drop-VDEC_SYS-register.patch
	arm64-dts-mediatek-mt8183-Add-register-names-and-sys.patch
	arm64-dts-mt8183-Add-jacuzzi-makomo-board.patch
	arm64-dts-mt8183-Add-jacuzzi-pico-pico6-board.patch
	arm64-dts-mt8183-Add-kukui-katsu-board.patch
	arm64-dts-mt8183-Add-kukui-jacuzzi-cerise-board.patch
	mt8183-kukui-jacuzzi-fix-display-resume.patch
	mt8183-kukui-jacuzzi-hack-dpms-resume.patch
	mt8183-fix-bluetooth.patch
	Revert-ASoC-mediatek-mt8183-da7219-max98357-Map-miss.patch
	mt8183-kukui-jacuzzi-fennel14-rt1015p-sound.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="
1f1c31a104aa399cd7fd67c0e73c5037e95112e544b00ad70a2a809b52d9d190c303e3f946d67d805125181004fe7de500ff2069dcacad94f6b56bfb8f180f6a  linux-6.6.25.tar.xz
669a1bbf8707ec9294da83336673fbb55061a2eed0c6ddb2613da3ae4fa9b0e2bdbdd91ad166694173e3540ea934b2f3bf27d5f9659a6952de806765eed9b824  arm64-dts-mediatek-mt8183-Add-missing-GPU-clocks.patch
027fee259454764e47ffee7100dba7cb9f0741a156ba3d1b47815a0beb6b4ea6cccba885f93b068923ff88047fa82a3d937d3808d0199f1de85cf553068a9ba7  arm64-dts-mediatek-mt8183-Add-missing-syscon-power-d.patch
40246a8da036dc6c21592efd6625a4be22d6f524b067854f17f5671f5f3b134ed1c63a8c03a15a55e9b45b7d8d1a9b63833b86f38a6f5863e02cc8ddbf70fa57  arm64-dts-mediatek-mt8183-Add-video-encoder-decoder.patch
aee85972804ab4a254f007805e25d30a82bb87e48144a05805ccefd49f8530f588e2c50b6550f302895a675003ffbe8e7986c2214d76763474b88804fe7f1519  arm64-dts-mediatek-mt8183-Drop-VDEC_SYS-register.patch
567b13d7508fdf584a64bf3f9d71ba34c045c6e4610ef7f7024ed98f4e7ebbd78c0ee2d5dccc7a50e651e4a088c0621f5150d477520069965466d5db265160ab  arm64-dts-mediatek-mt8183-Add-register-names-and-sys.patch
c0ac0f26bb515a68b89515a19113a14e2cd11c940f01649a2e4e9261f852be66af6a53683fc3d4f2ae7b1289fa9247111772f458ff96e51742b2b1efc7a73a11  arm64-dts-mt8183-Add-jacuzzi-makomo-board.patch
5a1bdadc6cb12c1fb52c1ed8710e0d0c05e91b4559725fe7b26c41bc6fa375800cbb51e554401cdf419fbfdf6ab7f91f1efb5ad333db2e0e0466036f41eff519  arm64-dts-mt8183-Add-jacuzzi-pico-pico6-board.patch
69f26a25a9a35eaf8f0c655e3f50a5ab19a5f727b1cdf49ad0c9cb89c69cd9517bd381a62e5197c1f00a7c2f03cd2411415f455e9fb5a2c8c1afa777e754398e  arm64-dts-mt8183-Add-kukui-katsu-board.patch
a95ce4a71d249ef401ca04cf8faf85b9022114d35fef5a0ce18929f734a0ac80ed0332648cc9768625f3c26b3720679e1a20bf8ac564087bd4c64f49cd96cc45  arm64-dts-mt8183-Add-kukui-jacuzzi-cerise-board.patch
519b6468bca78d0e315c826592ae40dddca9daeba7c2b451a20ca996494cca45721833b9138fefbb543f53e0b9257c78ec4fec54de2a160aa8df730daf3ac996  mt8183-kukui-jacuzzi-fix-display-resume.patch
e9a128a8ddd98c6c8957ba45186afa2ea8ebeac83d4f2db3ff9ee8a5dd8027af90868c334a7b456bfe7dce793517f27ad63efa220bc933e3407f6362da6d7b2a  mt8183-kukui-jacuzzi-hack-dpms-resume.patch
d74da1231181835bec82015da1b3f5b08a1fe9c3c35dd712e285891094d94d9427ceac75d32f74be3a635e17d93ad82b37adf97db8176efc91aed17535023fc2  mt8183-fix-bluetooth.patch
9e64ef057ecd9bb23b0b0e830007c50ea9c481f64f460d063e9f64735d70d5a4bcf87d9148aa5cc90963ccd5860fe4a9e6f25556a902332b95ef48537d6ee045  Revert-ASoC-mediatek-mt8183-da7219-max98357-Map-miss.patch
9b8707de42635734031495da055c5860addeb656051540f1a14404b10aa8b501168d8b0e274b37bce989db3bc050e9beef722189556f6d782b92cc907731488d  mt8183-kukui-jacuzzi-fennel14-rt1015p-sound.patch
b99d226ad93ee3d09ffedf028bccf2d0561709e3c8f55e1c2db77eb83ae14e4bf81c545e3c016e811f4f66e6216def18893a1a347940e6db4fe3bc1a1ecc36cd  config-postmarketos-mediatek-mt8183.aarch64
"
