# Template file for 'gpgme'
#
# THIS PACKAGE MUST BE SYNCHRONIZED WITH "srcpkgs/gpgme-qt6"
pkgname=gpgme
version=1.24.1
revision=1
build_style=gnu-configure
build_helper="python3"
configure_args="--enable-fd-passing
 --with-libgpg-error-prefix=$XBPS_CROSS_BASE/usr
 --with-libassuan-prefix=$XBPS_CROSS_BASE/usr"
hostmakedepends="gnupg pkg-config python3-setuptools python3-installer
 python3-build python3-wheel swig"
makedepends="libassuan-devel libgpg-error-devel python3-devel"
checkdepends="which gnupg"
short_desc="GnuPG Made Easy"
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=ea05d0258e71061d61716584ec34cef59330a91340571edc46b78374973ba85f

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

post_build() {
	cd lang/python

	mkdir build
	ln -sf ../../../src/data.h build/data.h
	ln -sf ../../../conf/config.h build/config.h
	ln -sf src gpg

	top_builddir=../.. python3 -m build --wheel --no-isolation
}

post_install() {
	python3 -m installer --destdir="${DESTDIR}" lang/python/dist/*.whl
}

libgpgme_package() {
	# posix-util.c call gpgconf to get GnuPG binaries
	depends="gnupg>=2"
	short_desc+=" - library"
	pkg_install() {
		vmove "usr/lib/*.so.*"
	}
}

gpgme-devel_package() {
	depends="libassuan-devel libgpg-error-devel libgpgme>=${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/lib/pkgconfig
		vmove usr/bin/gpgme-config
		vmove usr/include/gpgme.h
		vmove usr/share
		vmove usr/lib/libgpgme.so
	}
}

gpgmepp_package() {
	short_desc+=" - C++ library"
	pkg_install() {
		vmove "usr/lib/libgpgmepp.so.*"
	}
}

gpgmepp-devel_package() {
	depends="gpgme-devel>=${version}_${revision} gpgmepp>=${version}_${revision}"
	short_desc+=" - C++ library development files"
	pkg_install() {
		vmove usr/include/gpgme++
		vmove usr/lib/libgpgmepp.so
		vmove usr/lib/cmake/Gpgmepp/GpgmeppConfig.cmake
		vmove usr/lib/cmake/Gpgmepp/GpgmeppConfigVersion.cmake
	}
}

gpgme-python3_package() {
	short_desc+=" - Python binding"
	depends="gpgme"
	pkg_install() {
		vmove "${py3_sitelib}"
	}
}

python3-gpg_package() {
	short_desc+=" - Python binding (transitional dummy package)"
	build_style=meta
	depends="gpgme-python3>=${version}_${revision}"
}
