# Maintainer: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=libdeflate
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7
pkgrel=3
pkgdesc="Heavily optimized library for DEFLATE/zlib/gzip compression and decompression (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/ebiggers/libdeflate'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/ebiggers/libdeflate/archive/v${pkgver}.tar.gz"
        "001-libdeflate-makefile-mingw-fix.patch")
sha256sums=('a5e6a0a9ab69f40f0f59332106532ca76918977a974e7004977a9498e3f11350'
            '0c6104d036417f12b969fd36b821cca11da29b61a26caa179cfdfe39fb4b57c8')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-libdeflate-makefile-mingw-fix.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -a "${srcdir}"/${_realname}-${pkgver} "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  make PREFIX=${MINGW_PREFIX}
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install PREFIX=${MINGW_PREFIX} DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
