# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lz4
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.9.3
pkgrel=1
pkgdesc="Very fast lossless compression algorithm (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://lz4.github.io/lz4/"
license=('BSD' 'GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
checkdepends=('diffutils')
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/lz4/lz4/archive/v${pkgver}.tar.gz")
sha256sums=('030644df4611007ff7dc962d981f390361e6c97a34e5cbc393ddfbe019ffe2c1')

build() {

  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 CC=${MINGW_PREFIX}/bin/gcc
}

check() {
  cd ${srcdir}
  msg2 "rm -f profile.lz4"
  rm -f profile.lz4 || true

  ${srcdir}/build-${MINGW_CHOST}/programs/lz4 /etc/profile profile.lz4
  ${srcdir}/build-${MINGW_CHOST}/programs/lz4 -d profile.lz4 profile
  diff -q /etc/profile profile

  rm profile

#  cd "${srcdir}/build-${MINGW_CHOST}"
#  make test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make CC=${MINGW_PREFIX}/bin/gcc DESTDIR="${pkgdir}" PREFIX=${MINGW_PREFIX} install
}
