# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=qtkeychain
pkgver=0.14.3
pkgrel=0
pkgdesc="Qt API to store passwords and other secret data"
url="https://github.com/frankosterfeld/qtkeychain"
arch="all"
license="BSD-2-Clause"
depends="dbus:org.freedesktop.Secrets"
makedepends="
	cmake
	libsecret-dev
	qt5-qttools-dev
	qt6-qttools-dev
	samurai
	"
subpackages="
	$pkgname-dev
	qt5-qtkeychain:qt5
	qt6-qtkeychain:qt6
	qt5-qtkeychain-lang:qt5_lang
	qt6-qtkeychain-lang:qt6_lang
	"
# replace prior names
replaces="qtkeychain qt5-qtkeychain qt5-qtkeychain-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/frankosterfeld/qtkeychain/archive/$pkgver.tar.gz"
options="!check"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	export CXXFLAGS="$CXXFLAGS -DNDEBUG -flto=auto"

	cmake -B build-qt5 -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		$CMAKE_CROSSOPTS

	cmake --build build-qt5

	cmake -B build-qt6 -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_WITH_QT6=ON \
		$CMAKE_CROSSOPTS

	cmake --build build-qt6
}

package() {
	DESTDIR="$pkgdir" cmake --install build-qt5
	DESTDIR="$pkgdir" cmake --install build-qt6
}

qt5() {
	pkgdesc="$pkgdesc (Qt5)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/libqt5keychain.so.*
}

qt5_lang() {
	pkgdesc="$pkgdesc (Qt5 translations)"
	install_if="qt5-qtkeychain=$pkgver-r$pkgrel lang"

	amove usr/share/qt5keychain/translations
}

qt6() {
	pkgdesc="$pkgdesc (Qt6)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/libqt6keychain.so.*
}

qt6_lang() {
	pkgdesc="$pkgdesc (Qt6 translations)"
	install_if="qt6-qtkeychain=$pkgver-r$pkgrel lang"

	amove usr/share/qt6keychain/translations
}

sha512sums="
d1d87553db94bf54da1373016a847476e6cd608db6d427ed72532658e2272501daf45d7c9976efdde2f26ab3810ba9dbfec2518d46dee5a76ecaa369bfee2e4a  qtkeychain-0.14.3.tar.gz
"
