SUMMARY="A image processing and analysis library"
DESCRIPTION="VIGRA stands for \"Vision with Generic Algorithms\". It's an \
image processing and analysis library that puts its main emphasis on \
customizable algorithms and data structures. VIGRA is especially strong for \
multi-dimensional images, because many algorithms (e.g. filters, feature \
computation, superpixels) are implemented for arbitrary high dimensions. \
By using template techniques similar to those in the C++ Standard Template \
Library, you can easily adapt any VIGRA component to the needs of your \
application, without thereby giving up execution speed."
HOMEPAGE="http://ukoethe.github.io/vigra/"
COPYRIGHT="1998-2017 by Ullrich Koethe"
LICENSE="MIT"
REVISION="2"
SOURCE_URI="https://github.com/ukoethe/vigra/archive/Version-${portVersion//./-}.tar.gz"
CHECKSUM_SHA256="b2718250d28baf1932fcbe8e30f7e4d146e751ad0e726e375a72a0cdb4e3250e"
SOURCE_FILENAME="vigra-$portVersion.tar.gz"
SOURCE_DIR="vigra-Version-${portVersion//./-}"

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

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

PROVIDES="
	vigra$secondaryArchSuffix = $portVersion
	lib:libvigraimpex$secondaryArchSuffix = 11.1.11.1 compat >= 11
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libfftw3$secondaryArchSuffix
	lib:libhalf$secondaryArchSuffix
	lib:libiex_2_2$secondaryArchSuffix
	lib:libilmimf_2_2$secondaryArchSuffix
	lib:libilmthread_2_2$secondaryArchSuffix
	lib:libimath_2_2$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libtiff$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	vigra${secondaryArchSuffix}_devel = $portVersion
	cmd:vigra_config$commandSuffix
	devel:libvigraimpex$secondaryArchSuffix = 11.1.11.1 compat >= 11
	"
REQUIRES_devel="
	vigra$secondaryArchSuffix == $portVersion base
	cmd:python # vigra-config is python script
	"

BUILD_REQUIRES="
	devel:libfftw3$secondaryArchSuffix
	devel:libhalf$secondaryArchSuffix
	devel:libiex$secondaryArchSuffix
	devel:libilmimf$secondaryArchSuffix
	devel:libimath$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libtiff$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	"

PATCH()
{
	sed -i 's,\/lib,/'${relativeLibDir}',g' \
		config/vigra-config.in
}

BUILD()
{
	mkdir -p build
	cd build
	cmake -DCMAKE_INSTALL_PREFIX=$prefix -DWITH_HDF5=0 -DWITH_VIGRANUMPY=0 \
		-DWITH_OPENEXR=1 ../
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	# we did not generate documentation
	rm -rf $prefix/doc

	# move headers
	mkdir -p $includeDir
	mv $prefix/include/* $includeDir

	rm -rf $prefix/include

	# move libs for secondaryArchSuffix
	if [ "$targetArchitecture" = x86_gcc2 ]; then
	mv $prefix/lib $prefix/lib2
	mkdir $(dirname $libDir)
	mv $prefix/lib2 $libDir
	fi

	#rm -rf $prefix/lib

	prepareInstalledDevelLib libvigraimpex

	fixDevelopLibDirReferences $prefix/bin/vigra-config
	sed -i 's,\/include,/'${relativeIncludeDir}',g' \
		$commandBinDir/vigra-config

	# move CMake scripts...
	# FIXME: ...which probably won't work
	mv $libDir/vigra $developLibDir
	sed -i 's,\/include,/'${relativeIncludeDir}',g' \
		$developLibDir/vigra/VigraConfig.cmake

	packageEntries devel \
		$developDir \
		$commandBinDir/vigra-config
}

TEST()
{
	# FIXME: these tests fail, probably due to wrong paths
	cd build
	make test
}
