# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=libjpeg-turbo
pkgver=3.0.3
pkgrel=1
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'
  strip-nondeterminism
)
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=('7c3a6660e7a54527eaa40929f5cc3d519842ffb7e961c32630ae7232b71ecaa19e89dbf5600c61038f0c5db289b607c2316fe9b6b03d482d770bcac29288d129'
            'SKIP')
b2sums=('9d141dadd0dce970bf857b51352c57a8e15180438abd7d6d66f9dfd24e23889add8c6c89120b84026e40ab61611516b0567984bd1db37e9c45b41917cf32e9a6'
        'SKIP')

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

  # cmake creates non-reproducible jars: https://github.com/libjpeg-turbo/libjpeg-turbo/issues/745
  strip-nondeterminism --timestamp "$SOURCE_DATE_EPOCH" build/java/turbojpeg.jar
}

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/"
}
