pkgname=libjpeg-turbo
pkgver=3.1.2
pkgdesc="JPEG image codec with accelerated baseline compression and decompression"
homepage="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
  yasm
)
sources=("${pkgname}-${pkgver}.tar.gz")
urls=("${_url}/releases/download/${pkgver}/${sources[0]}")
md5sums=("6f4780b95edde615c34de515f5eb617a")

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

src_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=OFF
    -D WITH_JPEG8=ON
    -G Ninja
    -W no-dev
  )
  cmake "${cmake_options[@]}"
  cmake --build build -v
}

src_check() {
  ctest --test-dir build --output-on-failure --stop-on-failure -j${PARALLEL_JOBS}
}

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

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

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

  mv -vf "${pkgdir}/usr/share/doc/${pkgname}" "${pkgdir}/usr/share/doc/${pkgname}-${pkgver}"
}

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