# 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.0.0
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
	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() {
	# 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" \
		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="
bb77df5ac5863d7594fe0189c989b4a9e8826ea805be7b7dd4e52521578dc434e866770e24f9dd981c43ef3abe97244b62345788e1933c63265a15147a73eb3d  linux-v7.0.0-sc7280.tar.gz
27deb3343e49459b7a094ffddfd15d0259d93a58cbdb7e6103b37ae13f22fe2253bb552942612e9379e1a65288a5061b92752f558dbef8e107f21520719544ee  config-postmarketos-qcom-sc7280.aarch64
"
