# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/librem5-devkit_defconfig
pkgname="linux-purism-librem5"
# <kernel ver>.<purism kernel release>
pkgver=5.6.0
_purismver=${pkgver}_rc7+librem5.1
# Note: abusing pkgrel due to not using _rc# earlier, so package is still an
# 'upgrade'. When 5.6.1 is out, stop doing this.
pkgrel=1
pkgdesc="Purism Librem 5 phone kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="purism-librem5"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev
	     devicepkg-dev bison flex openssl-dev"

# Source
_repository="linux-next"
# imx8-current-librem5 branch:
# kconfig generated with: ARCH=arm64 make defconfig KBUILD_DEFCONFIG=librem5_defconfig
_config="config-$_flavor.$arch"
source="
	$pkgname-$_purismver.tar.gz::https://source.puri.sm/Librem5/$_repository/-/archive/pureos/$_purismver/$_repository-pureos-$_purismver.tar.gz
	$_config
"
builddir="$srcdir/$_repository-pureos-$_purismver"

prepare() {
	default_prepare
	REPLACE_GCCH=0 \
		. downstreamkernel_prepare
}

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

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

	local _install
	case "$CARCH" in
	aarch64*|arm*)	_install="modules_install dtbs_install" ;;
	*)		_install="modules_install" ;;
	esac

	make -j1 $_install \
		ARCH="$_carch" \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/usr/share/dtb"

}
sha512sums="9371906611216ea7d2f66171b5abf2d0dcf769ec5b2dbe15123da39f30f1121e7c1104b8f67e27ee3be8dab3cb29a472ee87b48ea8161ae83f4fd108637e7548  linux-purism-librem5-5.6.0_rc7+librem5.1.tar.gz
7189c0211457284a93106a24e80e084fb991d2162a7eb65eb52cd9fe4df4ab87fccbba1b2c35fe88766b33e1c23eff9305982ae82f78a3f40263a25d661346f3  config-purism-librem5.aarch64"
