# 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.1.14
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" \
		V=1
}

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="
f4bc8c7b32cd3ad468cae64d00dce19d9b24d97b08a9f818213d202809c8706043f777566635a60df8a02e0883a04d2be7e0fdf40b32196a4ee1744914dfe9dd  linux-sdm670-v6.1.14.tar.gz
f983d7524bc81831e716e078ada9841ea53ba56fea9b25d67f3d74fde370df142b5aeac946553039245ec52bb341703cffc73c0690f45713a6a9887b4c437996  config-postmarketos-qcom-sdm670.aarch64
ee032082eef7cde79602e16c8e97d19661f0fcfd649c55edad070866cb60a39a8d42cf2a739f06670932ff2035b117b9401cef812ebb084de29bce22f502840f  0001-arm64-dts-qcom-sdm670-google-sargo-move-modem-firmwa.patch
"
