# Maintainer: Jenneron <jenneron@protonmail.com>
pkgname=linux-postmarketos-qcom-sc8180x
pkgver=6.1.8
pkgrel=0
pkgdesc="Mainline Kernel fork for Snadpragon 8cx 1st generation devices"
arch="aarch64"
_carch="arm64"
_flavor="${pkgname#linux-}"
url="https://gitlab.com/sc8180x-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	pmb:kconfigcheck-uefi"
makedepends="bash bison findutils flex installkernel openssl-dev perl"

_commit="3cff4dd06e16e2b62c824feb6393bd9a678d1b4f"
_config="config-$_flavor.$arch"
# Source
source="
	linux-$_commit.tar.gz::https://gitlab.com/sc8180x-mainline/linux/-/archive/$_commit/linux-$commit.tar.gz
	$_config
"
builddir="$srcdir/linux-$_commit"

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() {
	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="
d2947452d389261d59ad128b1d91b031f4d08269accd6d369ae4672a1ac053958beaf6b2566a98cb158c1d91b981984dbc325218d7b3820c4a683173a7442099  linux-3cff4dd06e16e2b62c824feb6393bd9a678d1b4f.tar.gz
a5ac6fd11030e61e607d22d26e6cb665cd383da288caf6fe120823fa9339b7c8e8efe230ddffaaf70cca434c83bca7f5071573c2b82c141aa61214293389dc02  config-postmarketos-qcom-sc8180x.aarch64
"
