# Contributor: Daniele Debernardi <drebrez@gmail.com>
# Maintainer: Daniele Debernardi <drebrez@gmail.com>

pkgname=linux-nokia-n900
pkgver=5.3.2
pkgrel=2
pkgdesc="Mainline kernel fork for Nokia N900"
arch="armv7"
url="https://kernel.org/"
license="GPL-2.0-only"
options="!strip !check !tracedeps"
makedepends="bison findutils flex installkernel openssl-dev perl"

_carch="arm"
_flavor=nokia-n900
_config="config-$_flavor.armv7"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.*};;
	*.*) _kernver=$pkgver;;
esac
source="
	https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$_kernver.tar.xz
	$_config
	0001-ARM-dts-n900-increase-charge-current-limit-to-950mA.patch
	0002-ARM-dts-n900-remove-rx51-battery.patch
	0003-power-supply-bq27xxx_battery-ignore-inaccurate-flag.patch
"
if [ "${pkgver%.0}" = "$pkgver" ]; then
	source="$source
	https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/patch-$pkgver.xz"
fi
builddir="$srcdir/linux-$_kernver"

prepare() {
	if [ "$_kernver" != "$pkgver" ]; then
		msg "Applying patch-$pkgver.xz"
		unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1 -N
	fi
	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_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/usr/share/dtb"

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

sha512sums="6b5edef47c319a3fa7f6c20a3e0903a5acd89ec75e32dc5f99adcb60c9fe118ea312722d9c3d27e2e3900afa2455afb86e83a8b6bb131009bc79ddbe6fb0595d  linux-5.3.tar.xz
1bb77dba5753194437fae7304a8304d4f4f0a2e4c5bf9c8c410ee07486e7eccff44ffbd3fd81e937bf32a2c5ead766f0606203addc8a024cbf6b471040c3d051  config-nokia-n900.armv7
04a39253afd25a7de03dc45ff322161672005406543c44b97d2dc293f202de7de446aee9707a690a290641c55c7bed6e78bbe096ca323dd7d88d3207427c8d31  0001-ARM-dts-n900-increase-charge-current-limit-to-950mA.patch
c1055c7a4d2e39ce13db3871d948022b62eb7ebeb898777d197169b3e7c04d705ce7f52f28214754e3cefe99d1dd66f339a1a5770bae1ee970d5926067032061  0002-ARM-dts-n900-remove-rx51-battery.patch
cca336961620cc8aea700bf22d4d788f514177c37fb2a660478b731cf2f01d4e63bfa0951aae39b7dfa722966a1692bc237eda1951e4fe1da3f597aa68b56ebe  0003-power-supply-bq27xxx_battery-ignore-inaccurate-flag.patch
3528b4355ebbf1a1cbc4ac7efd7cdd5b5dddb28c30e182e8c0f3119c61a97d6bc1fb07ec8f2cf0a78067b098c27535bc006485428c76d6c8fb653f215218dff3  patch-5.3.2.xz"
