# Maintainer: Caleb Connolly <caleb@connolly.tech>
# Co-Maintainer: Uclydde <julianbraha@gmail.com>
# Co-Maintainer: Alexey Min <alexeymin@postmarketos.org>
# Stable Linux kernel with patches for SM8150 devices
# Kernel config based on: arch/arm64/configs/defconfig and sm8150.config

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

_repo="linux"
_config="config-$_flavor.$arch"
_tag="v5.17.0-sm8150"

# Source
source="
	$_repo-$_tag.tar.bz2::https://gitlab.com/sm8150-mainline/linux/-/archive/$_tag/linux-$_tag.tar.bz2
	$_config
"
builddir="$srcdir/$_repo-$_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
	make zinstall 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="
0cfcec980668ecdc1646c6398807367525058eb762d0410bb9443632febaa3f1c8d3164d165da20e6638fb625443aab5c37635bc0d347df685ce8e65308b752e  linux-v5.17.0-sm8150.tar.bz2
71013301cb4432dad555600fddfee1fc86ecfca7fe9569ae35930c54a02a8b4cd70afa0e79fd0e5e9d64956dc888e9873cce1efd1cbb743095f877fd0940aac1  config-postmarketos-qcom-sm8150.aarch64
"
