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

pkgname=linux-kobo-clara-mainline
pkgver=6.1.12
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="d6a0a4cc5f6fd75a5c6e26e14b2c2d6c94918ff3"
_rtl8189fs_repository="rtl8189ES_linux"
_rtl8189fs_commit="476020109b3841421af289a7b78c7a25b0c45fac"
_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="
e490188a6748c99209fcefef461c47bbc6174149c6ea00c35d141be0b924733ee7650a78776647781dc69ed8530a49b0eaa3fe0edd844094100ed75254f6f303  linux-kobo-clara-mainline-d6a0a4cc5f6fd75a5c6e26e14b2c2d6c94918ff3.tar.gz
24a3db037d52c8d1b537e8e3fb106dc722f80688801eca5d3f423027be8e9acf189a53b514375a44d9b7f2e7e9565627d73cb25bf083cdc5d68d0b8260028d9b  rtl8189ES_linux-476020109b3841421af289a7b78c7a25b0c45fac.tar.gz
124728c37c8cc701c2286d852283de312339298fe67db108ebc588a7eea68820241ce34d09a8a4f6cf16103fa2d9accfc0c7fcb2387dfcea7994b5cd9150a2a6  config-kobo-clara-mainline.armv7
"
