SUMMARY="Qt-based image viewer"
DESCRIPTION="nomacs is a free, open source image viewer, which supports \
multiple platforms. You can use it for viewing all common image formats \
including RAW and psd images."
HOMEPAGE="https://nomacs.org/"
COPYRIGHT="2011-2020 Markus Diem
	2011-2020 Stefan Fiel
	2011-2020 Florian Kleber"
LICENSE="GNU LGPL v3"
REVISION="2"
SOURCE_URI="https://github.com/nomacs/nomacs/archive/$portVersion.224.tar.gz"
CHECKSUM_SHA256="bbc7e9048026ef9e0d2b64902c88050f17a679ef3d3c009de2c3b7de5d1d217c"
SOURCE_FILENAME="nomacs-$portVersion.tar.gz"
SOURCE_DIR="nomacs-$portVersion.224"
SOURCE_URI_2="https://github.com/nomacs/nomacs-plugins/archive/$portVersion.tar.gz"
CHECKSUM_SHA256_2="ab6a91c582d48f4a4697d80ce549886921888cfbb32ea8b8c3b172fb7139225a"
SOURCE_FILENAME_2="nomacs-plugins-$portVersion.tar.gz"
SOURCE_DIR_2="nomacs-plugins-$portVersion"
PATCHES="nomacs-$portVersion.patchset"
ADDITIONAL_FILES="
	nomacs.rdef.in
	haikuicons.zip
	"

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

PROVIDES="
	nomacs$secondaryArchSuffix = $portVersion
	app:Nomacs$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libexiv2$secondaryArchSuffix
	lib:libexpat$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:liblcms2$secondaryArchSuffix
	lib:libopencv_core$secondaryArchSuffix
	lib:libopencv_imgproc$secondaryArchSuffix
	lib:libQt5Concurrent$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libquazip5$secondaryArchSuffix
	lib:libraw$secondaryArchSuffix
	lib:libtiff$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libexiv2$secondaryArchSuffix
	devel:libexpat$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:liblcms2$secondaryArchSuffix
	devel:libopencv_core$secondaryArchSuffix
	devel:libopencv_imgproc$secondaryArchSuffix
	devel:libQt5Concurrent$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libquazip5$secondaryArchSuffix
	devel:libraw$secondaryArchSuffix >= 19
	devel:libtiff$secondaryArchSuffix >= 5
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:lcov
	cmd:lrelease$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python2
	cmd:unzip
	"

PATCH()
{
	unzip -o $sourceDir/../../additional-files/haikuicons.zip -d $sourceDir/ImageLounge/src/img
	sed -e '/font-size:/d' -i $sourceDir/ImageLounge/src/stylesheet.css
}

BUILD()
{
	cd ImageLounge
	mkdir -p plugins
	cp -r $sourceDir2/* plugins

	mkdir -p build
	cd build

	cmake .. \
		-DUSE_SYSTEM_QUAZIP=ON \
		-DENABLE_TRANSLATIONS=ON \
		$cmakeDirArgs

	make $jobArgs
}

INSTALL()
{
	cd ImageLounge/build
	make install

	local APP_SIGNATURE="application/x-vnd.nomacs"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
#	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local MINOR="0"
	local INTERNAL="0"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@INTERNAL@|$INTERNAL|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/nomacs.rdef.in > nomacs.rdef

	mkdir -p $appsDir/Nomacs $manDir
	mv $prefix/bin/nomacs $appsDir/Nomacs/Nomacs
	mv $prefix/lib $appsDir/Nomacs
	mv $appsDir/Nomacs/lib/nomacs-plugins $appsDir/Nomacs/plugins
	mv $prefix/share/man/man1 $manDir
	mv "$prefix/share/nomacs/Image Lounge/translations" $appsDir/Nomacs
	rm -rf $prefix/bin $prefix/share

	addResourcesToBinaries nomacs.rdef $appsDir/Nomacs/Nomacs
	addAppDeskbarSymlink $appsDir/Nomacs/Nomacs
}
