# Kernel config based on: arch/arm64/configs/defconfig
maintainer="Neil Armstrong <neil.armstrong@linaro.org>"
pkgname=linux-ayaneo-pocket-s2
pkgver=7.0_git20260612
pkgrel=0
pkgdesc="Ayaneo Pocket S2 kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip
	!check
	!tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	pmb:kconfigcheck-uefi
	"
makedepends="
	bash
	bc
	bison
	clang
	clang-libclang
	devicepkg-dev
	elfutils-dev
	findutils
	flex
	git
	lld
	llvm
	openssl-dev
	perl
	postmarketos-installkernel
	python3
	rust
	rust-bindgen
	rust-src
	rustfmt
	zstd
"

# Source
_url="https://gitlab.com/superna9999/"
_repository="linux"
_commit="d42f74bb3f3372e95cd0525177e2cb83ebb23b17"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::$_url/$_repository/-/archive/$_commit/$_repository-$_commit.tar.gz
	misc.config
	$_config
"
builddir="$srcdir/$_repository-$_commit"

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

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

package() {
	mkdir -p "$pkgdir"/boot

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

	make LLVM=1 zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		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="
f50dc5bcbc511e87d93024fa4430b87cdaaf3314368bcf8a7c24b7461e912bb6a5fb51feff7e5e6b98aa77d533e3bebb79ef276cec9e2eab6e50db657ee2cd83  linux-ayaneo-pocket-s2-d42f74bb3f3372e95cd0525177e2cb83ebb23b17.tar.gz
f7712cb52ab2abae02deb3f90d0bdba83bcdf1af9b5f4fdb97963d729d1a0161301ecb3b5948dcd7a7f182c14e52d3863ec48f22a00276008d3bb0615d29ba68  misc.config
07089f3297c5206ae1a1a64c5c8438d1d82ca29c4c4651211be74e9786a10956a45bc13ad9bb666a9beb5ca7550948e71bdaa90598bfd4282b2fe57ad9277e1f  config-ayaneo-pocket-s2.aarch64
"
