# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgname=libjpeg-turbo
pkgver=%version%
pkgrel=%release%
pkgdesc="JPEG image codec with accelerated baseline compression and decompression"
url="https://libjpeg-turbo.org/"
_url="https://github.com/libjpeg-turbo/libjpeg-turbo/"
arch=(x86_64)
license=(
  BSD-3-Clause
  IJG
)
depends=(glibc)
makedepends=(
  cmake
  ninja
  nasm
  'java-environment>11'
)
optdepends=('java-runtime>11: for TurboJPEG Java wrapper')
provides=(
  libjpeg
  libjpeg.so
  libturbojpeg.so
)
source=(
  $_url/releases/download/$pkgver/$pkgname-$pkgver.tar.gz{,.sig}
)
sha512sums=('f5eadda0712feb810a8c3bb2621fda24a4c30574998ce30f423b3ffa25225c7a87cb14b696232bc0270485f422a2853a5c32eafb65bc5eeab1b41d8aeb32ad29'
            'SKIP')
b2sums=('b6eff81657707852ee9ea81099179c6e20914f513fd32b12b1bfbf5233f850f54a1062a98150044aa34476f0c54e42a67c88633a59834a764d3f8bb394f374f0'
        'SKIP')
validpgpkeys=('0338C8D8D9FDA62CF9C421BD7EC2DBB6F4DBF434') # The libjpeg-turbo Project (Signing key for official binaries) <information@libjpeg-turbo.org>

build() {
  local cmake_options=(
    -B build
    -D CMAKE_INSTALL_PREFIX=/usr
    -D CMAKE_INSTALL_LIBDIR=/usr/lib
    -D CMAKE_BUILD_TYPE=None
    -D ENABLE_STATIC=OFF
    -D WITH_JAVA=ON
    -D WITH_JPEG8=ON
    -G Ninja
    -S $pkgname-$pkgver
    -W no-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build -v
}

check() {
  ctest --test-dir build --output-on-failure --stop-on-failure -j$(nproc)
}

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

  # header required by some dependents
  # https://bugs.archlinux.org/task/24787
  install -vDm 644 $pkgname-$pkgver/jpegint.h "$pkgdir/usr/include"

  install -vDm 644 $pkgname-$pkgver/LICENSE.md -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/README.ijg -t "$pkgdir/usr/share/licenses/$pkgname/"
}
