maintainer="Luca Weiss <luca@lucaweiss.eu>"
_flavor="postmarketos-qcom-sc7280"
pkgname=linux-$_flavor
pkgver=6.18.7
pkgrel=0
pkgdesc="Mainline Kernel fork for SC7280/SM7325/QCM6490 devices"
arch="aarch64"
_carch="arm64"
url="https://github.com/sc7280-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	"
makedepends="
	bison
	clang
	findutils
	flex
	installkernel
	lld
	llvm
	openssl-dev
	perl
	python3
	zstd
"

_repo="linux"
_config="config-$_flavor.$arch"
_tag="v$pkgver-sc7280"

# Source
source="
	https://github.com/sc7280-mainline/$_repo/archive/refs/tags/$_tag/$_repo-$_tag.tar.gz
	$_config
"
builddir="$srcdir/$_repo-$pkgver-sc7280"

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

build() {
	unset LDFLAGS
	make ARCH="$_carch" LLVM=1 \
		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" \
		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="
9bed1987b47e38571fe966bb5cb632f604c434beafa8dacf2e21e7a4e5ad768b7feb417484ff5a6bdf837bdce6c88a024f9a6ee56df7016476e896129e1fa6c1  linux-v6.18.7-sc7280.tar.gz
38e3ccde16400356c22dc9293cf6bebcb76eebbcdc3fcc30b33005469bb9867e56941992568492fb14d8609789117af8858fd07fbf4f60ece9c4bf634681a61d  config-postmarketos-qcom-sc7280.aarch64
"
