SUMMARY="Implementation of the codec specified in the JPEG-2000 Part-1 standard"
DESCRIPTION="The JasPer Project is an open-source initiative to provide a \
free software-based reference implementation of the codec specified in the \
JPEG-2000 Part-1 standard. More details about this software can be found in \
the JasPer Software Reference Manual."
HOMEPAGE="http://www.ece.uvic.ca/~frodo/jasper/"
COPYRIGHT="1999-2007 Michael D. Adams"
LICENSE="JasPer v2"
REVISION="4"
SOURCE_URI="https://github.com/mdadams/jasper/archive/version-$portVersion.tar.gz"
CHECKSUM_SHA256="f1d8b90f231184d99968f361884e2054a1714fdbbd9944ba1ae4ebdcc9bbfdb1"
SOURCE_DIR="jasper-version-$portVersion"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	jasper$secondaryArchSuffix = $portVersion
	lib:libjasper$secondaryArchSuffix = 4.0.0 compat >= 4
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	"

PROVIDES_devel="
	jasper${secondaryArchSuffix}_devel = $portVersion
	devel:libjasper$secondaryArchSuffix = 4.0.0 compat >= 4
	"
REQUIRES_devel="
	jasper$secondaryArchSuffix == $portVersion base
	"

if [ -z "$secondaryArchSuffix" ]; then
	SUMMARY_tools="The jasper tools"
	PROVIDES_tools="
		jasper${secondaryArchSuffix}_tools = $portVersion
		cmd:imgcmp$secondaryArchSuffix = $portVersion
		cmd:imginfo$secondaryArchSuffix = $portVersion
		cmd:jasper$secondaryArchSuffix = $portVersion
		cmd:jiv$secondaryArchSuffix = $portVersion
		"
	REQUIRES_tools="
		jasper$secondaryArchSuffix == $portVersion base
		haiku$secondaryArchSuffix
		lib:libGL$secondaryArchSuffix
		lib:libglu$secondaryArchSuffix
		lib:libjpeg$secondaryArchSuffix
		"
fi

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build-jasper && cd build-jasper
	cmake .. $cmakeDirArgs \
		-DJAS_ENABLE_AUTOMATIC_DEPENDENCIES=OFF \
    		-DCMAKE_SKIP_RPATH=ON \
    		-DJAS_ENABLE_OPENGL=ON
	make
}

INSTALL()
{
	cd build-jasper
	make install

	prepareInstalledDevelLibs libjasper
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir

	# tools package
	if [ -z "$secondaryArchSuffix" ]; then
		packageEntries tools \
			$binDir \
			$documentationDir
	fi

	# Remove stuff we don't need in the secondary architecture base package.
	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf $prefix/bin
		rm -rf $documentationDir
	fi
}
