# Template file for 'zbar'
pkgname=zbar
version=0.23.1
revision=8
build_style=gnu-configure
build_helper=gir
configure_args="$(vopt_with qt) --with-gir --with-python=python3"
hostmakedepends="pkg-config python3-setuptools glib-devel
 $(vopt_if qt 'qt5-qmake qt5-host-tools')"
makedepends="libmagick-devel libXv-devel python3-devel v4l-utils-devel
 gtk+3-devel $(vopt_if qt qt5-x11extras-devel)"
depends="libzbar-${version}_${revision}"
short_desc="Barcode reading library and application"
maintainer="Leah Neukirchen <leah@vuxu.org>"
license="LGPL-2.1-or-later"
homepage="https://git.linuxtv.org/zbar.git/"
distfiles="https://linuxtv.org/downloads/zbar/${pkgname}-${version}.tar.bz2"
checksum=dad260b47ef887a639e840a89e5e6e132217b6bba2a8473565d1f459bcb97c1f

build_options="qt"
case "$XBPS_TARGET_MACHINE" in
	mips*)	;; # don't enable qt as it can't be built for mips*
	*) build_options_default="qt" ;;
esac

case "$XBPS_TARGET_MACHINE" in
	*-musl) makedepends+=" argp-standalone"
		LDFLAGS="-largp"
		;;
esac

export PYTHON_CFLAGS="-I$XBPS_CROSS_BASE/usr/include/python$py3_ver"
CFLAGS="-DNDEBUG"

subpackages="libzbar libzbar-devel"

if [ "$build_option_qt" ]; then
	subpackages+=" zbar-qt libzbar-qt"
fi

post_extract() {
	# 0.23.1 doesn't ship this file, corrected in master
	cat >zbar-qt5.pc.in <<-'_EOF'
	prefix=@prefix@
	exec_prefix=@exec_prefix@
	libdir=@libdir@
	includedir=@includedir@

	Name: zbar-qt
	Description: bar code scanning and decoding Qt5 widget
	URL: http://zbar.sourceforge.net
	Version: @VERSION@
	Requires: zbar, Qt5Core >= 5, Qt5Gui >= 5
	Libs: -L${libdir} -lzbarqt
	Cflags: -I${includedir}
	_EOF
}

post_patch() {
	# https://github.com/mchehab/zbar/commit/a133aea7880bbb56d7553
	vsed -i -e 's/^.include.*gettext[.]h.*/#include <locale.h>/' \
		zbarcam/zbarcam.c zbarimg/zbarimg.c
}

libzbar_package() {
	short_desc+=" - library files"
	pkg_install() {
		vmove "usr/lib/libzbar.so.*"
		vmove "usr/lib/libzbargtk.so.*"
		vmove "$py3_lib"
		vmove "usr/lib/girepository-1.0"
	}
}

zbar-qt_package() {
	short_desc+=" - Qt frontend"
	pkg_install() {
		vmove "usr/bin/*-qt"
	}
}


libzbar-qt_package() {
	conflicts="libzbar<0.10_10"
	short_desc+=" - Qt bindings"
	pkg_install() {
		vmove "usr/lib/libzbarqt.so.*"
	}
}

libzbar-devel_package() {
	short_desc+=" - development files"
	depends="libzbar>=${version}_${revision}"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/pkgconfig
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove "usr/share/gir-1.0"
	}
}
