# Co-Maintainer: Aelin <aelin@postmarketos.org>
# Co-Maintainer: Federico Amedeo Izzo <federico@izzo.pro>
maintainer="Luca Weiss <luca@lucaweiss.eu>"
_flavor="postmarketos-qcom-sc7280"
pkgname=linux-$_flavor
pkgver=7.1.2
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
	pmb:kconfigcheck-uefi
	pmb:kconfigcheck-virt
	"
makedepends="
	bison
	clang
	elfutils-dev
	findutils
	flex
	installkernel
	linux-headers
	lld
	llvm
	openssl-dev
	pahole
	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
	linux7.0-resolve_btfids-preserve-tag-and-parameter-names-when.patch
	$_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() {
	# ZBOOT EFI decompressor for EFI booting
	install -Dm644 "$builddir/arch/$_carch/boot/vmlinuz.efi" \
		"$pkgdir/boot/linux.efi"

	# Old GZIP'd kernel image for boot.img compatibility
	install -Dm644 "$builddir/arch/$_carch/boot/vmlinuz" \
		"$pkgdir/boot/vmlinuz"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		LLVM=1 \
		INSTALL_PATH="$pkgdir"/boot/ \
		INSTALL_MOD_PATH="$pkgdir"/usr \
		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="
056118544a8214acc283f848e5adc1746e90c99d65fed8c6fcc07c5ffd6ae252347605a6111f63de031e82dbbe89e21b09d053c823c675483bc32b904f964b90  linux-v7.1.2-sc7280.tar.gz
4e705e038a91466a86fc5317b0028c2220aa1e7a4807e5d86db2f9ac815a927c59666a8f21ed50c4632147d3ce183d8042378a76f95341dbcd3db1047faf39e3  linux7.0-resolve_btfids-preserve-tag-and-parameter-names-when.patch
0f4c2b926d3a33fd87931a18ce020bda24ce7eef33046a8e0a786d9d66e8674ae41a2c04a8148a779ea299ad7a39f24dd7b19e23911a35395090f6e2c26779a0  config-postmarketos-qcom-sc7280.aarch64
"
