# Maintainer: Sicelo <absicsz@gmail.com>
# Co-Maintainer: Danct12 <danct12@disroot.org>

pkgname=linux-nokia-n900
pkgver=5.15.81
pkgrel=0
pkgdesc="Mainline kernel fork for Nokia N900"
arch="armv7"
url="https://kernel.org/"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	"
makedepends="bison findutils flex openssl-dev perl gmp-dev mpc1-dev mpfr-dev postmarketos-installkernel"

_carch="arm"
_flavor=nokia-n900
_config="config-$_flavor.armv7"
case $pkgver in
	*.*.0)	_kernver=${pkgver%.0};;
	*.*.*)	_kernver=${pkgver%.*}
		_patch="
		linux-$pkgver.patch.xz::https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/patch-$pkgver.xz";;
	*.*)	_kernver=$pkgver;;
esac
source="
	https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$_kernver.tar.xz
	$_patch
	$_config
	0001-ARM-dts-n900-increase-charge-current-limit-to-950mA.patch
	0002-power-supply-bq27xxx-expose-battery-data-when-CI.patch
	0003-wip-Revert-dma-direct-Fix-potential-NULL-pointer-der.patch
	0004-ARM-dts-omap3_n900-disable-thermal-for-now.patch
	0005-iio-accel-st-accel-add-lis302dl.patch
	0006-ARM-dts-N900-use-iio-driver-for-accelerometer.patch
	0007-Revert-ARM-omap3-enable-off-mode-automatically.patch
	0008-wl1251-specify-max.-IE-length.patch
"
builddir="$srcdir/linux-$_kernver"

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

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

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

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

sha512sums="
d25ad40b5bcd6a4c6042fd0fd84e196e7a58024734c3e9a484fd0d5d54a0c1d87db8a3c784eff55e43b6f021709dc685eb0efa18d2aec327e4f88a79f405705a  linux-5.15.tar.xz
022a3c82eb31596f9dde69a4c71721284f4129c5efd95fcef0c102ae4f53a70487e3c1ce44d92197510e98fcb0884398fc5b866938f93e542b2b010a592c5c75  linux-5.15.81.patch.xz
7fbbed5b6488cea6518c91147ae32c56bb113ff83c415d0564d5f442ccfaa7bd847a15351983b4d68c44a9fca764e34e6c3681086069d7cf6da467df6a4fce98  config-nokia-n900.armv7
04a39253afd25a7de03dc45ff322161672005406543c44b97d2dc293f202de7de446aee9707a690a290641c55c7bed6e78bbe096ca323dd7d88d3207427c8d31  0001-ARM-dts-n900-increase-charge-current-limit-to-950mA.patch
3cc2036ba264bd855358361aacb309ad1cf1660cb82a0978523508d1b3fe513676c58f6efc5bb64f7601b77392c19d2c609b6d83541db7e418c1737cff3973e8  0002-power-supply-bq27xxx-expose-battery-data-when-CI.patch
991237276bee4ff7bca24cf3a26afe3f12a2a604452793ad905a605890f761ac98374b5509cfbcab33c7b7ccf3da5cc286e70afe27b8e201387f403bf5025ae9  0003-wip-Revert-dma-direct-Fix-potential-NULL-pointer-der.patch
ea33adda06e1fb64b763c34f1f598bb00ccfdba5400d0996871138284b4cb8a51e021c7c0ace9d4bc16027530027fb2a443d5013c6f0b22ed3d64f36152c8854  0004-ARM-dts-omap3_n900-disable-thermal-for-now.patch
eb23d77ef3b03d90af43a22f37556c040f8ba69f91564d443615c9554c6ea4d19578730e8087b88751b5f673143cc557ac50bb81598f7f50aba08953c7604df8  0005-iio-accel-st-accel-add-lis302dl.patch
302aa8e6677e7ecfae473553806cdf5d47687c4f8e73322d0ace78486f9290ba503069ed6b41250fe38802b6c6091c7c4eac06ab387e011f1316b84ad5e2641d  0006-ARM-dts-N900-use-iio-driver-for-accelerometer.patch
acf3beef5448da7f3be19b862ac2fef65379d9f1617246baaab296083901174d891526cd9bf781162d4406089969c311701dfded04219bafd3c5c7784bc4c2e6  0007-Revert-ARM-omap3-enable-off-mode-automatically.patch
acaa153809c390957ee8d80caae440a41d84c78f045268ac226f05019dbdd69959b5cf56b6bac2e2c0300bcdb68649ffb847e7a0a333408bf5b4426fc969afe8  0008-wl1251-specify-max.-IE-length.patch
"
