# Template file for 'gpgme-qt6'
#
# THIS PACKAGE MUST BE SYNCHRONIZED WITH "srcpkgs/gpgme"
#
# IT IS SPLIT TO AVOID A CYCLIC DEDPENDENCY:
#     SDL2 -> pipewire -> libcanberra -> gtk+ -> gtk+3
#          -> colord -> sane -> poppler -> gpgme -> qt5 -> SDL2
pkgname=gpgme-qt6
version=1.23.2
revision=6
build_style=gnu-configure
configure_args="--enable-fd-passing
 --with-libgpg-error-prefix=$XBPS_CROSS_BASE/usr
 --with-libassuan-prefix=$XBPS_CROSS_BASE/usr"
hostmakedepends="gnupg pkg-config qt5-host-tools qt5-qmake qt6-base"
makedepends="libassuan-devel libgpg-error-devel qt5-devel qt6-base-devel"
checkdepends="which gnupg"
short_desc="GnuPG Made Easy - Qt6 binding"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-2.0-or-later, LGPL-2.1-or-later"
homepage="https://www.gnupg.org/software/gpgme/index.html"
changelog="https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gpgme.git;a=blob_plain;f=NEWS;hb=HEAD"
distfiles="https://www.gnupg.org/ftp/gcrypt/gpgme/gpgme-${version}.tar.bz2"
checksum=9499e8b1f33cccb6815527a1bc16049d35a6198a6c5fae0185f2bd561bce5224

CXXFLAGS="-D_GLIBCXX_USE_C99_STDIO=1"

if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	configure_args+=" ac_cv_sys_file_offset_bits=no"
elif [ "$XBPS_TARGET_WORDSIZE" = "32" ]; then
	CFLAGS="-D_FILE_OFFSET_BITS=64 -DLARGEFILE_SOURCE=1"
	CXXFLAGS+=" ${CFLAGS}"
fi

do_configure() {
	mkdir -p build
	( cd build && ../configure ${configure_args} )

	mkdir -p build-qt6
	( cd build-qt6 && \
		../configure ${configure_args} \
			--enable-languages=qt6,cpp \
			MOC=/usr/lib/qt6/libexec/moc )
}

do_build() {
	make -C build ${makejobs}
	make -C build-qt6 ${makejobs}
}

do_check() {
	make -C build ${makejobs} check
	make -C build-qt6 ${makejobs} check
}

do_install() {
	make -C build install DESTDIR=${DESTDIR}
	make -C build-qt6 install DESTDIR=${DESTDIR}

	# Remove files not related to Qt

	local f

	for f in "${DESTDIR}"/usr/{include,lib/cmake}/*; do
		[ -e "${f}" ] || continue
		case "${f##*/}" in
			Q*|q*) ;;
			*) rm -r "${f}" ;;
		esac
	done

	rm -r "${DESTDIR}"/usr/{bin,share,lib/pkgconfig}
	rm "${DESTDIR}"/usr/lib/{libgpgme,libgpgmepp}.so*
}

gpgmeqt_package() {
	short_desc="GnuPG Made Easy - Qt5 binding"
	pkg_install() {
		vmove "usr/lib/libqgpgme.so.*"
	}
}

gpgmeqt-headers_package() {
	short_desc="GnuPG Made Easy - Qt binding headers"
	pkg_install() {
		vmove usr/include/QGpgME
		vmove usr/include/qgpgme
	}
}

gpgmeqt-devel_package() {
	depends="gpgme-devel>=${version}
	 gpgmeqt-headers>=${version}_${revision}
	 gpgmeqt>=${version}_${revision}"
	short_desc="GnuPG Made Easy - Qt5 development files"
	pkg_install() {
		vmove usr/lib/libqgpgme.so
		vmove usr/lib/cmake/QGpgme
	}
}

gpgme-qt6-devel_package() {
	depends="gpgme-devel>=${version}
	 gpgmeqt-headers>=${version}_${revision}
	 gpgme-qt6>=${version}_${revision}"
	short_desc="GnuPG Made Easy - Qt6 development files"
	pkg_install() {
		vmove usr/lib/libqgpgmeqt6.la
		vmove usr/lib/libqgpgmeqt6.so
		vmove usr/lib/cmake/QGpgmeQt6
	}
}
