# Maintainer: Petr Vorel <petr.vorel@gmail.com>
# Kernel config based on: arch/arm64/configs/defconfig

_flavor="postmarketos-qcom-msm8994"
pkgname=linux-$_flavor
pkgver=6.1.2
pkgrel=1
pkgdesc="Kernel mainline Qualcomm MSM8994 and MSM8992 devices"
arch="aarch64"
_carch="arm64"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-nftables
	"
makedepends="
	bison
	findutils
	flex
	openssl-dev
	perl
	postmarketos-installkernel
	xz
"

case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac
source="
	https://cdn.kernel.org/pub/linux/kernel/v${_kernver%%.*}.x/linux-$_kernver.tar.xz
	config-$_flavor.$arch
	0001-arm64-dts-msm8992-bullhead-add-memory-hole-region.patch
	0002-arm64-dts-qcom-msm8992-bullhead-Fix-cont_splash_mem-.patch
	0003-arm64-dts-qcom-msm8992-bullhead-Disable-dfps_data_me.patch
	0004-arm64-dts-qcom-msm8992-Don-t-use-sfpb-mutex.patch
	0005-arm64-dts-msm8994-angler-fix-the-memory-map.patch
"
builddir="$srcdir/linux-$_kernver"

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

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		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="
a906c15b1eb4f3015b1d9a0e6a321b5a399e77ccd0127cb8caabbe7cb337e77a85a432bac4763ab5448d86dd319441eef865aad41939ca1f796663c2b52170e6  linux-6.1.2.tar.xz
4191f3ffd3ca9a4c5e3986e57ca31d69d811045b91cb357957bd2d794b9cfb88fbbd9c6597cbd04aae74e5015d61c8344b4f20962cafbdb72a7dea94b05a26a9  config-postmarketos-qcom-msm8994.aarch64
878a48bff265b91e7970c84d3d8dc38753fdc15d7412db9000c2974989fa8fefc312bab0abd442365f83e7af27e2eb712d7f6abc41ab9c20fbe9f4e4419a9a94  0001-arm64-dts-msm8992-bullhead-add-memory-hole-region.patch
901fcae7ae813ea0a4d301283f423cd84696c7200075170c0385027955daa5796cd658cbb34d3d65053b50867638d78acb86913666f6ea48c5c59bb6e68f70d1  0002-arm64-dts-qcom-msm8992-bullhead-Fix-cont_splash_mem-.patch
6d06b1770dd8471fcc4c4fb1f37707833f3d1da1d8a2a58ca311c73dcbedb8ecdf2e8e52512a90676bd7a0a328585023aa8b94feeb4b0bafd75ca57cd1d637a1  0003-arm64-dts-qcom-msm8992-bullhead-Disable-dfps_data_me.patch
293b85417ffecfe59ae0955a98eb2232f98f676bcc4cc0743df9b4f945d8059a17bb09714e5abccc93e2858b13a0006e154c4f5efaecde0c544a31170671fb73  0004-arm64-dts-qcom-msm8992-Don-t-use-sfpb-mutex.patch
645a22550864f9f98798ff7334eef654537a113e0e6988282a68909d7d78e7a7122fb11cf12b6c44aff23d3c51964113d39fd1e387809c6d1576f5dd237d4b0d  0005-arm64-dts-msm8994-angler-fix-the-memory-map.patch
"
