# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/pinetab2_defconfig
# Maintainer: Danct12 <danct12@disroot.org>
pkgname=linux-pine64-pinetab2
pkgver=6.9.6
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-danctnix1"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_tags.tar.gz::https://github.com/dreemurrs-embedded/linux-pinetab2/archive/$_tags.tar.gz
	$_config
"
builddir="$srcdir/linux-pinetab2-${_tags:1}"
_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="
2e15c0491c93895605b9e371942927483d8c1b35df13540f953d9a5a12941becbe83a908ee3bab68c9700e044958dd3505b30defdc916c92c8eea33547f39754  linux-pine64-pinetab2-v6.9.6-danctnix1.tar.gz
1d2e735eefce1e35d7df487df8af1979dd556217665e16c4d812829df088fb88e73054fdbd3d599d058638790de0aaa368d530fe7e6149699110fee5bbb2dd72  config-pine64-pinetab2.aarch64
"
