# Contributor: Quade Curry <qc8086@qc8086.com>
maintainer="Sebastian Fleer <dev@dwurp.de>"
pkgname=linux-postmarketos-rockchip
pkgver=6.18.8
pkgrel=0
pkgdesc="Mainline kernel for rockchip devices"
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-nftables
"
makedepends="
	bash
	bison
	clang
	findutils
	flex
	lld
	llvm
	openssl-dev
	perl
	postmarketos-installkernel
	python3
	xz
	zstd
"

# Source
_config="config-$_flavor.$arch"
case $pkgver in
	*_rc*)	_kernver=${pkgver/_/-};;
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac

source="
	https://cdn.kernel.org/pub/linux/kernel/v${_kernver%%.*}.x/linux-$_kernver.tar.xz
	$_config
"
builddir="$srcdir/linux-$_kernver"

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

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

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

	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		LLVM=1 \
		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="
368b7d7c4513932baa7acfddea515025ce5f2e2c89bff25c4dc3a8ec9ecdd8e2a153439d8912989dab9d233e5b616995ba11b153a9dea1277bc0c579081719ad  linux-6.18.8.tar.xz
37abac73181b3bbf9ee172ed4eb8ed9adcdba884bc2899bd795c102fdcc453de9e2e527e31cc2bf1772898755e91d2e5008173463391d3dbe4af6c88efa10aec  config-postmarketos-rockchip.aarch64
"
