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

_realname=recode
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.7.8
pkgrel=1
pkgdesc="Converts files between various character sets and usages (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/rrthomas/recode"
license=('GPL3' 'LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gettext")
options=('!strip' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python")
source=("https://github.com/rrthomas/recode/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "01-no-undefined.patch")
sha256sums=('4fb75cacc7b80fda7147ea02580eafd2b4493461fb75159e9a49561d3e10cfa7'
            '21de31138709ec460fb684b5bf110beabf31627b8e55b4131aad67c7633e77dd')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/01-no-undefined.patch"

  autoreconf -fiv
}

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

  export lt_cv_deplibs_check_method='pass_all'

  PYTHON="${MINGW_PREFIX}/bin/python3" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --mandir=${MINGW_PREFIX}/share/man \
    --infodir=${MINGW_PREFIX}/share/info \
    --without-libiconv-prefix \
    --without-libintl-prefix

  make
}

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

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