pkgname=pillow
pkgver=12.1.0
pkgrel=2
pkgdesc='Python Imaging Library (PIL) fork'
arch=(x86_64)
homepage='https://pillow.readthedocs.io'
license=(MIT-CMU)
depends=(
  glibc
  python
  python-packaging
  libtiff
  libjpeg-turbo
  zlib
)
makedepends=(
  pybind11
  python-build
  python-installer
  python-wheel
  python-setuptools
  libwebp
)
sources=("${pkgname}-${pkgver}.tar.gz")
urls=("https://github.com/python-pillow/Pillow/archive/${pkgver}.tar.gz")
md5sums=("acf2299072e42bb6ea186967bffdcd3e")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
}

src_build() {
  cat >> setup.cfg <<EOF
  [build_ext]
  debug = True
  disable_platform_guessing = True
  disable_avif = True
  disable_freetype = True
  enable_jpeg = True
  disable_jpeg2000 = True
  disable_lcms = True
  enable_tiff = True
  disable_imagequant = True
  enable_webp = True
  disable_xcb = True
  enable_zlib = True
EOF
  python -m build --wheel --no-isolation
}

src_install() {
  python -m installer --destdir="$pkgdir" dist/*.whl

  local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
  install -vDm644 -t "$pkgdir/usr/include/python$python_version" src/libImaging/*.h

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}

# vim:ft=sh syn=sh et sw=2:
