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

_realname=libgweather
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.36.1
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="GWeather shared library (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libsoup"
         "${MINGW_PACKAGE_PREFIX}-libsystre"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-geocode-glib")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-glade"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "gtk-doc"
             "intltool")
options=('strip' 'staticlibs')
license=("LGPL 2.1")
url="https://www.gnome.org/"
install=${_realname}-${CARCH}.install
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        001-win.patch
        002-relocation.patch
        003-meson.patch)
sha256sums=('de2709f0ee233b20116d5fa9861d406071798c4aa37830ca25f5ef2c0083e450'
            'e423f33c074640dd2ce074859102782438961d21d8f8fc6fe88833196b1f7212'
            'b92f0f98613430dc4037925921dec6fed184ea6ae6d6db076297aaec969de6fc'
            'c1593cab978cbe01f4ed033c6ae8f8f19193e7583fa03b95734582f4fab8cdbb')
noextract=(${_realname}-${pkgver}.tar.xz)

prepare() {
  [[ -d ${srcdir}/${_realname}-${pkgver} ]] && rm -rf ${srcdir}/${_realname}-${pkgver}
  tar -xJf ${srcdir}/${_realname}-${pkgver}.tar.xz -C ${srcdir} 2>/dev/null || true

  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-win.patch
  patch -p1 -i ${srcdir}/002-relocation.patch
  patch -p1 -i ${srcdir}/003-meson.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/ninja install

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