# Reference: <https://postmarketos.org/devicepkg>
pkgname="device-pine64-pinephone"
pkgdesc="PINE64 PinePhone"
pkgver=0.1
pkgrel=11
url="https://postmarketos.org"
license="MIT"
arch="aarch64"
options="!check !archcheck"
subpackages="
	$pkgname-weston
	$pkgname-x11
	$pkgname-nonfree-firmware:nonfree_firmware
"
depends="postmarketos-base u-boot-pine64 uboot-tools mesa-git mesa-git-glapi mesa-git-gl mesa-git-gles mesa-git-egl mesa-git-gbm mesa-git-dri-lima mesa-git-dri-kmsro linux-postmarketos-allwinner ofono"
makedepends="devicepkg-dev"
install="$pkgname.post-install"
source="
	deviceinfo
	uboot-script.cmd
	weston.ini
	xorg.conf
	hwtest.ini
"

build() {
	devicepkg_build $startdir $pkgname
	mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n postmarketos -d "$srcdir/uboot-script.cmd" "$srcdir/boot.scr"
}

package() {
	devicepkg_package $startdir $pkgname
	install -D -m644 "$srcdir"/boot.scr \
		"$pkgdir"/boot/boot.scr
	install -D -m644 "$srcdir"/hwtest.ini \
		"$pkgdir"/usr/share/hwtest.ini
}

x11() {
        install_if="$pkgname xorg-server"
        depends="
                libinput
                xf86-input-libinput
                xf86-video-fbdev"
        install -Dm644 "$srcdir"/xorg.conf \
                "$subpkgdir"/etc/X11/xorg.conf.d/10-framebuffer.conf
}

weston() {
        install_if="$pkgname weston"
        install -Dm644 "$srcdir"/weston.ini \
                "$subpkgdir"/etc/xdg/weston/weston.ini
}

nonfree_firmware() {
	pkgdesc="Wifi and Bluetooth firmware"
	depends="linux-firmware-rtlwifi linux-firmware-rtl_bt firmware-rtl8723bt"
	mkdir "$subpkgdir"
}


sha512sums="5695150bcd2d2593bb912d5e714a48f5e0e97eb27829c6b5620a6d7fc6baaa2dc32b97f57c0ce13235d07035c80e1a5300510744d17d7645fb91db6222423e4f  deviceinfo
f577807fc5b62637ea550f4bfe3b9d95a043250722da5db791a40e62908b3364fad8963244a0b9c6d5b30c87d75d43aeb4fd5eb65a3927324b75cf46563c2bb6  uboot-script.cmd
c4c57d1627dd451213e1ef20d89de9266cd4edcc2d33a69aa9a1f13e16d9f9742036b69dc149fd910d7213f7525c41eb79576d4457bc85cc96eba0d986382d27  weston.ini
f86ef35730b89bcc8160c08db7a7fcd0970adf60c0b77af68bac397de49c0d1783e6b8db1762380c9bf874aff2d030c6f44ecb75c803d69e79ede11376409369  xorg.conf
3dd6d612c381cb0002049d1974d8fb5aa5a53a1eb4d6bcbf62eb2ad52cfdc45f0f6ad24a699716d3513b0371aa1316f25dc72afc10d7176cc3b99d0965c3f030  hwtest.ini"
