# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=gnome-latex
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
replaces=("${MINGW_PACKAGE_PREFIX}-latexila")
pkgver=3.46.0
pkgrel=3
pkgdesc="LaTeX editor designed for the GNOME desktop (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://wiki.gnome.org/Apps/GNOME-LaTeX'
license=("spdx:GPL-3.0-or-later")
depends=(
  "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
  "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
  "${MINGW_PACKAGE_PREFIX}-glib2"
  "${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
  "${MINGW_PACKAGE_PREFIX}-gspell"
  "${MINGW_PACKAGE_PREFIX}-gtk-update-icon-cache"
  "${MINGW_PACKAGE_PREFIX}-gtk3"
  "${MINGW_PACKAGE_PREFIX}-libgedit-amtk"
  "${MINGW_PACKAGE_PREFIX}-libgedit-gtksourceview"
  "${MINGW_PACKAGE_PREFIX}-libgedit-tepl"
  "${MINGW_PACKAGE_PREFIX}-libgee"
  "${MINGW_PACKAGE_PREFIX}-pango"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-appstream-glib"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-gettext-tools"
  "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
  "${MINGW_PACKAGE_PREFIX}-gtk-doc"
  "${MINGW_PACKAGE_PREFIX}-itstool"
  "${MINGW_PACKAGE_PREFIX}-vala"
  "${MINGW_PACKAGE_PREFIX}-yelp-tools"
)
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        https://gitlab.gnome.org/swilmet/gnome-latex/-/commit/41e532c427f43a5eed9081766963d6e29a9975a1.patch)
sha256sums=('d67555639b2a15a8aebd54f335354e44fe3433143ae3cb3cca7a8e26f8112ada'
            '53902ff7e58de750db69c70029f8ccd465a039d35347b71959a9b24b5090d5e3')

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

  # Adapt for Tepl -> libgedit-tepl rename
  patch -p1 -i "${srcdir}/41e532c427f43a5eed9081766963d6e29a9975a1.patch"

  autoreconf -fiv
}

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

  # clang error from vala generated file
  export CFLAGS="${CFLAGS} -Wno-incompatible-function-pointer-types"
  # gcc errors from vala generated file
  CFLAGS+=" -Wno-incompatible-pointer-types"

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib \
    --enable-introspection \
    --disable-dconf-migration

  make
}

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

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

  make DESTDIR="${pkgdir}" install

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