# Co-Maintainer: Ingo Reitz <9l@9lo.re>
# Co-Maintainer: WeirdTreeThing <bradyn127@protonmail.com>
maintainer="Alicja Michalska <ellyqw@mainlining.org>"
pkgname=linux-postmarketos-qcom-sc7180
pkgver=6.18.40
pkgrel=0
pkgdesc="Mainline kernel for Qualcomm Snapdragon 7c devices"
arch="aarch64"
_carch="arm64"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	pmb:kconfigcheck-uefi
"
makedepends="
	bison
	clang
	elfutils-dev
	findutils
	flex
	linux-headers
	lld
	llvm
	openssl-dev
	pahole
	perl
	postmarketos-installkernel
	xz
	python3
	zstd
"

# Source
_config="config-$_flavor.$arch"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac
source="
	https://cdn.kernel.org/pub/linux/kernel/v${_kernver%%.*}.x/linux-${pkgver//_/-}.tar.xz
	0001-drm-msm-adreno-a6xx-Mark-cxpd-device_link-as-statele.patch
	0002-drm-msm-Centralize-the-standalone-drm-device-check-f.patch
	0003-drm-msm-adreno-Fix-invalid-drvdata-typecast-in-adren.patch
	0004-drm-msm-Always-use-component-model-for-standalone-GP.patch
	0005-drm-msm-Attach-a-driver-to-the-GMU.patch
	$_config
"
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 ))-postmarketOS"
}

package() {
	if [ -e "$builddir/arch/$_carch/boot/vmlinuz.efi" ]; then
		# ZBOOT EFI decompressor for EFI booting
		install -Dm644 "$builddir/arch/$_carch/boot/vmlinuz.efi" \
			"$pkgdir/boot/linux.efi"

		# Old GZIP'd kernel image for boot.img/crOS compatibility
		install -Dm644 "$builddir/arch/$_carch/boot/vmlinuz" \
			"$pkgdir/boot/vmlinuz"
	else
		echo "WARNING: CONFIG_ZBOOT not enabled!"
		install -Dm644 "$builddir/arch/$_carch/boot/Image.gz" \
			"$pkgdir/boot/vmlinuz"
	fi

	make 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"/usr/lib/modules/*/build "$pkgdir"/usr/lib/modules/*/source

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

sha512sums="
c79b74b450c00c3da75da59bee5659687f06d3814ebc1c9e6304a89ec756c02caedcb6067897842ea2444c794dbfb83b2feaa6a22c463fe51323ce730554f9a1  linux-6.18.40.tar.xz
9680cf56d05e629ea4740123e02dd0ea09045b0cacd3aa1ce4c6cd2b42e136011d81b9e4ee50394974a58392d3fc5e99d3c489877ce359e437fabbee8bee712e  0001-drm-msm-adreno-a6xx-Mark-cxpd-device_link-as-statele.patch
4e2180cf50f75466b510435133f510fe1f06e4f828ce0aacd0588abc5d6db432d6257a8d6fcc88103c7ceb1f93eabc2d35f154201bef86f9a3aa65367edef694  0002-drm-msm-Centralize-the-standalone-drm-device-check-f.patch
22a416eadfd30a5ffd1d065ce17d7b0bd2285d8ae902401147be8617f26d372f9400551d728769f37398462f0ba0b58cdc4443f44c1d1fb2591c3a9f88432387  0003-drm-msm-adreno-Fix-invalid-drvdata-typecast-in-adren.patch
81f83455054502d04063178761d230e9300562241826f3a7e34605b9f7e6b95271ce060c80d4841f13731d69b076d46813f3ecd945e29b33672b836847a9096c  0004-drm-msm-Always-use-component-model-for-standalone-GP.patch
74d6e28134809ecd74719dd1ee804b92ffd0a8528b555d7bcc44a59064d58010fdc1710938c0af5bbdf08e3dd3792a4fd538548dfa5192dcd35aa25df09364b5  0005-drm-msm-Attach-a-driver-to-the-GMU.patch
a1acf2c80bcc1d700782177c13936f4cdd4f67479d0948778642f41746ec5cdacffc1c810acbf058bea4cd1876e6fd4fd2ece27992c246298703b3fbbb416d85  config-postmarketos-qcom-sc7180.aarch64
"
