# Maintainer: Andreas Kemnade <andreas@kemnade.info>
# Kernel config based on: arch/arm/configs/kobo_defconfig

pkgname=linux-kobo-clara-mainline
pkgver=6.3.0
pkgrel=0
pkgdesc="Kobo Clara HD kernel fork, close to mainline"
arch="armv7"
_carch="arm"
_flavor="kobo-clara-mainline"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native pmb:kconfigcheck-nftables"
makedepends="
	bash
	bc
	bison
	devicepkg-dev
	findutils
	flex
	gmp-dev
	lzop
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
"

# Source
_repository="linux"
_commit="f36056f9be0d6cd9eabf670a078c79699c02b1fd"
_rtl8189fs_repository="rtl8189ES_linux"
_rtl8189fs_commit="c223a25b1000d64432eca4201a8f012414dfc7ce"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/akemnade/$_repository/archive/$_commit.tar.gz
	$_rtl8189fs_repository-$_rtl8189fs_commit.tar.gz::https://github.com/jwrdegoede/$_rtl8189fs_repository/archive/$_rtl8189fs_commit.tar.gz
	$_config
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"
_rtl8189fs_dir="$srcdir/$_rtl8189fs_repository-$_rtl8189fs_commit"

prepare() {
	REPLACE_GCCH=0
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$(( pkgrel + 1 ))-postmarketOS"
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$(( pkgrel + 1 ))-postmarketOS" \
		CONFIG_RTW_SDIO_PM_KEEP_POWER=n \
		CONFIG_RTW_DEBUG=n \
		-C "$_rtl8189fs_dir" KSRC="$builddir"
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor" "$_outdir"
	make modules_install dtbs_install \
		O="$_outdir" ARCH="$_carch" \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/boot/dtbs"
	install -Dm644 "$_rtl8189fs_dir"/8189fs.ko "$pkgdir/lib/modules/$(make -s O="$_outdir" ARCH="$_carch" kernelrelease)/kernel/drivers/net/wireless"
}

sha512sums="
1b80e9a6bf430fe234df2c441ce4b74d69e72d85635b4efe426797d18fd716979629ea60d589c13dc3efed785400dc04e8941109a9cbae49e60a9120681cf9e2  linux-kobo-clara-mainline-f36056f9be0d6cd9eabf670a078c79699c02b1fd.tar.gz
5c20debd33a3ebeb7837c639d2a602e02648d335d8aad4c6aa87a701ba2cc3e302ab13ac3a536afb0a081d664692dcb11cc893303298ad9caf67e16d2e6b7dde  rtl8189ES_linux-c223a25b1000d64432eca4201a8f012414dfc7ce.tar.gz
1dc0df7b08f0d4da0530a27ca12e83a3370aea0de992bfe9e1acd4da111ce6aa385f9e168b41841ce7b25ca32e8bfe0ef1582dfd405684a77ebbd5ae5b7af0b9  config-kobo-clara-mainline.armv7
"
