# 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.5
pkgrel=1
pkgdesc='Zstandard - Fast real-time compression algorithm'
arch=(x86_64)
url='https://facebook.github.io/zstd/'
license=(BSD GPL2)
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=('ce264bca60eb2f0e99e4508cffd0d4d19dd362e84244d7fc941e79fa69ccf673'
            'SKIP')
b2sums=('2c2dc95f227e661ada23d8f6141bcd293505ce14e605f946ae00d4d4ac37d10b4eb08279ef7560618c67caf266431f76686fda5ae1921d698a6a93bbaf9a0052'
        '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}
}
