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

_realname=gsasl
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.2.1
pkgrel=2
pkgdesc="Simple Authentication and Security Layer framework and a few common SASL mechanisms (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.gnu.org/software/gsasl/"
msys2_repository_url="https://gitlab.com/gsasl/gsasl"
msys2_references=(
  'archlinux: gsasl'
)
license=("spdx:LGPL-2.1-or-later AND GPL-3.0-or-later")
depends=("${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gss"
         "${MINGW_PACKAGE_PREFIX}-libidn"
         "${MINGW_PACKAGE_PREFIX}-libntlm"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "help2man")
source=(https://ftp.gnu.org/gnu/gsasl/${_realname}-${pkgver}.tar.gz{,.sig})
sha256sums=('d45b562e13bd13b9fc20b372f4b53269740cf6279f836f09ce11b9d32bcee075'
            'SKIP')
validpgpkeys=('B1D2BD1375BECB784CF4F8C4D73CF638C53C06BE'   # Simon Josefsson <simon@josefsson.org>
              '9AA9BDB11BB1B99A21285A330664A76954265E8C')  # Simon Josefsson <simon@josefsson.org>

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

  # autoreconf to get updated libtool files with clang support.
  autoreconf -fiv
}

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

  # for clang
  CFLAGS+=" -Wno-int-conversion"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-shared \
    --enable-static \
    --disable-kerberos_v5

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make DESTDIR="${pkgdir}" install

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