# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=libheif
pkgver=1.18.2
pkgrel=0
pkgdesc="ISO/IEC 23008-12:2017 HEIF file format decoder and encoder"
url="https://www.libde265.org/"
arch="all"
license="LGPL-3.0-or-later"
depends_dev="
	libde265-dev
	x265-dev
	"
makedepends="
	$depends_dev
	aom-dev
	cmake
	libjpeg-turbo-dev
	libpng-dev
	gdk-pixbuf-dev
	samurai
	"
options="!check"  # no tests provided
subpackages="
	$pkgname-dev
	heif-thumbnailer
	$pkgname-tools
	$pkgname-doc
	$pkgname-pixbuf-loader
	"
source="https://github.com/strukturag/libheif/releases/download/v$pkgver/libheif-$pkgver.tar.gz"

# secfixes:
#   1.17.6-r0:
#     - CVE-2023-49462
#     - CVE-2023-49463
#   1.5.0-r0:
#     - CVE-2019-11471

build() {
	# This is en/decoder, so performance matters more than size.
	export CPPFLAGS="${CFLAGS/-Os/-O2}"
	export CXXFLAGS="${CFLAGS/-Os/-O2} -flto=auto"

	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_SKIP_INSTALL_RPATH=ON
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

thumbnailer() {
	pkgdesc="$pkgdesc (thumbnailer)"

	amove usr/bin/heif-thumbnailer
}

tools() {
	pkgdesc="$pkgdesc (tools)"
	depends="heif-thumbnailer=$pkgver-r$pkgrel"

	amove usr/bin
}

loader() {
	pkgdesc="$pkgdesc (pixbuf loader)"
	depends="heif-thumbnailer=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel gdk-pixbuf-loaders"

	amove \
		usr/lib/gdk-pixbuf-*/*/loaders \
		usr/share/thumbnailers
}

sha512sums="
8fd47dbc8e31fdb6a972c852bc4e78440492ee3dd769e139f28ad489ccc23e6cf42a90cd23b16405fa30df3c7c43c78b2b65d5ca3ffb449bf06789b457ed3072  libheif-1.18.2.tar.gz
"
