SUMMARY="GnuPG Made Easy is a library for making GnuPG easier to use"
DESCRIPTION="GnuPG Made Easy (GPGME) is a library designed to make access to GnuPG \
easier for applications. It provides a High-Level Crypto API for \
encryption, decryption, signing, signature verification and key management. \
Currently it uses GnuPG as its backend but the API isn't restricted to \
this engine; in fact we have already developed a backend for CMS (S/MIME)."
HOMEPAGE="http://www.gnupg.org/gpgme.html"
COPYRIGHT="1998-2020 Free Software Foundation, Inc.
	2001-2021 g10 Code GmbH"
LICENSE="GNU GPL v2
	GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://www.gnupg.org/ftp/gcrypt/gpgme/gpgme-$portVersion.tar.bz2"
CHECKSUM_SHA256="eebc3c1b27f1c8979896ff361ba9bb4778b508b2496c2fc10e3775a40b1de1ad"
PATCHES="gpgme-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

libgpgmeVersion="11.21.0"
libgpgmeppVersion="6.8.0"
libqgpgmeVersion="7.3.2"

#TODO: fix gpgme-config hardcoded package paths
PROVIDES="
	gpgme${secondaryArchSuffix} = $portVersion compat >= 1.9
	cmd:gpgme_json${secondaryArchSuffix} = $portVersion compat >= 1.9
	cmd:gpgme_tool${secondaryArchSuffix} = $portVersion compat >= 1.9
	lib:libgpgme${secondaryArchSuffix} = $libgpgmeVersion compat >= 11
	lib:libgpgmepp${secondaryArchSuffix} = $libgpgmeppVersion compat >= 6
	lib:libqgpgme${secondaryArchSuffix} = $libqgpgmeVersion compat >= 7
	"
REQUIRES="
	haiku${secondaryArchSuffix}
	lib:libassuan${secondaryArchSuffix}
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgpg_error${secondaryArchSuffix}
	lib:libQt5Core${secondaryArchSuffix}
	"

PROVIDES_devel="
	gpgme${secondaryArchSuffix}_devel = $portVersion compat >= 1.9
	cmd:gpgme_config${secondaryArchSuffix} = $portVersion compat >= 1.9
	devel:libgpgme${secondaryArchSuffix} = $libgpgmeVersion compat >= 11
	devel:libgpgmepp${secondaryArchSuffix} = $libgpgmeppVersion compat >= 6
	devel:libqgpgme${secondaryArchSuffix} = $libqgpgmeVersion compat >= 7
	"
REQUIRES_devel="
	gpgme${secondaryArchSuffix} == $portVersion base
	devel:libassuan${secondaryArchSuffix}
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libassuan${secondaryArchSuffix}
	devel:libglib_2.0$secondaryArchSuffix
	devel:libgpg_error${secondaryArchSuffix}
	devel:libQt5Core${secondaryArchSuffix}
	"
BUILD_PREREQUIRES="
	cmd:autoconf
	cmd:automake
	cmd:awk
	cmd:bison
	cmd:gcc${secondaryArchSuffix}
	cmd:git
	cmd:gpg$secondaryArchSuffix
	cmd:gpgconf$secondaryArchSuffix
	cmd:gpg_error$secondaryArchSuffix
	cmd:grep
	cmd:kill
	cmd:ld${secondaryArchSuffix}
	cmd:libtoolize
	cmd:make
	cmd:makeinfo
	cmd:msgfmt
	cmd:perl
	cmd:ps
	cmd:pkg_config$secondaryArchSuffix
	cmd:qmake$secondaryArchSuffix >= 5.12
	cmd:tar
	cmd:xargs
	"

BUILD()
{
	autoreconf -fi
	runConfigure ./configure
	make $jobArgs
	# kill gpg-agent processes
	ps -o Id Team | grep 'gpg-agent' | grep -v "grep" | awk '{print $1}' | xargs kill -9 $1
}

INSTALL()
{
	make install

	local develPackageName="${portName}_devel-$portFullVersion"
	local packageLinksDir=$(dirname $portPackageLinksDir)
	local assuanLinksDir="$packageLinksDir/${develPackageName}/devel~libassuan$secondaryArchSuffix/$relativeDevelopLibDir"

	# remove libtool files
	rm $libDir/lib*.la
	# fix lib path in cmake files
	sed -i "s|$libDir|$developLibDir|" \
		$libDir/cmake/QGpgme/QGpgmeConfig.cmake \
		$libDir/cmake/Gpgmepp/GpgmeppConfig.cmake
	sed -i "s|/packages/libassuan.*/lib|$assuanLinksDir|" \
		$libDir/cmake/QGpgme/QGpgmeConfig.cmake \
		$libDir/cmake/Gpgmepp/GpgmeppConfig.cmake

	prepareInstalledDevelLibs libgpgme libgpgmepp libqgpgme

	fixPkgconfig

	packageEntries devel \
		$developDir $libDir/cmake $binDir/gpgme-config
}

TEST()
{
	make check
}
