# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gtksourceview
pkgbase=mingw-w64-${_realname}3
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}3"
pkgver=3.24.11
pkgrel=1
pkgdesc="A text widget adding syntax highlighting and more to GNOME (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.gnome.org"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-glade"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "intltool")
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libxml2")
options=(!libtool strip staticlibs)
source=("https://download.gnome.org/sources/gtksourceview/${pkgver%.*}/gtksourceview-${pkgver}.tar.xz"
        0006-hack-convert-path-back-to-unix.patch)
sha256sums=('691b074a37b2a307f7f48edc5b8c7afa7301709be56378ccf9cc9735909077fd'
            '83cf1b41b7b4cfadaf8bf66b0508a68462e1d2865825c8c49d3ded29604f218a')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0006-hack-convert-path-back-to-unix.patch

  autoreconf -fi
}

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

  mkdir -p docs/reference/html
  cp -rf ../${_realname}-${pkgver}/docs/reference/html/* docs/reference/html

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --disable-static \
    --enable-glade-catalog \
    --enable-gtk-doc

  make
}

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

  for ff in ${pkgdir}/${MINGW_PREFIX}/bin/libgtksourceview*.dll; do
    local _reallib=$(basename $ff)
    _reallib=${_reallib%.dll}
    _reallib=${_reallib#lib}
    sed -e "s|library=\"gtksourceview-3.0\"|library=\"${_reallib}\"|g" -i ${pkgdir}/${MINGW_PREFIX}/share/glade/catalogs/gtksourceview.xml
  done

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