# Maintainer: Troy C < rstrox -ta yahoo -tod com >
# Contributor: Marek Skrobacki <skrobul@skrobul.com>
# Contributor: Alasdair Haswell <ali at arhaswell dot co dot uk>
# Maintainer: Zach Bacon <11doctorwhocanada@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

_realname=meanwhile
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.1.1
pkgrel=2
pkgdesc="Open implementation of the Lotus Sametime protocol. (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/obriencj/meanwhile"
license=(spdx:LGPL-2.0-or-later)
depends=("${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-glib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=(https://github.com/obriencj/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz
        001-fix-groupchat.patch
        002-no-samples.patch)
sha256sums=('10de306f03897572b30ce68ca80dffd04ec218f6842bbe0a47bb8cce933698d0'
            '90467c648c18086a3f7989b7bab8f21eb44631c19a7d531121e927a0a1e74e9c'
            '47df945c721ad4392b113874eed9b90bbb81f6917eaac76af474828520b0420e')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 --binary -i "${srcdir}/${_patch}"
  done
}

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

  apply_patch_with_msg \
    001-fix-groupchat.patch \
    002-no-samples.patch

  autoreconf -vfi
}

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

  export lt_cv_deplibs_check_method='pass_all'

  CFLAGS+=" -Wno-deprecated-declarations -Wno-unused-result" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --disable-doxygen \
    --disable-mailme \
    --enable-static \
    --enable-shared

  make
}

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

  make DESTDIR="${pkgdir}" install

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