# Contributor: Yves Schumann <yves@eisfair.org>
# Maintainer: Ariadne Conill <ariadne@dereferenced.org>
pkgname=quassel
pkgver=0.14.0
pkgrel=17
url="https://www.quassel-irc.org/"
pkgdesc="Distributed IRC client - metapackage"
arch="all"
license="GPL-2.0-or-later"
options="!check"
install="$pkgname-core.pre-install"
pkgusers="quassel"
pkggroups="quassel"
makedepends="
	boost-dev
	cmake
	dbus-dev
	extra-cmake-modules
	icu-dev
	openldap-dev
	openssl-dev>3
	qca-dev
	qt5-qtbase-dev
	qt5-qtmultimedia-dev
	qt5-qttools-dev
	samurai
	zlib-dev
	"
source="https://www.quassel-irc.org/pub/quassel-$pkgver.tar.bz2
	quasselcore.confd
	quasselcore.initd
	"
subpackages="
	$pkgname-common::noarch
	$pkgname-core
	$pkgname-core-openrc:core_openrc
	$pkgname-client
	$pkgname-mono
	$pkgname-libs-core:core_libs
	$pkgname-libs-qtui:qtui_libs
	$pkgname-libs-client:client_libs
	$pkgname-libs-common:common_libs
	$pkgname-libs-uisupport:uisupport_libs
	"

# secfixes:
#   0.13.1-r6:
#     - CVE-2021-34825

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DWANT_CORE=ON \
		-DWANT_MONO=ON \
		-DWANT_QTCLIENT=ON \
		-DWITH_KDE=0 \
		-DWITH_WEBKIT=OFF
	cmake --build build
}

package() {
	# install monolithic client by default
	depends="$pkgname-mono"
	DESTDIR="$pkgdir" cmake --install build

	install -Dm0644 "$srcdir"/quasselcore.confd \
		"$pkgdir"/etc/conf.d/quasselcore
	install -Dm0755 "$srcdir"/quasselcore.initd \
		"$pkgdir"/etc/init.d/quasselcore
}

common() {
	pkgdesc="Distributed IRC client - common/shared files"

	amove usr/share/icons \
		usr/share/$pkgname
}

core() {
	pkgdesc="Distributed IRC client - server"
	depends="qt5-qtbase-postgresql qt5-qtbase-sqlite quassel-common=$pkgver-r$pkgrel"

	amove usr/bin/quasselcore
}

core_openrc() {
	pkgdesc="Distributed IRC client - server (OpenRC init scripts)"
	install_if="openrc $pkgname-core=$pkgver-r$pkgrel"

	default_openrc
}

client() {
	pkgdesc="Distributed IRC client - client"
	depends="quassel-common=$pkgver-r$pkgrel"

	amove usr/bin/quasselclient \
		usr/share/applications/quasselclient.desktop
}

mono() {
	pkgdesc="Distributed IRC client - monolithic all-in-one package"

	amove usr/bin/quassel \
		usr/share/applications/quassel.desktop
}

core_libs() {
	pkgdesc="Distributed IRC client - server libraries"

	amove usr/lib/libquassel-core.so*
}

qtui_libs() {
	pkgdesc="Distributed IRC client - qtui libraries"

	amove usr/lib/libquassel-qtui.so*
}

client_libs() {
	pkgdesc="Distributed IRC client - client libraries"

	amove usr/lib/libquassel-client.so*
}

common_libs() {
	pkgdesc="Distributed IRC client - common libraries"

	amove usr/lib/libquassel-common.so*
}

uisupport_libs() {
	pkgdesc="Distributed IRC client - uisupport libraries"

	amove usr/lib/libquassel-uisupport.so*
}

sha512sums="
ea6b9723acab5ce73f760692770c1340c03bf277d2c99a2520345bfb6a7bb6fdc64a01dccfd7026341b46ee727821e1bcc2f487be72dfbc155f1de1ad264763f  quassel-0.14.0.tar.bz2
56d4b05fcb2702c103a611a170e444e237bd7c8626219063e5853c3efa5d91e21fa9b726b056393070e35b7d7efe0a145ac3ab61413bc8033642d7acb622b638  quasselcore.confd
7a0dd5a04b28c3099b4c9e98a25e6dc2b72bdb1e450e7299f9556487f6b34748ae881a4ccb955396e2ac0eab5d3fce4dbea426d7fa498d069f5d185057efa4cf  quasselcore.initd
"
