# Contributor:  Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Andrzej Giniewicz <gginiu@gmail.com>
# Contributor: Johan Förberg <johan@forberg.se>

_pkgname=zstd
pkgname=static-compat-$_pkgname
pkgver=1.5.7
pkgrel=1
pkgdesc='Zstandard - Fast real-time compression algorithm'
arch=(x86_64)
url='https://facebook.github.io/zstd/'
license=('BSD-3-Clause OR GPL-2.0-or-later')
depends=(static-compat-{zlib,xz,lz4})
makedepends=(gtest static-compat-cmake ninja)
options=(!emptydirs staticlibs)
source=(https://github.com/facebook/zstd/releases/download/v${pkgver}/zstd-${pkgver}.tar.zst{,.sig})
sha256sums=('5b331d961d6989dc21bb03397fc7a2a4d86bc65a14adc5ffbbce050354e30fd2'
            'SKIP')
b2sums=('20df0493d9d960b8fc98f7cac7630f84dae6226bd906364ab9c9ce7dfb2be44a303fd077e4264979f3ee92efd59072d63c4bb4ae7b65c52f6ce0153513088837'
        'SKIP')
validpgpkeys=(4EF4AC63455FC9F4545D9B7DEF8FE99528B52FFD)

build() {
  source static-compat-environment
  static-compat-cmake -S ${_pkgname}-${pkgver}/build/cmake -B build -G Ninja \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DZSTD_BUILD_CONTRIB=ON \
    -DZSTD_BUILD_TESTS=ON \
    -DZSTD_BUILD_SHARED=OFF \
    -DZSTD_BUILD_STATIC=ON
  cmake --build build
}

check() {
  cd build/tests
  ctest
}

package() {
  source static-compat-environment
  DESTDIR="${pkgdir}" cmake --install build
  install -Dm 644 ${_pkgname}-${pkgver}/LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  rm -r "$pkgdir/$static_compat_prefix"/{bin,share/man}
}
