# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Andrew Sun <adsun701@gmail.com>

_realname=optipng
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.7.7
pkgrel=1
pkgdesc="Compresses PNG files to a smaller size, without losing any information (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://optipng.sourceforge.io/"
license=("ZLIB")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('strip' 'staticlibs')
source=("https://downloads.sourceforge.net/sourceforge/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('4f32f233cef870b3f95d3ad6428bfe4224ef34908f1b42b0badf858216654452')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  cp -R "${srcdir}"/${_realname}-${pkgver}/* "${srcdir}"/build-${CARCH}
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --with-system-libpng \
    --with-system-zlib

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make prefix="${pkgdir}${MINGW_PREFIX}" mandir="${pkgdir}${MINGW_PREFIX}/share/man" install

  # Install license
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE.txt" ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
