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"
SOURCE_URI="ftp://ftp.gnupg.org/gcrypt/gpgme/gpgme-$portVersion.tar.bz2"
CHECKSUM_SHA256="0b3d3d5107680c594777aae65882a1ff6dd1ba629a83432e719c8b82a743c207"
REVISION="1"
LICENSE="
	GNU GPL v2
	GNU LGPL v2.1
	"
COPYRIGHT="
	1998-2010 Free Software Foundation, Inc.
	2001-2010 g10 Code GmbH
	"

ARCHITECTURES="x86_gcc2 x86 x86 x86_64"
SECONDARY_ARCHITECTURES="x86"

#TODO: fix gpgme-config hardcoded package paths
PROVIDES="
	gpgme${secondaryArchSuffix} = $portVersion compat >= 1.5
	cmd:gpgme_tool${secondaryArchSuffix} = $portVersion compat >= 1.5
	lib:libgpgme_pthread${secondaryArchSuffix} = 11.13.4 compat >= 11
	lib:libgpgme${secondaryArchSuffix} = 11.13.4 compat >= 11
	"
REQUIRES="
	haiku${secondaryArchSuffix}
	lib:libgpg_error${secondaryArchSuffix}
	cmd:gpg
	lib:libglib_2.0$secondaryArchSuffix
	lib:libassuan${secondaryArchSuffix}
	"
BUILD_REQUIRES="
	devel:libgpg_error${secondaryArchSuffix}
	devel:libglib_2.0$secondaryArchSuffix
	devel:libassuan${secondaryArchSuffix}
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:autoconf
	cmd:automake
	cmd:bison
	cmd:gcc${secondaryArchSuffix}
	cmd:git
	cmd:gpg
	cmd:gpg_error$secondaryArchSuffix
	cmd:ld${secondaryArchSuffix}
	cmd:libtoolize
	cmd:make
	cmd:makeinfo
	cmd:msgfmt
	cmd:perl
	cmd:tar
	"
PATCHES="gpgme-$portVersion.patchset"

BUILD()
{
	autoreconf -fi
	runConfigure ./configure
	make $jobArgs
}

INSTALL()
{
	make install

	prepareInstalledDevelLibs libgpgme libgpgme-pthread

	# The libtool files reference other libraries using the wrong paths, which
	# creates a lot of confusion. Fix them so correct paths are used.
	local develPackageName="${portName}_devel-$portFullVersion"
	local packageLinksDir=$(dirname $portPackageLinksDir)
	for l in libgpgme libgpgme-pthread; do
		local linksDir="$packageLinksDir/${develPackageName}/devel~libassuan$secondaryArchSuffix/$relativeDevelopLibDir"
		sed -i -e "s,\(-L/packages/libassuan[^ ]*\),-L$linksDir," \
			-e "s,[^ ]*/libassuan\.la,$linksDir/libassuan.la,g" \
			$developLibDir/$l.la
		local linksDir="$packageLinksDir/${develPackageName}/devel~libgpg_error$secondaryArchSuffix/$relativeDevelopLibDir"
		sed -i -e "s,\(-L/packages/libgpg_error[^ ]*\),-L$linksDir," \
			-e "s,[^ ]*/libgpg-error\.la,$linksDir/libgpg-error.la,g" \
			$developLibDir/$l.la
	done

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

TEST()
{
	make check
}

# ----- devel package -------------------------------------------------------

PROVIDES_devel="
	gpgme${secondaryArchSuffix}_devel = $portVersion compat >= 1.5
	cmd:gpgme_config${secondaryArchSuffix} = $portVersion compat >= 1.5
	devel:libgpgme_pthread${secondaryArchSuffix} = 11.13.4 compat >= 11
	devel:libgpgme${secondaryArchSuffix} = 11.13.4 compat >= 11
	"
REQUIRES_devel="
	gpgme${secondaryArchSuffix} == $portVersion base
	"
