# Reference: <https://postmarketos.org/devicepkg>
maintainer="Anjandev Momi <anjan@momi.ca>"
pkgname=device-google-bonito
pkgdesc="Google Pixel 3a XL"
pkgver=11
pkgrel=0
url="https://postmarketos.org"
license="MIT"
arch="aarch64"
options="!check !archcheck"
depends="
	alsa-ucm-conf-qcom-sdm670
	firmware-google-sargo
	hexagonrpcd
	linux-firmware-ath10k
	linux-firmware-qca
	linux-firmware-qcom
	make-dynpart-mappings
	mkbootimg
	postmarketos-base
	soc-qcom
	soc-qcom-modem
	soc-qcom-pd-mapper
	soc-qcom-qbootctl
	systemd-boot
	unl0kr-fbforcerefresh
"
makedepends="devicepkg-dev"
install="$pkgname-openrc.post-install"
source="
	81-libssc-google-sargo.rules
	deviceinfo
	hexagonrpcd-adsp-sensorspd.confd
	modules-initfs
	no-hexagonrpcd-on-suspend.sh
	plasmacamerarc
	q6voiced.conf
"
subpackages="
	$pkgname-kernel-sdc:kernel_sdc
	$pkgname-kernel-tianma:kernel_tianma
	$pkgname-openrc:openrc
	$pkgname-plasma-camera:plasma_camera
"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	replaces="device-google-bonito-nonfree-firmware"
	devicepkg_package $startdir $pkgname

	# Sensors depend on ADSP firmware and the sensors registry served over FastRPC.
	install -Dm644 "$srcdir"/hexagonrpcd-adsp-sensorspd.confd \
		"$pkgdir"/usr/share/hexagonrpcd/hexagonrpcd-adsp-sensorspd.conf
	install -Dm644 "$srcdir"/81-libssc-google-sargo.rules \
		"$pkgdir"/usr/lib/udev/rules.d/81-libssc-google-sargo.rules

	# The q6voiced configuration can only be used if the ADSP is brought up
	# via non-free firmware.
	install -Dm644 "$srcdir"/q6voiced.conf \
		-t "$pkgdir"/usr/share/q6voiced/
}

kernel_sdc() {
	pkgdesc="Kernel for devices with the Samsung panel"
	depends="linux-postmarketos-qcom-sdm670"

	devicepkg_subpackage_kernel $startdir $pkgname $subpkgname
}

kernel_tianma() {
	pkgdesc="Kernel for devices with the Tianma panel"
	depends="linux-postmarketos-qcom-sdm670"

	devicepkg_subpackage_kernel $startdir $pkgname $subpkgname
}

openrc() {
	install_if="$pkgname=$pkgver-r$pkgrel openrc"
	# Enable HexagonRPCD by default, but not if the user installed this
	# package then disabled it.
	depends="hexagonrpcd-openrc openrc"

	# The FastRPC service is only enabled when non-free firmware is installed.
	install -Dm755 "$srcdir"/no-hexagonrpcd-on-suspend.sh \
		-t "$subpkgdir"/usr/libexec/elogind/system-sleep
}

plasma_camera() {
	install_if="$pkgname=$pkgver-r$pkgrel plasma-camera"

	install -Dm644 "$srcdir"/plasmacamerarc "$subpkgdir"/etc/xdg/plasmacamerarc
}

sha512sums="
e358f0565b95cd5d39dd5bc07645c6e0f94679c93b120b72bd2b6082b7f919e990a6a78e03edc0db045f8fc5e3363377c69fb8e42107298868ec319740c29210  81-libssc-google-sargo.rules
bbd5032dd4d40554b3a0d44c1a35c1f1b984f347b9a3d2d4fd718aeedc2e39e8efc8243af5829dd31300c6cb49c8d5f4678364b787861f2144a88e063d90397b  deviceinfo
b6208c254b6e44ac4f6d748a38cc6b05da0db2c90235ada2011b138b82ccc3372687df2f5ad97e885e9eea135216a3c52266a08a7f4eb323e62e799f6f82ec7b  hexagonrpcd-adsp-sensorspd.confd
0253ff4688b789aa7cdbffb22e7ff9497aabe083adc44bf33fa52617215a1f48fc722bd61aa13a35d109eff1e69202eb599dccff029e39c0a390dcab11dd9b76  modules-initfs
2972005a9cf6ca57061965075593dddfa8ee479bc6c21cd41851b1a14768cb1cddbd31a17975ae17adc36d40d294ccbc6bf83defbd69fc7b363f638d8564fbbc  no-hexagonrpcd-on-suspend.sh
53bec3338d875ecedf2ae981cf9a0f9066e276f09570b3bd06217414461126a76942b70e01c3bb18831fbefeb188621dd5a341ab2604e8fb0c6de8a3025177e2  plasmacamerarc
3a4a9322839d4b3ef9d79668a37840a9f444954759ae3c512e694051d2f9a2573db42ad6c4c1a5c75eeb861232a27ba1a8cef9b503decd54ead25a96e3dd6f98  q6voiced.conf
"
