# Maintainer: Nicolas Frattaroli <ovdev@fratti.ch>

_realname=pngcrush
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.8.13
pkgrel=2
pkgdesc="A tool for optimizing the compression of PNG files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://pmt.sourceforge.io/pngcrush"
msys2_references=(
  "cpe: cpe:/a:pngcrush_project:pngcrush"
)
license=('custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs" "${MINGW_PACKAGE_PREFIX}-libpng" "${MINGW_PACKAGE_PREFIX}-zlib")
source=("https://downloads.sourceforge.net/pmt/${_realname}-${pkgver}-nolib.tar.gz"
        LICENSE)
sha256sums=('fed0aaf5c098aa8c7f78c75365cd18d7341417326ecbdba547876b7b4f3df4be'
            '5628338f1b1c711b2b2e82d14124bc3001b37216a66f00b18d0b3b9c7e016720')

prepare() {
  mv "${srcdir}/${_realname}-${pkgver}-nolib" "${srcdir}/${_realname}-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/${_realname}-build-${MSYSTEM}"
  CFLAGS+=" -DPNGCRUSH_COUNT_COLORS" make CC="$CC" LD="$CC"
}

package() {
  install -Dm755 "${srcdir}"/${_realname}-build-${MSYSTEM}/${_realname} \
    "${pkgdir}"${MINGW_PREFIX}/bin/${_realname}
  install -Dm644 LICENSE \
    "$pkgdir"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
