# 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.14.0
pkgrel=3
pkgdesc="Next-generation distributed IRC client (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: quassel-client'
  "cpe: cpe:/a:quassel-irc:quassel"
)
url="https://quassel-irc.org/"
license=('GPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             #"${MINGW_PACKAGE_PREFIX}-extra-cmake-modules" #TODO: only needed with WITH_KDE=ON
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-qca-qt5"
         "${MINGW_PACKAGE_PREFIX}-qt5-base"
         "${MINGW_PACKAGE_PREFIX}-qt5-multimedia"
         #"${MINGW_PACKAGE_PREFIX}-qt5-script"
         #"${MINGW_PACKAGE_PREFIX}-Snorenotify"
         #"${MINGW_PACKAGE_PREFIX}-sonnet-qt5"
         "${MINGW_PACKAGE_PREFIX}-zlib")
source=(https://quassel-irc.org/pub/${_realname}-${pkgver}.tar.bz2
        "0001-MinGW-w64-Adopt-FHS-Layout.patch"
        "0002-aarch64-logbacktrace.patch")
sha256sums=('bbd46ca429c1518480904c9e2b0ab3a0412fe197f3ce4879974e06ed3a0093a3'
            '12b82e72c2d3a42872104906bad73f48c9b944506d086c0bcd710af904c9fcd8'
            '88bdf2acebc897508fc5f13298cf0b74cf6b62aa3002617ba520f9d0f3fe1421')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-MinGW-w64-Adopt-FHS-Layout.patch
  patch -p1 -i "${srcdir}"/0002-aarch64-logbacktrace.patch
}

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

  # ENABLE_SHARED=OFF is required or we get
  # "Trying to access a singleton that has not been instantiated yet"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DWITH_KDE=OFF \
    -DCMAKE_BUILD_TYPE="Release" \
    -DWANT_CORE=ON \
    -DWANT_QTCLIENT=ON \
    -DWANT_MONO=ON \
    -DENABLE_SHARED=OFF \
    -Wno-dev \
    ../${_realname}-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

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

  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .
}
