# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=pngquant
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.13.1
pkgrel=1
pkgdesc="Command-line utility to quantize PNGs down to 8-bit paletted PNGs (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://pngquant.org/'
license=("BSD")
depends=("${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-lcms2"
         "${MINGW_PACKAGE_PREFIX}-libimagequant")
source=("https://github.com/kornelski/${_realname}/archive/$pkgver/${_realname}-${pkgver}.tar.gz")
sha256sums=('2d462ca5739ac0afe5a6851914a48ff9d06d4fbd3c4883e8308de5dcc6d444bc')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
#  patch -p1 -i ${srcdir}/0001-min-build-fix.patch
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  rm -rf "${srcdir}"/build-${CARCH} || true
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${CARCH}"
  cd "${srcdir}"/build-${CARCH}
  msg2 "PWD $(pwd)"
  if [ "${CARCH}" = "i686" ]; then
    SSE="--disable-sse"
  else
    SSE="--enable-sse"
  fi
  ./configure --prefix=${MINGW_PREFIX} \
    CC="${MINGW_PREFIX}/bin/gcc" \
    --with-libimagequant=${MINGW_PREFIX}/lib/ \
    ${SSE}
  make --jobs=1
}

package() {
  cd "${srcdir}"/build-${CARCH}

  install -dm 0755 ${pkgdir}${MINGW_PREFIX}/bin
  install -dm 0755 ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}
  install -dm 0755 ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  install -m 0644 -p pngquant.exe \
     ${pkgdir}${MINGW_PREFIX}/bin/pngquant.exe
   install -m 0644 -p CHANGELOG \
      ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/CHANGELOG
   install -m 0644 -p README.md \
      ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md
   install -m 0644 -p COPYRIGHT \
       ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT
}

