# Reference: <https://postmarketos.org/devicepkg>
pkgname=device-kobo-clara
pkgdesc="Kobo Clara HD"
pkgver=0.7
pkgrel=1
url="https://postmarketos.org"
license="MIT"
arch="armv7"
options="!check !archcheck"
depends="
	kobo-epdc-extractor
	perl
	postmarketos-base
	u-boot-kobo-clara
	u-boot-tools
"
makedepends="devicepkg-dev"
subpackages="
	$pkgname-kernel-downstream:kernel_downstream
	$pkgname-kernel-mainline:kernel_mainline
	$pkgname-nonfree-firmware:nonfree_firmware
"
source="
	deviceinfo
	uboot-script-downstream.cmd
	uboot-script-mainline.cmd
"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname
}

kernel_downstream() {
	pkgdesc="Downstream kernel"
	depends="linux-kobo-clara"
	devicepkg_subpackage_kernel $startdir $pkgname $subpkgname

	mkimage -A arm -O linux -T script -n postmarketOS \
		-d "$srcdir"/uboot-script-downstream.cmd "$srcdir/boot-downstream.scr"
	install -Dm644 "$srcdir/boot-downstream.scr" "$subpkgdir/boot/boot.scr"
}

kernel_mainline() {
	pkgdesc="Close to mainline kernel"
	depends="linux-kobo-clara-mainline"
	devicepkg_subpackage_kernel $startdir $pkgname $subpkgname

	mkimage -A arm -O linux -T script -n postmarketOS \
		-d "$srcdir/uboot-script-mainline.cmd" "$srcdir/boot-mainline.scr"
	install -Dm644 "$srcdir/boot-mainline.scr" "$subpkgdir/boot/boot.scr"
}

nonfree_firmware() {
	pkgdesc="Kobo Clara HD firmware"
	depends="firmware-kobo-clara"
	mkdir "$subpkgdir"
}

sha512sums="
cf1537054e6123ccdc803c0ea5f99f2dbea499ea5d6be9f95893744a5dd2400544b5570232fb13009dfa3f9afd3b8dd54d29e645c9e0ff6aa5c845bca186a0b7  deviceinfo
4bfc2714a2670efc451860bd97d36ba12559e00aed41afdde1ac3e01b41458390358ac7f6bc96a6dee6be6a34f534da52d845b02df0566b25f4868774ef69b1d  uboot-script-downstream.cmd
9f624e90df6bc6acbd6db03d4319a778443b270e5756a2bc78002df8da19d23a3ea652f3d8da15257552a7381646b83553f794d24f6ef31479d3a16af9ae5e0b  uboot-script-mainline.cmd
"
