maintainer="Clayton Craft <clayton@craftyguy.net>"
pkgname=linux-postmarketos-asahi
pkgver=7.1.5_p2
pkgrel=0
_rel=${pkgver#*_p}
_kver=${pkgver%_p*}
_kver=${_kver//_/-}
_asahiver=$_kver-$_rel
pkgdesc="Kernel for Apple M-series devices"
arch="aarch64"
_carch="arm64"
_flavor="postmarketos-asahi"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip
	!check
	!tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	pmb:kconfigcheck-uefi
	pmb:kconfigcheck-virt
"
makedepends="
	bash
	bc
	bison
	clang
	clang-libclang
	devicepkg-dev
	diffutils
	elfutils-dev
	findutils
	flex
	git
	linux-headers
	lld
	llvm
	openssl-dev
	pahole
	perl
	python3
	rust
	rust-bindgen
	rust-src
	rustfmt
	sed
	zstd
"

# Source
_repository="linux"
source="
	$pkgname-$_asahiver.tar.gz::https://github.com/AsahiLinux/linux/archive/refs/tags/asahi-$_asahiver.tar.gz
	config-postmarketos-asahi.aarch64

	0001-nvmem-apple-spmi-nvmem-Fix-CFI-failures.patch
	enable-dynamic-ftrace.patch
"
builddir="$srcdir/linux-asahi-$_asahiver"

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

build() {
	unset LDFLAGS
	make ARCH="$_carch" LLVM=1 \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	install -Dm644 "$builddir/arch/$_carch/boot/vmlinuz.efi" \
			"$pkgdir/boot/linux.efi"

	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-asahi

	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="
d96ca5e807ad262f885dc690090b48772f05488b8a2f0ec59110e63de7fd49e6219bb4b15aa6e92384fb49aacda60799598eaa75adaefe431be6a8a8eca14bfd  linux-postmarketos-asahi-7.1.5-2.tar.gz
18ab57942740703a23ad879dcb25531ac148b1e004c6b12fa12f3805d939f3d513ba80ee29ee92a4bac7f8b154d6f8a367476c03b800e4bf2081ae206df00ea2  config-postmarketos-asahi.aarch64
8d205300cfabe192b53ed1cc644b087e76421eb973e1b2a31d657e4f2676badebdfcf6b0865569c43b4b904935435f6e729c3a8d4a6221fb5792e40ec1017a0f  0001-nvmem-apple-spmi-nvmem-Fix-CFI-failures.patch
e8b595f3e076896dc38f249c8908d58e2e6a858eaa77fe1e680f27db0e76d3d74c0b5dfebb7a4c57d546fee0b0f6eb81a38b20dfd72f985c9d02f28d79a5eceb  enable-dynamic-ftrace.patch
"
