# Maintainer: Tobias Powalowski <tpowa@archlinux.org>

pkgname=openexr
pkgver=3.4.7
pkgrel=2
pkgdesc='A high dynamic-range image file format library'
url='https://www.openexr.com/'
arch=(x86_64 aarch64)
license=(BSD-3-Clause)
depends=(glibc
         imath
         libdeflate
         libgcc
         libstdc++
         openjph)
makedepends=(cmake
             git
             pybind11)
optdepends=('python: for python bindings')
source=(git+https://github.com/openexr/openexr#tag=v$pkgver
        python-install-dir.patch)
sha256sums=('dc00a8533bc1eef692f8b855688e25a4c30e604db357aec6f6092e4987c60a34'
            'ea2909df520d08aae5d40bf12db9112ae153a602885fa892818a0e806adc59da')

prepare() {
# unpin scikit-build-core version
  sed 's|scikit-build-core[^"]*|scikit-build-core|' -i openexr/pyproject.toml
# Fix python module install dir
  patch -d $pkgname -p1 < python-install-dir.patch
}

build() {
  cmake -B build -S $pkgname \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -DOPENEXR_BUILD_PYTHON=ON
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -Dm644 $pkgname/LICENSE.md -t "$pkgdir"/usr/share/licenses/$pkgname

  python -m compileall "$pkgdir"/usr/lib/python*
  python -Om compileall "$pkgdir"/usr/lib/python*
}
