# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jürgen Pfeifer <juergen@familiepfeifer.de>

pkgname=lftp
pkgver=4.9.3
pkgrel=1
pkgdesc="Sophisticated command line based FTP client (net-utils)"
arch=('i686' 'x86_64')
license=('GPL3')
groups=('net-utils')
depends=('gcc-libs'
         'ca-certificates'
         'expat'
         'gettext'
         'libexpat'
         'libgnutls'
         'libiconv'
         'libidn2'
         'libintl'
         'libreadline'
         'libunistring'
         'openssh'
         'zlib')
makedepends=('gcc'
             'autotools'
             'gettext-devel'
             'libexpat-devel'
             'libgnutls-devel'
             'libiconv-devel'
             'libidn2-devel'
             'libreadline-devel'
             'libunistring-devel'
             'zlib-devel')
optdepends=('perl: needed for convert-netscape-cookies and verify-file')
url="https://lftp.yar.ru/"
msys2_repository_url="https://github.com/lavv17/lftp"
msys2_references=(
  "cpe: cpe:/a:alexander_v._lukyanov:lftp"
  "cpe: cpe:/a:lftp_project:lftp"
)
backup=('etc/lftp.conf')
source=(https://lftp.yar.ru/ftp/${pkgname}-${pkgver}.tar.xz
        lftp-4.7.6-no-undefined.patch)
sha256sums=('96e7199d7935be33cf6b1161e955b2aab40ab77ecdf2a19cea4fc1193f457edc'
            'e9a289f30d0d7fd9994165b6991a722dbe529f1fdbd738d5b44b48ec9c773bf4')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/lftp-4.7.6-no-undefined.patch

  autoreconf -fiv
}

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

  ../${pkgname}-${pkgver}/configure \
    --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --with-gnutls \
    --without-openssl \
    --without-included-regex \
    --with-expat \
    --with-libidn2 \
    --disable-rpath
  make
}

check() {
  cd ${srcdir}/build-${CARCH}
  make -k check
}

package() {

  cd ${srcdir}/build-${CARCH}
  make DESTDIR=${pkgdir} install
  
  grep -q 'set ssl:ca-file' ${pkgdir}/etc/lftp.conf || echo 'set ssl:ca-file /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem' >> ${pkgdir}/etc/lftp.conf

}
