# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/u8500_defconfig

_flavor="postmarketos-stericsson"
_config="config-$_flavor.armv7"
pkgname=linux-$_flavor
pkgver=5.13_rc2
pkgrel=0
_tag="5.13-rc2"
pkgdesc="Mainline kernel fork for ST-Ericsson NovaThor devices"
arch="armv7"
_carch="arm"
url="https://github.com/stericsson-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bison findutils gmp-dev flex installkernel mpc1-dev mpfr-dev openssl-dev perl"

source="
	$pkgname-$_tag.tar.gz::https://git.kernel.org/torvalds/t/linux-$_tag.tar.gz
	config-$_flavor.armv7
	bl.patch
"
builddir="$srcdir/linux-${_tag#v}"

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"/usr/share/dtb
	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="
eee237da43e08ac6d897510436b52fe042cff6583fd5406f4bc1535bd8a6780cbb0e1dfee9584b88cfa60fbc55a38be4cd5a424587c57168050f6ec6ce96890e  linux-postmarketos-stericsson-5.13-rc2.tar.gz
a55862ad08db8d9307107a1996c64b59f716870549ca7a9ce38a3ebcbd14b57e1cbb91f830c1f938f8cf3b5b5512a41edf06d9deec5a48fb02a03e8b18cc3873  config-postmarketos-stericsson.armv7
44ba95ca1278de476489ed505de6ea18140ee1f5f4176ecb0935a336c01e4468b7cb70176474e7fd12c886428dc74219fbcc3883b285276dda44530cd8262c32  bl.patch
"
