# Reference: <https://postmarketos.org/devicepkg>
maintainer="Patriot-06 <mbmc172@gmail.com>"
pkgname=device-realme-x3
pkgdesc="Realme X3"
pkgver=3
pkgrel=0
url="https://postmarketos.org"
license="MIT"
arch="aarch64"
options="!check !archcheck"
depends="
	postmarketos-base
	mkbootimg
	linux-realme-x3
	mesa-vulkan-freedreno
	swclock-offset
"
makedepends="devicepkg-dev"
source="
	alsa-ucm-conf/HiFi.conf
	alsa-ucm-conf/x3.conf
	deviceinfo
	kernel-cmdline.conf
	30-gpu-firmware.files
	51-qcom-sm8150.lua
	modules-initfs
"

subpackages="
	$pkgname-nonfree-firmware:nonfree_firmware
	$pkgname-nonfree-firmware-openrc:nonfree_firmware_openrc
	$pkgname-alsa_ucm_conf
	$pkgname-wireplumber
"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname
}

nonfree_firmware() {
	pkgdesc="Firmware for GPU, Touchscreen, Audio, Bluetooth, WiFi, etc."
	depends="
		firmware-realme-x3
		msm-modem
		pd-mapper
		tqftpserv
		bootmac
		alsa-utils
		"

	install -Dm644 "$srcdir/30-gpu-firmware.files" \
		 "$subpkgdir/usr/share/mkinitfs/files/30-gpu-firmware.files"
}

nonfree_firmware_openrc() {
	install_if="$pkgname-nonfree-firmware=$pkgver-r$pkgrel openrc"
	install="$subpkgname.post-install"
	depends="
		openrc
		pd-mapper-openrc
		tqftpserv-openrc
	"

	mkdir -p "$subpkgdir"
}

alsa_ucm_conf() {
	install -Dm644 "$srcdir/HiFi.conf" \
		"$subpkgdir/usr/share/alsa/ucm2/Realme/x3/HiFi.conf"

	install -Dm644 "$srcdir/x3.conf" \
		"$subpkgdir/usr/share/alsa/ucm2/Realme/x3/x3.conf"

	mkdir -p "$subpkgdir/usr/share/alsa/ucm2/conf.d/sdm845"
	ln -s ../../Realme/x3/x3.conf \
		"$subpkgdir/usr/share/alsa/ucm2/conf.d/sdm845/Realme X3.conf"
}

wireplumber() {
	install -Dm644 "$srcdir/51-qcom-sm8150.lua" \
		-t "$subpkgdir/usr/share/wireplumber/main.lua.d"
}

sha512sums="
da5509da4b7f0dbf5e2c95375b334a750cef620f8ea77c17c8dde611134bdf474b4e10723f6d656b42843a727e395d352dd0578f1317fcbdf623f4533273fb49  HiFi.conf
28d8dadac648f007d6e554684200bb1c0fb699a472e8459802691bbbadd67458626969d3d418ae145b94bedb3e83d73e8403206c0b4b509a6d3c541b6b733a7a  x3.conf
162720a1003b43664847be88b7731321fe65cc1e6d86e072ac4adf355611beaf1870c820692e7f58197b128d63688f0ec05fe453043532a4fd61c5f670356108  deviceinfo
a230e30a05453491d41ba4a6a4c504e3dbe7b630402ac2b837aa5d977c2d38c73c93fb198e8aff892a12005de8d2355593fe2fae8e3e9412418efb1d32250022  kernel-cmdline.conf
281ddbbd0cc49f54debed63d4531b5b3154b7c1ff9b5482d4b5b8cf655ddb9972f2a21b889db0bde5b9607dd298c9ed9b61c9772f1d0544a5e103da73d4dcf4f  30-gpu-firmware.files
d97601fd5bd36c5710c9a122e400cdd0aecf37df7088bfef4490aef2356f15533cdf70e47e3a270cd77d5384ac1fcdc9c6ea46e314c3b88db26bfc8d86fdadce  51-qcom-sm8150.lua
dbf6f3280cda66914be3215d771105b2994fc2e76c69d461c63ddbb914fe7882432a4d8c8a2590288c660ae4a834c2ddf0f7282a87c87c965631574db38c5a1c  modules-initfs
"
