SUMMARY="MMX, SSE, and SSE2 SIMD accelerated JPEG library"
DESCRIPTION="libjpeg-turbo is a JPEG image codec that uses SIMD instructions \
(MMX, SSE2, AVX2, NEON, AltiVec) to accelerate baseline JPEG compression and \
decompression on x86, x86-64, ARM, and PowerPC systems. On such systems, \
libjpeg-turbo is generally 2-6x as fast as libjpeg, all else being equal. On \
other types of systems, libjpeg-turbo can still outperform libjpeg by a \
significant amount, by virtue of its highly-optimized Huffman coding routines.
In many cases, the performance of libjpeg-turbo rivals that of proprietary \
high-speed JPEG codecs.
libjpeg-turbo implements both the traditional libjpeg API as well as the less \
powerful but more straightforward TurboJPEG API. libjpeg-turbo also features \
colorspace extensions that allow it to compress from/decompress to 32-bit and \
big-endian pixel buffers (RGBX, XBGR, etc.), as well as a full-featured Java \
interface.
libjpeg-turbo was originally based on libjpeg/SIMD, an MMX-accelerated \
derivative of libjpeg v6b developed by Miyasaka Masaru. The TigerVNC and \
VirtualGL projects made numerous enhancements to the codec in 2009, and in \
early 2010, libjpeg-turbo spun off into an independent project, with the goal \
of making high-speed JPEG compression/decompression technology available to \
a broader range of users and developers."
HOMEPAGE="https://www.libjpeg-turbo.org/"
COPYRIGHT="1991-2019 Thomas G. Lane, Guido Vollbeding
	1997-2010 Guido Vollbeding
	2000-2017 D. R. Commander
	2009 Bill Allombert
	1999-2006 MIYASAKA Masaru
	2011 Siarhei Siamashka
	2013 Linaro Limited
	2014 MIPS Technologies, Inc.
	2015 Google, Inc.
	2015 Matthieu Darbois"
LICENSE="BSD (3-clause)
	IJG
	Zlib"
REVISION="1"
SOURCE_URI="https://downloads.sourceforge.net/libjpeg-turbo/libjpeg-turbo-$portVersion.tar.gz"
CHECKSUM_SHA256="09b96cb8cbff9ea556a9c2d173485fd19488844d55276ed4f42240e1e2073ce5"
SOURCE_DIR="libjpeg-turbo-$portVersion"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

libjpegVersion="62.3.0"
libjpegVersionCompat="$libjpegVersion compat >= ${libjpegVersion%%.*}"
libturbojpegVersion="0.2.0"
libturbojpegVersionCompat="$libturbojpegVersion compat >= ${libturbojpegVersion%%.*}"

PROVIDES="
	libjpeg_turbo$secondaryArchSuffix = $portVersion
	lib:libjpeg$secondaryArchSuffix = $libjpegVersionCompat
	lib:libturbojpeg$secondaryArchSuffix = $libturbojpegVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	libjpeg_turbo${secondaryArchSuffix}_devel = $portVersion
	devel:libjpeg$secondaryArchSuffix = $libjpegVersionCompat
	devel:libturbojpeg$secondaryArchSuffix = $libturbojpegVersionCompat
	"
REQUIRES_devel="
	libjpeg_turbo$secondaryArchSuffix == $portVersion base
	"
CONFLICTS_devel="
	jpeg${secondaryArchSuffix}_devel
	"

PROVIDES_tools="
	libjpeg_turbo${secondaryArchSuffix}_tools = $portVersion
	cmd:cjpeg$secondaryArchSuffix = $portVersion
	cmd:djpeg$secondaryArchSuffix = $portVersion
	cmd:jpegtran$secondaryArchSuffix = $portVersion
	cmd:rdjpgcom$secondaryArchSuffix = $portVersion
	cmd:tjbench$secondaryArchSuffix = $portVersion
	cmd:wrjpgcom$secondaryArchSuffix = $portVersion
	"
REQUIRES_tools="
	haiku$secondaryArchSuffix
	libjpeg_turbo$secondaryArchSuffix == $portVersion base
	"
CONFLICTS_tools="
	jpeg${secondaryArchSuffix}_tools
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:nasm
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage libjpeg_turbo$secondaryArchSuffix \
	$libDir/libjpeg.so.$libjpegVersion \
	$libDir/libturbojpeg.so.$libturbojpegVersion

BUILD()
{
	cmake -S. -Bbuild \
		$cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo
	make -C build $jobArgs
}

INSTALL()
{
	make -C build install

	prepareInstalledDevelLibs libjpeg libturbojpeg
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir \
		$libDir/cmake

	# tools package
	packageEntries tools \
		$binDir \
		$documentationDir
}

TEST()
{
	make -C build test
}
