# Stable Linux kernel with patches for SDM670 devices
# Kernel config based on: arch/arm64/configs/{defconfig,sdm{670,845}.config}
maintainer="Richard Acayan <mailingradian@gmail.com>"
_flavor="postmarketos-qcom-sdm670"
pkgname=linux-$_flavor
pkgver=6.19.10
pkgrel=0
pkgdesc="Mainline Kernel fork for SDM670/SDM710 devices"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/sdm670-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	pmb:kconfigcheck-uefi
"
makedepends="
	bison
	clang
	findutils
	flex
	installkernel
	lld
	llvm
	openssl-dev
	perl
	python3
	zstd
"

_config="config-$_flavor.$arch"
_tag="sdm670-v$pkgver"

# Source
source="
	https://gitlab.com/sdm670-mainline/linux/-/archive/$_tag/linux-$_tag.tar.gz
	0001-ASoC-qcom-qdsp6-q6asm-dai-Keep-stream-marked-running.patch
	$_config
"
builddir="$srcdir/linux-$_tag"

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

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

package() {
	# 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 compatibility
	install -Dm644 "$builddir/arch/$_carch/boot/vmlinuz" \
		"$pkgdir/boot/vmlinuz"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		LLVM=1 \
		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="
e88abf25ae6e6da37069a2147b5c06aeffe9083879fe5877e17f8d27da73a05bfa60c80af68a73f2402ab9a009b2f1d13a96602a6ead9b63732e019d975dfee1  linux-sdm670-v6.19.10.tar.gz
c30da4fb13415b0c30072cfb0c984454aaafbc90124ea399dce65f35baee0acc30f52f381ca44ebbddd028e4ff1b32b2c65eab2af8264309f0b2085bfb1ada5b  0001-ASoC-qcom-qdsp6-q6asm-dai-Keep-stream-marked-running.patch
d014bb29168811406eded72037b27155398e5b423eccaae1c3d65fe35b67eb4a565fd2c014ee152fc598d948d0be40443a76ba9c481d13591d5774b5788dec10  config-postmarketos-qcom-sdm670.aarch64
"
