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

_realname=FileZilla
_wx_basever=3.2
pkgbase=mingw-w64-filezilla
pkgname=("${MINGW_PACKAGE_PREFIX}-filezilla")
pkgver=3.69.2
pkgrel=1
pkgdesc="Fast and reliable FTP, FTPS and SFTP client (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://filezilla-project.org/"
msys2_repository_url="https://svn.filezilla-project.org/filezilla/FileZilla3/"
msys2_documentation_url="https://wiki.filezilla-project.org/Documentation"
msys2_references=(
  'archlinux: filezilla'
  "cpe: cpe:/a:filezilla:filezilla"
  "cpe: cpe:/a:filezilla-project:filezilla_client"
)
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-libfilezilla"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw")
# Upstream download link became (purposely) unstable
# See https://trac.filezilla-project.org/ticket/13186
#source=("https://download.filezilla-project.org/client/${_realname}_${pkgver}_src.tar.xz"
source=("https://sources.archlinux.org/other/${_realname,,}/${_realname,,}-${pkgver}.tar.xz"
        "0002-fix-mingw-compiler-detection.patch"
        "0003-fix-build.patch")
sha256sums=('ee1868310acbefe312981364b219e7ea85f6028e5f7596a7aa305ee15a4e7a01'
            'b19da8c59e9010cd08034090a64348d30e2e9d14a8cefa87da994825197f58ba'
            'da8ba93395e82896cfa285d4379cec1ee0a18ae4389002c5964ff51e4a380bbf')

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

  patch -Np1 -i "${srcdir}/0002-fix-mingw-compiler-detection.patch"

  # https://trac.filezilla-project.org/ticket/13099
  patch -Np1 -i "${srcdir}/0003-fix-build.patch"
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  if [[ $MINGW_PACKAGE_PREFIX != *-clang-* ]]; then
    CFLAGS+=" -Wno-incompatible-pointer-types"
    CXXFLAGS+=" -Wno-incompatible-pointer-types"
  fi

  ../${_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-${_wx_basever}

  make
}

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

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

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