SUMMARY="Middleware to access a smart card using SCard API (PC/SC)"
DESCRIPTION="PSCS-lite implements the PC/SC international standard for PC \
to smartcard reader communication."
HOMEPAGE="https://pcsclite.apdu.fr"
COPYRIGHT="1999-2002 David Corcoran
	2001-2014 Ludovic Rousseau
	2003-2004 Damien Sauveron"
LICENSE="MIT
	GNU GPL v2
	BSD (3-clause)"
REVISION="1"
SOURCE_URI="https://pcsclite.apdu.fr/files/pcsc-lite-$portVersion.tar.bz2"
CHECKSUM_SHA256="d76d79edc31cf76e782b9f697420d3defbcc91778c3c650658086a1b748e8792"
SOURCE_DIR="pcsc-lite-$portVersion"
PATCHES="pcsc_lite-$portVersion.patchset"
ADDITIONAL_FILES="create-pcscd-directory.sh"

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

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

libpcscliteVersion="1.0.0"
libpcscspyVersion="0.0.0"
libpcscspyVersionCompat="$libpcscspyVersion compat >= ${libpcscspyVersion%%.*}"
libpcscliteVersionCompat="$libpcscliteVersion compat >= ${libpcscliteVersion%%.*}"

POST_INSTALL_SCRIPTS="$relativePostInstallDir/create-pcscd-directory.sh"

PROVIDES="
	pcsc_lite$secondaryArchSuffix = $portVersion
 	cmd:pcsc_spy$commandSuffix = $portVersion
	cmd:pcscd$commandSuffix = $portVersion
	lib:libpcsclite$secondaryArchSuffix = $libpcscliteVersionCompat
	lib:libpcscspy$secondaryArchSuffix = $libpcscspyVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libusb_1.0$secondaryArchSuffix
	"

PROVIDES_devel="
	pcsc_lite${secondaryArchSuffix}_devel = $portVersion
	devel:libpcsclite$secondaryArchSuffix = $libpcscliteVersionCompat
	devel:libpcscspy$secondaryArchSuffix = $libpcscspyVersionCompat
	"
REQUIRES_devel="
	pcsc_lite$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libusb_1.0$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:awk
	cmd:autoreconf
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	autoreconf -vfi

	runConfigure --omit-dirs "binDir sbinDir" ./configure \
		--bindir="$commandBinDir" \
		--sbindir="$commandBinDir" \
		--disable-libsystemd

	make $jobArgs
}

INSTALL()
{
	make $jobArgs install

	mkdir -p $postInstallDir
	cp -f $portDir/additional-files/create-pcscd-directory.sh $postInstallDir

	rm $libDir/*.la

	prepareInstalledDevelLibs \
		libpcsclite \
		libpcscspy
	fixPkgconfig

	packageEntries devel \
		$developDir
}
