# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/sun8iw7p1smp_defconfig in downstream kernel for BPi M2 Zero
maintainer="User0 <user0thenyancat@proton.me>"
pkgname=linux-bananapi-bpi-m2-zero
pkgver=6.19.0_rc1
pkgrel=1
pkgdesc="Banana Pi BPI-M2 Zero mainline kernel fork"
arch="armv7"
_carch="arm"
_flavor="bananapi-bpi-m2-zero"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bash
	bc
	bison
	clang
	devicepkg-dev
	flex
	lld
	llvm
	openssl-dev
	perl
	findutils
	postmarketos-installkernel
"

# Source
_commit="8f0b4cce4481fb22653697cced8d0d04027cb1e8"
_config="config-$_flavor.$arch"
_repository="linux"
source="
	$pkgname-$_commit.tar.gz::https://github.com/torvalds/$_repository/archive/$_commit.tar.gz
	$_config
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"

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

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

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		LLVM=1 \
		INSTALL_MOD_STRIP=1 \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/usr/share/dtb"

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"
}

sha512sums="
05ef6abe8a428d6ec0a68920b4376259e3e58aeb722c8b3df444abfc16ae3998a079b2cd464e46611d404b20d506057f3001ce14e7e15cdb43f2cc6d5bfe666c  linux-bananapi-bpi-m2-zero-8f0b4cce4481fb22653697cced8d0d04027cb1e8.tar.gz
822bab24899dd4d653773562313a9b1bcee3b7801d6b83bca1a278f45f9ff40f0c9e17dc1700b168b99b4bd2c68610b366f8e878dd58571238fdfe30699dcf91  config-bananapi-bpi-m2-zero.armv7
"
