# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=FileZilla
pkgbase=mingw-w64-filezilla
pkgname=("${MINGW_PACKAGE_PREFIX}-filezilla")
pkgver=3.51.0
pkgrel=2
pkgdesc="Fast and reliable FTP, FTPS and SFTP client (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://lib.filezilla-project.org/"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-libfilezilla"
         "${MINGW_PACKAGE_PREFIX}-wxWidgets")
license=('GPL')
source=("${_realname}-${pkgver}.tar.bz2"::"https://download.filezilla-project.org/client/${_realname}_${pkgver}_src.tar.bz2"
        "0001-fix-datadir-lookup.patch"
        "0002-fix-mingw-compiler-detection.patch")
sha256sums=('82be1c4a4f51bb32a599d0b4cc3a24127ba948c0af0f957233cc6a13ea3b6c4c'
            '793fa75ab742087aa8c98d05414b152a48ba244dc715d02563c8450399f27bab'
            'b19da8c59e9010cd08034090a64348d30e2e9d14a8cefa87da994825197f58ba')

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

  patch -Np1 -i "${srcdir}/0001-fix-datadir-lookup.patch"
  patch -Np1 -i "${srcdir}/0002-fix-mingw-compiler-detection.patch"
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-manualupdatecheck \
    --disable-autoupdatecheck \
    --with-pugixml=builtin \
    --with-wx-config=${MINGW_PREFIX}/bin/wx-config

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  # LANG needed to fix string_test::test_conversion2
  LANG=en_US.UTF-8 make check || true
}

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

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