# Reference: https://github.com/archlinuxarm/PKGBUILDs/blob/d2ee78cab3c298583eb3f3bed4d75970f54885be/core/linux-armv7/config
# Kernel config based on: ~2021 mainline kernel of the linux-armv7 package (5.x mainline) from archlinux arm
# Maintainer: Robert Eckelmann <longnoserob@postmarketos.org>
# Co-Maintainer: exkc <exkc@exkc.moe>

pkgname=linux-postmarketos-marvell
pkgver=6.13.2
pkgrel=0
pkgdesc="mainline (stable) for Marvell SoC"
arch="armv7"
_carch="arm"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native pmb:kconfigcheck-community"
makedepends="
	bash
	bc
	bison
	devicepkg-dev
	findutils
	flex
	openssl-dev
	perl
	xz
"
replaces="linux-postmarketos-marvell-dove"

# Source
_config="config-$_flavor.$arch"
source="
	$pkgname-$pkgver.tar.xz::https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$pkgver.tar.xz
	$_config
"
builddir="$srcdir/linux-$pkgver"

prepare() {
	default_prepare
	cp -v "$srcdir"/$_config .config
}

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

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

	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/$_flavor/kernel.release
}


sha512sums="
c21b5d41c8983cb404a5b1747e17e900a10e09fb1a2b56f73d3c4d8ceed6af376e5149fc5484f97aacb771ca2e7def66789c6ae06eb696875f3ef89c67db302f  linux-postmarketos-marvell-6.13.2.tar.xz
c20ea9155aa343160b944280bfebf1d504a155533c2c2c7a4e5d0edf9552a68ed12429725d3f18fe18d71d7137ef5c0a73fce45557b8a2daed6bc55e6ed47630  config-postmarketos-marvell.armv7
"
