# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=datovka
pkgver=4.24.1
pkgrel=0
pkgdesc="A free graphical interface for Czech Databox"
url="https://www.datovka.cz/"
# riscv64: qmake6 segfaults
arch="all !riscv64"
license="GPL-3.0-or-later WITH cryptsetup-OpenSSL-exception"
makedepends="
	desktop-file-utils
	libdatovka-dev
	openssl-dev
	qt6-qt5compat-dev
	qt6-qtbase-dev
	qt6-qtsvg-dev
	qt6-qtwebsockets-dev
	quazip-dev
	zlib-dev
	"
subpackages="$pkgname-doc"
source="https://datovka.nic.cz/$pkgver/datovka-$pkgver.tar.xz
	disable-test_crypto_pin_pwd.patch
	"

prepare() {
	default_prepare

	# XXX: This enables '#define _Bool bool' which is needed on Alpine.
	sed -i 's/#if defined(__APPLE__) || defined(__clang__)/& || true/' \
		config.tests/libdatovka/*.cpp \
		src/*.cpp \
		src/*.h \
		src/isds/*.cpp \
		src/isds/*.h \
		src/datovka_shared/isds/*.h \
		tests/*.cpp

	# Fedora dropped them too, claiming that upstream had been notified.
	# Also disable db tests as they error and generate huge build log
	rm -f tests/test_crypto_message.pri \
		tests/test_isds_message.pri \
		tests/test_*db*.pri
}

build() {
	export CFLAGS="$CFLAGS -flto=auto"
	export CXXFLAGS="$CXXFLAGS -flto=auto"

	qmake6 PREFIX=/usr DISABLE_VERSION_CHECK_BY_DEFAULT=1
	make
}

check() {
	cd tests
	qmake6 tests.pro PREFIX=/usr
	make
	./tests
}

package() {
	make install INSTALL_ROOT="$pkgdir"
	desktop-file-validate "$pkgdir"/usr/share/applications/$pkgname.desktop
}

sha512sums="
7667eaf22b19d448ab71617911a517b9154eb084eec889be365cf05c6a767bd4b6954b80aee0bf7c24771c2fb11b1642a33262358a49e5ec5cb5bbd786ed0c64  datovka-4.24.1.tar.xz
ff0d49238fa5e2bf7c6f22f09c23453bf7b39f4252285e86c8bfa140be76b4b82122d4c9548fb6ab6009a5d071b2195a64b2226b5e295ce5f8c11e83c74b4448  disable-test_crypto_pin_pwd.patch
"
