SUMMARY="JPEG XL reference encoder/decoder"
DESCRIPTION="The JPEG XL Image Coding System (ISO/IEC 18181) has a rich \
feature set and is particularly optimised for responsive web environments, so \
that content renders well on a wide range of devices. Moreover, it includes \
several features that help transition from the legacy JPEG format."
HOMEPAGE="https://jpeg.org/jpegxl/"
COPYRIGHT="2021 the JPEG XL Project
	2005-2021 Lode Vandevenne
	2018-2021 Google Inc.
	2021 Google LLC"
LICENSE="BSD (3-clause)
	Apache v2
	MIT
	Zlib"
REVISION="1"
SOURCE_URI="https://gitlab.com/wg1/jpeg-xl/-/archive/v$portVersion/jpeg-xl-v$portVersion.tar.bz2"
CHECKSUM_SHA256="2eccd29d3454fc3f4612185d9f90546b20e3cfedc8420447f6effc5ff6aae25b"
srcGitRev_2="48e5364ef48ec2408f44c727657ac1b6703185f8"
SOURCE_URI_2="https://github.com/lvandeve/lodepng/archive/$srcGitRev_2.tar.gz"
CHECKSUM_SHA256_2="c47c48c77a205f1af484b7b5a847290af65de3ea6f15817aa27c5ec7cc5208fd"
SOURCE_FILENAME_2="lodepng-$srcGitRev_2.tar.gz"
srcGitRev_3="64374756e03700d649f897dbd98c95e78c30c7da"
SOURCE_URI_3="https://github.com/workerVA/skcms/archive/$srcGitRev_3.tar.gz"
CHECKSUM_SHA256_3="d28ff68c49a4946b29d76d03d75414895f4dd897ca42be6d304ec24b9f539fe1"
SOURCE_FILENAME_3="ckcms-$srcGitRev_3.tar.gz"
srcGitRev_4="868ab558fad70fcbe8863ba4e85179eeb81cc840"
SOURCE_URI_4="https://github.com/webmproject/sjpeg/archive/$srcGitRev_4.tar.gz"
CHECKSUM_SHA256_4="72279cd6d4089b62a49cb127353bf875cb35844eda42d90901dd32f08992060e"
SOURCE_FILENAME_4="sjpeg-$srcGitRev_4.tar.gz"
SOURCE_DIR="jpeg-xl-v$portVersion"

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

PROVIDES="
	libjxl$secondaryArchSuffix = $portVersion
	lib:libjxl$secondaryArchSuffix = $portVersion
	lib:libjxl_dec$secondaryArchSuffix = $portVersion
	lib:libjxl_threads$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libavif$secondaryArchSuffix
	lib:libbrotlicommon$secondaryArchSuffix
	lib:libbrotlidec$secondaryArchSuffix
	lib:libbrotlienc$secondaryArchSuffix
	lib:libgif$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libIex_3_0$secondaryArchSuffix
	lib:libIlmThread_3_0$secondaryArchSuffix
	lib:libImath_3_0$secondaryArchSuffix
	lib:libOpenEXR_3_0$secondaryArchSuffix
	lib:libOpenEXRUtil_3_0$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	lib:libwebp$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	libjxl${secondaryArchSuffix}_devel = $portVersion
	devel:libjxl$secondaryArchSuffix = $portVersion
	devel:libjxl_dec$secondaryArchSuffix = $portVersion
	devel:libjxl_threads$secondaryArchSuffix = $portVersion
	"
REQUIRES_devel="
	libjxl$secondaryArchSuffix == $portVersion base
	"

PROVIDES_tools="
	libjxl${secondaryArchSuffix}_tools = $portVersion
	cmd:benchmark_xl$secondaryArchSuffix
	cmd:cjxl$secondaryArchSuffix
	cmd:djxl$secondaryArchSuffix
	"
REQUIRES_tools="
	$REQUIRES
	libjxl$secondaryArchSuffix == $portVersion base
	lib:libstdc++$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libavif$secondaryArchSuffix
	devel:libbrotlicommon$secondaryArchSuffix
	devel:libbrotlidec$secondaryArchSuffix
	devel:libbrotlienc$secondaryArchSuffix
	devel:libgif$secondaryArchSuffix >= 7
	devel:libGL$secondaryArchSuffix
	devel:libhwy$secondaryArchSuffix
	devel:libhwy_contrib$secondaryArchSuffix
	devel:libIex_3_0$secondaryArchSuffix
	devel:libIlmThread_3_0$secondaryArchSuffix
	devel:libImath_3_0$secondaryArchSuffix
	devel:libOpenEXR_3_0$secondaryArchSuffix
	devel:libOpenEXRUtil_3_0$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libwebp$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:git
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
	"

BUILD()
{
	cp -r $sourceDir2/lodepng-$srcGitRev_2/* third_party/lodepng
	cp -r $sourceDir3/skcms-$srcGitRev_3/* third_party/skcms
	cp -r $sourceDir4/sjpeg-$srcGitRev_4/* third_party/sjpeg
	cmake -B build -S . $cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_TESTING=OFF \
		-DJPEGXL_FORCE_SYSTEM_BROTLI=true \
		-DJPEGXL_FORCE_SYSTEM_HWY=true \
		-DJPEGXL_WARNINGS_AS_ERRORS=false \
		-DJPEGXL_ENABLE_OPENEXR=true
	make -C build $jobArgs
}

INSTALL()
{
	make -C build install

	prepareInstalledDevelLibs \
		libjxl libjxl_dec libjxl_threads
	fixPkgconfig

	packageEntries devel \
		$developDir
	packageEntries tools \
		$binDir
}

TEST()
{
	make -C build test
}
