# Maintainer: Richard Acayan <mailingradian@gmail.com>
# Stable Linux kernel with patches for SDM670 devices
# Kernel config based on: arch/arm64/configs/{defconfig,sdm{670,845}.config}

_flavor="postmarketos-qcom-sdm670"
pkgname=linux-$_flavor
pkgver=6.2.6
pkgrel=0
pkgdesc="Mainline Kernel fork for SDM670 devices"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/sdm670-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native"
makedepends="bash bison findutils flex installkernel openssl-dev perl"

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

# Source
source="
	https://gitlab.com/sdm670-mainline/linux/-/archive/$_tag/linux-$_tag.tar.gz
	$_config
	0001-arm64-dts-qcom-sdm670-google-sargo-move-modem-firmwa.patch
"
builddir="$srcdir/linux-$_tag"

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

	install -Dm644 "$builddir/arch/$_carch/boot/Image.gz" \
		"$pkgdir/boot/vmlinuz"

	make 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="
2e9edd94decbee15282f418446528c50e8ab5e1e570593ccf1ebadb1d36ca45c5c17d84bdc1f530fc8e63c82a505ef5dd241253df82afecd8117472a0b669078  linux-sdm670-v6.2.6.tar.gz
5e2160cf5d103cdd6ecd8cdca7b96933e25fadb8f2ff93502fce89b22f6285fe1fc831a60119bd8bd325662d1624ff4c393517c985df8384db140362e6ca3f05  config-postmarketos-qcom-sdm670.aarch64
678b0d657eeef10fa5891fecebfd2cd3a934e89ce7b3a56b3539899d9fc622daa4447ca4b9af993a636aeab3ac5c9d731c863ed167528025f033ff48f99ce9cb  0001-arm64-dts-qcom-sdm670-google-sargo-move-modem-firmwa.patch
"
