# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=enca
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.19
pkgrel=2
pkgdesc="Charset analyser and converter (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://cihar.com/software/enca/"
options=('strip' 'staticlibs')
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-recode")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://dl.cihar.com/enca/enca-${pkgver}.tar.xz"
        'configure.patch'
        'noconfigure-autogen.patch')
sha256sums=('3a487eca40b41021e2e4b7a6440b97d822e6532db5464471f572ecf77295e8b8'
            '9078b82b3c68dc55a949cf039418ba807b27ba8292853a24399a56d13b600634'
            '053f549c99e490550f73f19ae1074712c7d7374ac26b38d81013c81f86a3e075')

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

  patch -Np1 -i "${srcdir}/configure.patch"
  patch -Np1 -i "${srcdir}/noconfigure-autogen.patch"
  NOCONFIGURE=1 ./autogen.sh
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../enca-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --libexecdir=${MINGW_PREFIX}/lib \
    --mandir=${MINGW_PREFIX}/share/man \
    --with-librecode=${MINGW_PREFIX} \
    --enable-external

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
