SUMMARY="Photo processor for RAW and Bitmap images"
DESCRIPTION="Photivo is a free and open source (GPL3) photo processor.
It handles your RAW files as well as your bitmap files (TIFF, JPEG, BMP, PNG and many more) \
in a non-destructive 16 bit processing pipe with gimp workflow integration and batch mode.

Photivo tries to provide the best algorithms available; even if this implies some redundancy. \
So, to my knowledge, it offers the most flexible and powerful denoise, sharpen and local contrast \
(fake HDR) algorithms in the open source world. (If not, let's port them ;-)) Although, to get \
the desired results, there may be a quite steep learning curve ;-).

Photivo is just a developer, no manager and no “Gimp”. \
It is intended to be used in a workflow together with digiKam/F-Spot/Shotwell and Gimp. \
It needs a quite strong computer and is not aimed at beginners."
HOMEPAGE="http://www.photivo.org"
COPYRIGHT="2004-2007 Jeremy Ruston,
		2007-2020, UnaMesa Association"
LICENSE="GNU GPL v3"
REVISION="2"
srcGitRevision="b8210572f022"
SOURCE_URI="https://bitbucket.org/Photivo/photivo/get/$srcGitRevision.tar.bz2"
CHECKSUM_SHA256="0086c2b4f57bf58295812385edb5f9299c21266fd71c1ba8bd482da7a28e400b"
SOURCE_DIR="Photivo-photivo-$srcGitRevision"

PATCHES="photivo-$portVersion.patchset"
ADDITIONAL_FILES="
	photivo.rdef.in
	haikuicons.zip
	"

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

PROVIDES="
	photivo$secondaryArchSuffix = $portVersion
	app:Photivo$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libexiv2$secondaryArchSuffix
	lib:libexiv2_xmp$secondaryArchSuffix
	lib:libfftw3$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
	lib:libGraphicsMagick$secondaryArchSuffix
	lib:libGraphicsMagickWand$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:liblensfun$secondaryArchSuffix
	lib:liblcms2$secondaryArchSuffix
	lib:liblqr_1$secondaryArchSuffix
	lib:libpugixml$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libraw$secondaryArchSuffix
	lib:libtiff$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libexiv2$secondaryArchSuffix
	devel:libfftw3$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libGraphicsMagick$secondaryArchSuffix
	devel:libGraphicsMagickWand$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:liblensfun$secondaryArchSuffix
	devel:liblcms2$secondaryArchSuffix
	devel:liblqr_1$secondaryArchSuffix
	devel:libopencv_core$secondaryArchSuffix
	devel:libpugixml$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libraw$secondaryArchSuffix
	devel:libtiff$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"

BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:gm$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:which
	cmd:unzip
	"

PATCH()
{
	unzip -o $sourceDir/../../additional-files/haikuicons.zip -d $sourceDir/qrc/dark/icons
}

BUILD()
{
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DWITH_X3F=OFF \
		-DWITH_GIMP=OFF \
		-DCMAKE_INSTALL_PREFIX=$appsDir/Photivo

	export DISABLE_ASLR=1
	# multi-job takes too much memory
	make
}

INSTALL()
{
	cd build
	make install

	mv $appsDir/Photivo/bin/photivo $appsDir/Photivo/Photivo
	mv $appsDir/Photivo/share/photivo/* $appsDir/Photivo
	rm -rf  $appsDir/Photivo/{bin,share,pixmaps,applications}

	local APP_SIGNATURE="application/x-vnd.photivo"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/photivo.rdef.in > photivo.rdef

	addResourcesToBinaries photivo.rdef $appsDir/Photivo/Photivo

	addAppDeskbarSymlink $appsDir/Photivo/Photivo
}
