SUMMARY="Barcode and QR scanning library"
DESCRIPTION="ZBar is an open source software suite for reading bar codes \
from various sources, such as video streams, image files and raw intensity \
sensors. It supports many popular symbologies (types of bar codes) including \
EAN-13/UPC-A, UPC-E, EAN-8, Code 128, Code 39, Interleaved 2 of 5 and QR Code.\
The flexible, layered implementation facilitates bar code scanning and decoding \
for any application: use it stand-alone with the included GUI and command line \
programs, easily integrate a bar code scanning widget into your Qt, GTK+ or \
PyGTK GUI application, leverage one of the script or programming interfaces \
(Python, Perl, C++) ...all the way down to a streamlined C library suitable \
for embedded use."
HOMEPAGE="https://github.com/mchehab/zbar/"
COPYRIGHT="2007-2010 Jeff Brown"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://github.com/mchehab/zbar/archive/refs/tags/$portVersion.zip"
CHECKSUM_SHA256="db1db11da4b7a3e2be752dfe2844834482ce72fd024c6b8f499d8caba0a52ce4"

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

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

libVersion="0.3.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	zbar$secondaryArchSuffix = $portVersion
	cmd:zbarimg$commandSuffix = $portVersion
	lib:libzbar$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libMagick++_7.Q16HDRI$secondaryArchSuffix
	lib:libMagickCore_7.Q16HDRI$secondaryArchSuffix
	lib:libMagickWand_7.Q16HDRI$secondaryArchSuffix
	"

PROVIDES_devel="
	zbar${secondaryArchSuffix}_devel = $portVersion
	devel:libzbar$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	zbar$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libMagick++_7.Q16HDRI$secondaryArchSuffix
	devel:libMagickCore_7.Q16HDRI$secondaryArchSuffix
	devel:libMagickWand_7.Q16HDRI$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:autopoint
	cmd:awk
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

defineDebugInfoPackage zbar$secondaryArchSuffix \
	"$commandBinDir"/zbarimg \
	"$libDir"/libzbar.so.$libVersion

BUILD()
{
	autoreconf -vfi
	LDFLAGS="-lintl" runConfigure --omit-dirs $binDir ./configure \
		--bindir=$commandBinDir \
		--disable-video \
		--without-dbus \
		--without-qt \
		--without-gtk \
		--without-python
		
	# Patch libtool for build as ln silently fails
	# this will instead trigger an OR statement and copy the file
	sed -i 's/func_show_eval "ln /func_show_eval "false /' libtool
	make $jobArgs
}

INSTALL()
{
	make install

	prepareInstalledDevelLib libzbar
	fixPkgconfig

	packageEntries devel \
		"$developDir"
}
