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

_realname=pngquant
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.17.0
pkgrel=3
pkgdesc="Command-line utility to quantize PNGs down to 8-bit paletted PNGs (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://pngquant.org/'
msys2_references=(
  "cpe: cpe:/a:pngquant:pngquant"
)
license=("spdx:GPL-3.0-or-later")
depends=("${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-lcms2"
         "${MINGW_PACKAGE_PREFIX}-libimagequant")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/kornelski/${_realname}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('bc1baa43c814b4416bb63d7b2168d4e5395cfc69a00f8997a595361caa507887')

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

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

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

  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
}

