# Maintainer (ArchLinux): Vesa Kaihlavirta <vegai@iki.fi>
# Maintainer (ArchLinux): Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>
# Contributor (MSYS2): David Macek <david.macek.0@gmail.com>

_realname=quassel
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.13.1
pkgrel=2
pkgdesc="Next-generation distributed IRC client (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://quassel-irc.org/"
license=('GPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-qca-qt5"
         #"${MINGW_PACKAGE_PREFIX}-extra-cmake-modules" #TODO: only needed with WITH_KDE=ON
         "${MINGW_PACKAGE_PREFIX}-Snorenotify"
         "${MINGW_PACKAGE_PREFIX}-sonnet-qt5")
source=(https://quassel-irc.org/pub/${_realname}-${pkgver}.tar.bz2
        "0001-MinGW-w64-Adopt-FHS-Layout.patch"
        "0002-fix-webkit-including.patch"
        "0004-use-pkg-config-mingw.patch")
sha256sums=('48efee9778743b1db9f44efb91d1c913104db01190c57f2ff57483c39a97e855'
            '12b82e72c2d3a42872104906bad73f48c9b944506d086c0bcd710af904c9fcd8'
            '0c2c0db03d4636a02e2e704cd4b844dd883100a83a777745d4e7e80dce51e56b'
            '0e5d8f78d4f3009b88f536040b659436d67a94975718c1cf973530b79993ab70')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-MinGW-w64-Adopt-FHS-Layout.patch
  patch -p1 -i "${srcdir}"/0002-fix-webkit-including.patch
  patch -p1 -i "${srcdir}"/0004-use-pkg-config-mingw.patch
}

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

  # -DWIN32_LEAN_AND_MEAN=1 because "interface" is used in:
  # /mingw64/include/QtDBus/qdbusconnection.h

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_CXX_FLAGS="${CFLAGS} -DWIN32_LEAN_AND_MEAN=1" \
    -DUSE_QT5=ON \
    -DWITH_KDE=OFF \
    -DCMAKE_BUILD_TYPE="Release" \
    -DWANT_CORE=ON \
    -DWANT_QTCLIENT=ON \
    -DWANT_MONO=ON \
    -Wno-dev \
    ../${_realname}-${pkgver}

  make
}

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