# Maintainer: Renato Silva <br.renatosilva@gmail.com>
# Contributor: Zach Bacon <11doctorwhocanada@gmail.com>

_realname='pidgin'
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.14.14
pkgrel=5
pkgdesc='Multi-protocol instant messaging client (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://pidgin.im'
msys2_references=(
  "cpe: cpe:/a:pidgin:libpurple"
  "cpe: cpe:/a:pidgin:pidgin"
)
license=(spdx:GPL-2.0-or-later AND GPL-2.0-only) # GPL2+, but Novell and SILC are GPL2-only
provides=("${MINGW_PACKAGE_PREFIX}-libpurple")
depends=("${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-atk"
         "${MINGW_PACKAGE_PREFIX}-ca-certificates"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         #"${MINGW_PACKAGE_PREFIX}-cyrus-sasl"
         #"${MINGW_PACKAGE_PREFIX}-dbus"
         "${MINGW_PACKAGE_PREFIX}-farstream"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gsasl"
         "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
         "${MINGW_PACKAGE_PREFIX}-gst-plugins-good"
         "${MINGW_PACKAGE_PREFIX}-gstreamer"
         "${MINGW_PACKAGE_PREFIX}-gtk2"
         "${MINGW_PACKAGE_PREFIX}-gtkspell"
         "${MINGW_PACKAGE_PREFIX}-libgadu"
         "${MINGW_PACKAGE_PREFIX}-libidn"
         #"${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-meanwhile"
         #"${MINGW_PACKAGE_PREFIX}-nspr"
         "${MINGW_PACKAGE_PREFIX}-nss"
         "${MINGW_PACKAGE_PREFIX}-ncurses"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-silc-toolkit"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools"
             #"${MINGW_PACKAGE_PREFIX}-dbus-glib"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             'intltool')
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.bz2"{,.asc}
        001-autotools-and-fhs.patch
        002-build-fixes.patch
        003-build-fixes.patch)
sha256sums=('0ffc9994def10260f98a55cd132deefa8dc4a9835451cc0e982747bd458e2356'
            'SKIP'
            '5852d78f97e344226e598f2342b7a1b276f25eec71903bacdc9f68849804df85'
            'bdc8fc0e707206ec340711c25c7ef5be453be1cff93b1678908ebe71907600d7'
            '1cc23086ab40bed7df176015cbd7f3cc0cd4dc72ae814dea9120f5e2d2ce9faa')
validpgpkeys=('40DE1DC7288FE3F50AB938C548F66AFFD9BDB729') # Gary Kramlich <grim@reaperworld.com>

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

    # From https://build.opensuse.org/package/view_file/windows:mingw:win32/mingw32-pidgin/pidgin-2.10.11-autotools.patch
    rm -f pidgin/plugins/win32/Makefile.am
    rm -f pidgin/plugins/win32/winprefs/Makefile.am
    patch -p1 < "${srcdir}/001-autotools-and-fhs.patch"
    patch -p1 < "${srcdir}/002-build-fixes.patch"
    patch -p1 < "${srcdir}/003-build-fixes.patch"

    libtoolize --force --copy --install
    aclocal -I m4macros
    automake --add-missing
    autoreconf -f -i
}

build() {
    cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MSYSTEM}"
    cd "${srcdir}/build-${MSYSTEM}"

    CFLAGS+=" -Wno-deprecated-declarations -Wno-int-conversion -Wno-incompatible-pointer-types" \
    CXXFLAGS+=" -Wno-deprecated-declarations -Wno-int-conversion -Wno-incompatible-pointer-types" \
    INTLTOOL_PERL=/usr/bin/perl ./configure \
        --prefix=${MINGW_PREFIX} \
        --build=${MINGW_CHOST} \
        --host=${MINGW_CHOST} \
        --sysconfdir=${MINGW_PREFIX}/etc \
        --with-python3=${MINGW_PREFIX}/bin/python \
        --with-system-ssl-certs=${MINGW_PREFIX}/etc/ssl/certs \
        --without-x \
        --disable-avahi \
        --disable-schemas-install \
        --disable-screensaver \
        --disable-perl \
        --disable-tcl \
        --disable-tk \
        --disable-sm \
        --disable-nm \
        --disable-dbus \
        --disable-gevolution \
        --disable-cyrus-sasl

    make
}

package() {
    cd "${srcdir}/build-${MSYSTEM}"
    make DESTDIR="${pkgdir}" install
    install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
