# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/pinetab2_defconfig
# Co-Maintainer: Stefan Hansson <newbyte@postmarketos.org>
maintainer="Danct12 <danct12@disroot.org>"
pkgname=linux-pine64-pinetab2
pkgver=6.17.8
_danctnix_kernel_rel=1
pkgrel=0
pkgdesc="Pine64 PineTab 2 mainline"
arch="aarch64"
_carch="arm64"
_flavor="pine64-pinetab2"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native"
depends="kmod"
makedepends="
	bash
	bison
	findutils
	flex
	linux-headers
	postmarketos-installkernel
	openssl-dev
	perl
	xz
	zstd
"

# Source
_tags="v$pkgver-danctnix$_danctnix_kernel_rel"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_tags.tar.gz::https://codeberg.org/DanctNIX/linux-pinetab2/archive/$_tags.tar.gz
	$_config
"
builddir="$srcdir/linux-pinetab2"
_outdir="out"

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

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

package() {
	install -Dm644 "$builddir/arch/$_carch/boot/Image" \
		"$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="
8d2dc3222d1dac89996a3432c5b8fd5c2f21b1926a87b7bb2352f41722de46510f340e8972d1b29b077912a2ea7b82c869d42f866ec8ca2a1839a5a2fd6e88ff  linux-pine64-pinetab2-v6.17.8-danctnix1.tar.gz
18ecd2da7a9668a71b6236641132bbffce527040c2d0e2268eb15900c932757020f87dda2bad0c0e4b3507f7b5b7e43b4b757320e6f9f5b1c69b6a4cc77c8977  config-pine64-pinetab2.aarch64
"
