# Maintainer: Jan Jasper de Kroon <jajadekroon@gmail.com>
# Co-Maintainer: Arnav Singh <me@arnavion.dev>
_flavor=postmarketos-allwinner
_config="config-$_flavor.$CARCH"
pkgname=linux-$_flavor
pkgver=6.9.7_git20240630
pkgrel=0
_tag="orange-pi-6.9-20240630-2043"
pkgdesc="Kernel fork with Pine64 patches (megi's tree, slightly patched)"
arch="aarch64 armv7"
url="https://megous.com/git/linux/"
license="GPL-2.0-only"
makedepends="
	bison
	devicepkg-dev
	findutils
	flex
	gmp-dev
	installkernel
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
	rsync
	xz
	bash
	"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	"
source="$pkgname-$_tag.tar.gz::https://codeberg.org/megi/linux/archive/$_tag.tar.gz
	config-$_flavor.aarch64
	config-$_flavor.armv7
	0001-dts-add-dontbeevil-pinephone-devkit.patch
	0002-dts-add-pinetab-dev-old-display-panel.patch
	0003-dts-pinetab-add-missing-ohci1.patch
	0004-dts-pinetab-make-audio-routing-consistent-with-pinep.patch
	0005-dts-pinephone-drop-modem-power-node.patch
	0006-drm-panel-simple-Add-Hannstar-TQTM070CB501.patch
	0007-ARM-dts-sun6i-Add-GoClever-Orion-70L-tablet.patch
	0008-drm-panel-simple-Add-Hannstar-HSD070IDW1-A.patch
	0009-ARM-dts-sun6i-Add-Lark-FreeMe-70.2S-tablet.patch
	0010-eMMC-workaround.patch
	0011-arm64-dts-allwinner-orangepi-3-fix-ethernet.patch
	0012-ARM-dts-allwinner-sun5i-a13-pocketbook-614-plus-Add-.patch
	"
builddir="$srcdir/linux"

case "$CARCH" in
	aarch64*) _carch="arm64" ;;
	arm*) _carch="arm" ;;
esac


prepare() {
	default_prepare

	REPLACE_GCCH=0 \
		. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	# V=1: workaround for pma#1990
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor" \
		CFLAGS_MODULE=-fno-pic \
		DTC_FLAGS="-@" \
		V=1
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor"

	make -j1 modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/boot/dtbs"
}

sha512sums="
51523e96919d817a14a3b2e9f149e7f0f2b33edac1f5a9c6b72cc31fa69c4d66632404d5851253ad83fa60eb4f56278c50bcd8ba1aca0133ca1796bfdde677e0  linux-postmarketos-allwinner-orange-pi-6.9-20240630-2043.tar.gz
ed33e7d190d8acee5f8a66ba203dfa04831a14af939d76538f26d0802c47a3145ff44edc9d4a3aa15adbb39ffddbb5edf453c1c69ede9b4ea7cc48d982bf0b6b  config-postmarketos-allwinner.aarch64
930dab0c58b3885fe6a808b17b470f6a9e26f475e28453c05ec323637ef808465778a2da8487f9db734a2e8bd6d40d6b9e434df12bad61fcf85821ef7391dd5f  config-postmarketos-allwinner.armv7
a1fe1a21c34062eb92b6a4a9d2ef330d0e745859af283ccf05fc899ec263f9d452c1399c29620a0e4c748eca4b0c13645668b2fc0dc72f5703426d472f1294be  0001-dts-add-dontbeevil-pinephone-devkit.patch
0ef26b34fa834c119ebff6daa27b1dd3fac27448d6a40c0b2022a00c239dad0ef3e2b3ab3f9eec5460f921c9c6ea21db360adc175a7e658d5c34c5d0aacc498f  0002-dts-add-pinetab-dev-old-display-panel.patch
d37d929100a9de9431cc3cef6b714b61b5af9633e35a2880fcc8b60279fdc9ab65198fa70d01e070a9f263818d994b9b851973bb079ddea1ca66d2b7964f365d  0003-dts-pinetab-add-missing-ohci1.patch
e368935e8e1a2380b0b42961ca65e7ebb842916e80b7b3e96211d5091413d5b8112e60f2437f82795e9c21183411f81daf1f2806b7a93b0c03dca0a64e25f079  0004-dts-pinetab-make-audio-routing-consistent-with-pinep.patch
e4dd137537cecc8cfbb2152120134ee4fb19b930ed0e66313c414fb14061f9d2dd4c280cfbde722f8f39531868823c8f12ec79e45800f5c6e0ded03475557f79  0005-dts-pinephone-drop-modem-power-node.patch
0234490da9ea6d172ccea95092ab8a0623d2b57d43b0066d0b77a096b4a5e2a02047579f12b09d2e6bc1b77a3f9ea67dc26e9d5c02b947a7126f822132c85d30  0006-drm-panel-simple-Add-Hannstar-TQTM070CB501.patch
09e8a2b06b45bb0be75a4c09f6a9d165861a950bf6ed1cd91faa493710dd9fdc0aa35a38e23a731bb3f281c30c353310e4a17cdea3ddc6ab7ec3436722eb3b07  0007-ARM-dts-sun6i-Add-GoClever-Orion-70L-tablet.patch
96d7b7d8161dcd7379092b6aec531ca47ee0566c308057aec2f934256f67ee9f3dcd2fb7ca592b056a5305600ea4125932c96f2c244966d7d46f9b1f3fb77052  0008-drm-panel-simple-Add-Hannstar-HSD070IDW1-A.patch
22cf608d79337aee6354e7db6bf1f177a6b4ab89f7b26da46e0cf2e280978ace7203829a0e87675449ef41b488ab114cedd5ab911e326b87fa823a0073c8d1fc  0009-ARM-dts-sun6i-Add-Lark-FreeMe-70.2S-tablet.patch
898f1227fe27e38706ea8e6e2846cbc9bded328090ddb457733cf6417f2e1da5bac2d9caa753b29a0667a2733a937b9d447b666a070462a93d1cfea3f88daea7  0010-eMMC-workaround.patch
4acfd79aa2978d6b8078fbd7649a2dda4ef5a1e03b52d7e034a7cc40b5a7349c4dc741fab9cb7722fa61eb022fd270719ed5257ac8487796c9e2b1135a123e86  0011-arm64-dts-allwinner-orangepi-3-fix-ethernet.patch
0770f510a12f8ec29fa2798682b0687438f733634df0b339876b8181c08cd154904412aa88d5dd5df336803da3a4f5c274cba5008be533e036dc5deb3c41fb17  0012-ARM-dts-allwinner-sun5i-a13-pocketbook-614-plus-Add-.patch
"
