# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Adam Fontenot <fontenot@ucla.edu>

pkgname=libheif
pkgver=1.19.5
pkgrel=2
pkgdesc='An HEIF and AVIF file format decoder and encoder'
arch=(x86_64 aarch64)
url='https://github.com/strukturag/libheif'
license=(GPL3)
provides=('libheif.so')
makedepends=(cmake
             dav1d
             ffmpeg
             gdk-pixbuf2
             git
             libjpeg-turbo
             libpng
             rav1e
             svt-av1)
depends=(aom
         gcc-libs
         glibc
         libde265
         libwebp
         x265)
optdepends=('libjpeg-turbo: for heif-convert and heif-enc'
            'libpng: for heif-convert and heif-enc'
            'dav1d: dav1d encoder'
            'ffmpeg: hardware decode'
            'rav1e: rav1e encoder'
            'svt-av1: svt-av1 encoder')
source=(git+https://github.com/strukturag/libheif#tag=v$pkgver
        fix-build-with-svt-av1.patch)
sha256sums=('321c30e21eb2c28748df227b852916656b6bb9786e7c4cb4cfc6df29dfa73c0d'
            'e5f7eaee94aebeef387e10be6d515d2ba25b250fb15829d160a0c1a3cebe5e24')

prepare() {
  cd $pkgname
  # Fix for svt-av1 3.0
  # https://github.com/strukturag/libheif/commit/4bc4cfb66055a997f03d57649bf5456fe09a5a97
  patch -Np1 < ../fix-build-with-svt-av1.patch
}

build() {
  cmake -B build -S $pkgname \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DWITH_DAV1D=ON \
    -DWITH_RAV1E=ON \
    -DWITH_FFMPEG_DECODER=ON \
    -DWITH_FFMPEG_DECODER_PLUGIN=ON \
    -DWITH_SvtEnc=ON
  cmake --build build
}

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