# Based on the Arch package
# Don't building with installed jbigkit package as we build tiff without jbigkit support

_pkgname=tkimg
pkgbase=mingw-w64-${_pkgname}
pkgname=${MINGW_PACKAGE_PREFIX}-$_pkgname
pkgver=1.4.13
pkgrel=1
pkgdesc="Adds support to Tk for many other Image formats: BMP, XBM, XPM, GIF, PNG, JPEG, TIFF and postscript (mingw-64)"
url="https://tkimg.sourceforge.io/"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('BSD')
depends=(#"${MINGW_PACKAGE_PREFIX}-jbigkit"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libtiff"
         "${MINGW_PACKAGE_PREFIX}-tk"
         "${MINGW_PACKAGE_PREFIX}-zlib")
# Uses dtplite for generating the man pages:
makedepends=("${MINGW_PACKAGE_PREFIX}-tcllib")
source=("https://downloads.sourceforge.net/tkimg/Img-${pkgver}-Source.tar.gz"
        001-compile-tif_jbig.patch
        002-dtplite_tcl.patch
        003-msys_mingw-no-need-cygpath.patch)
sha256sums=('f0868c1cad9752dcf1234f81f00c417d34a11c0f0dd499ba469df29f1c40d163'
            'b05c8996d794f7e174037a08537e6596b7a2fbadd226f8e7d6521f4f32cb4a39'
            'eb39aa5f628852b8030041c082e1ede89e2516930125572e5b1f8bc1bcbe8fca'
            '68e8b83214ec9523f2be0d144efd3364e4588e769626538d499543504835083f')

prepare() {
  cd "${srcdir}/Img-${pkgver}"
  #patch -Np1 -i "${srcdir}/001-compile-tif_jbig.patch"
  patch -Np1 -i "${srcdir}/002-dtplite_tcl.patch"
  patch -Np1 -i "${srcdir}/003-msys_mingw-no-need-cygpath.patch"

  autoreconf -fiv
}

build() {
  if check_option "debug" "y"; then
    extra_config+=( --enable-symbols )
  fi

  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"

  ../Img-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --mandir=${MINGW_PREFIX}/share/man \
    --disable-jbig \
    "${extra_config[@]}"
  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make INSTALL_ROOT="${pkgdir}" install
  rm -f ${pkgdir}/${MINGW_PREFIX}/lib/*.sh
}
