# Reference: <https://postmarketos.org/vendorkernel>
# Maintainer: Newbyte <newbyte@disroot.org>
# Kernel config based on: arch/arm/configs/u8500_defconfig

_flavor="postmarketos-stericsson"
_config="config-$_flavor.armv7"
pkgname=linux-$_flavor
pkgver=6.1
pkgrel=0
pkgdesc="Mainline kernel for ST-Ericsson NovaThor devices"
arch="armv7"
_carch="arm"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-waydroid
	pmb:kconfigcheck-containers
	pmb:kconfigcheck-zram
	pmb:kconfigcheck-nftables
	"
makedepends="
	bash
	bison
	findutils
	gmp-dev
	flex
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
	postmarketos-installkernel
"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac
source="
	https://cdn.kernel.org/pub/linux/kernel/v${_kernver%%.*}.x/linux-$_kernver.tar.xz
	config-$_flavor.armv7
	0001-Disable-busy-detect-on-Ux500-MMCI.patch
	0002-pwm-ab8500-Get-HW-ID-from-reg-value.patch
	"
builddir="$srcdir/linux-${_kernver//_/-}"

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

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

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"/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="
6ed2a73c2699d0810e54753715635736fc370288ad5ce95c594f2379959b0e418665cd71bc512a0273fe226fe90074d8b10d14c209080a6466498417a4fdda68  linux-6.1.tar.xz
2e88c854ccb8b6e8aff23aeb818f4a9883d6aa366ecc96216f8d298a50346597ac59c22eacfda204d2e7720ce0d843e3e5c41a8b3c958ecb8da1a991a58ea49e  config-postmarketos-stericsson.armv7
2850f2c7a4405ed13c6ae18c97a1e8b3b0be545fb517a0b692666e559efdc00981a177f556c4c8fb6c8115d1c29674b6487a10700d9c30317ffb8d953c595281  0001-Disable-busy-detect-on-Ux500-MMCI.patch
3abf1a2b28077a2784c33f468facf44c2312f8bb54422463cffcb92a0eaa1f8954f1fa5f8f5acac0262495c08692a2161325c1ca68f7d23aecb36c1f9138d7ef  0002-pwm-ab8500-Get-HW-ID-from-reg-value.patch
"
