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

_realname=djview
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.10.6
pkgrel=1
pkgdesc='Portable DjVu viewer (mingw-w64)'
url='http://djvu.sourceforge.net/djview4.html'
license=('GPL')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
depends=("${MINGW_PACKAGE_PREFIX}-djvulibre"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-qt5" 
         "${MINGW_PACKAGE_PREFIX}-libtiff")
source=("https://downloads.sourceforge.net/djvu/${_realname}-${pkgver}.tar.gz")
sha256sums=('8446f3cd692238421a342f12baa365528445637bffb96899f319fe762fda7c21')
conflicts=("${MINGW_PACKAGE_PREFIX}-djview4")
provides=("${MINGW_PACKAGE_PREFIX}-djview4")
replaces=("${MINGW_PACKAGE_PREFIX}-djview4")

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  export QMAKE=${MINGW_PREFIX}/bin/qmake.exe
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  cp src/release/djview.exe "${pkgdir}${MINGW_PREFIX}"/bin/djview4.exe
  ln -s "${pkgdir}${MINGW_PREFIX}"/bin/djview4.exe "${pkgdir}${MINGW_PREFIX}"/bin/djview.exe
}
