# Maintainer: Caleb Connolly <caleb@postmarketos.org>
# Kernel config based on: arch/arm64/configs/defconfig

pkgname=linux-next
pkgver=6.15_git20250423
pkgrel=0
_nextver="${pkgver#*_git}"
pkgdesc="Linux next kernel"
arch="aarch64"
_carch="arm64"
_flavor="generic-trailblazer"
url="https://kernel.org"
license="GPL-2.0-only"
# FIXME: kconfigcheck isn't supported since we use fragments
options="!strip !check !tracedeps pmb:cross-native"
source="
	https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/snapshot/linux-next-next-$_nextver.tar.gz
	devices.config
	pmos.config
"
makedepends="
	bash
	bc
	bison
	devicepkg-dev
	findutils
	flex
	git
	openssl-dev
	perl
	python3
	zstd
"
builddir="$srcdir/linux-next-next-$_nextver"

prepare() {
	default_prepare
	cp "$srcdir/pmos.config" "$builddir"/arch/"$_carch"/configs/
	cp "$srcdir/devices.config" "$builddir"/arch/"$_carch"/configs/

	# Generate .config
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-next-$_nextver" \
		defconfig pmos.config devices.config
}

build() {
	unset LDFLAGS
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

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

	make modules_install dtbs_install \
		ARCH="$_carch" \
		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/next-"$_nextver"/kernel.release
}

sha512sums="
3a9ca378a63c015b8f606791fabaf846bfd6b19af84877cc12ae37aca8b973621a7f66b7edcfeb9a05657335f5fc8f9019c862c45bee8baaa4b75651baecd896  linux-next-next-20250423.tar.gz
95b1da5657af138ef97022c9f64987e765bfee634f8b967530dc7126f664039984dc2c2d20abb131fc119794fed25394b235bfc0c18390a45fd782bbaab63dba  devices.config
8ceb3e5904c6d860b7b516c4313610a2ac80b89cb64a8b5b2993561f50c53ba087408b1c6b3108a2e51af4775630a2526ff678704be13eb282df9e5d9f97ccfd  pmos.config
"
