# Maintainer: Gabriel Rauter <rauter.gabriel@gmail.com>

_realname=baobab
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=40.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="A graphical directory tree analyzer (mingw-w64)"
url="https://wiki.gnome.org/Apps/DiskUsageAnalyzer"
depends=("${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
         "${MINGW_PACKAGE_PREFIX}-gobject-introspection-runtime"
         "${MINGW_PACKAGE_PREFIX}-libhandy"
         "${MINGW_PACKAGE_PREFIX}-librsvg")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-yelp-tools"
             "${MINGW_PACKAGE_PREFIX}-appstream-glib"
             "${MINGW_PACKAGE_PREFIX}-meson")
options=('strip' 'staticlibs')
license=("GPL2")
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"
        "0001-Fix-application-icon-name-in-baobab-main-window.ui.patch"
        "0001-Build-GUI-application-on-windows.patch")
sha256sums=('a6aeaa2c327a997fe0d5f443ce95b785e2ba6e338fb0a026cb7dc7d7d688d1a7'
            '53b44512790623b318c07584ea72c85acaf5c1280c00dde8969e863010cb183c'
            '29fdd3e63e1b87dc9b88ee23674bda6bdd127828a8c542279ae4185a1e72f6b7')

prepare() {
    cd "${_realname}-${pkgver}"
    # https://gitlab.gnome.org/GNOME/baobab/-/merge_requests/23
    patch --forward --strip=1 --input="${srcdir}/0001-Fix-application-icon-name-in-baobab-main-window.ui.patch"
    # https://gitlab.gnome.org/GNOME/baobab/-/merge_requests/32
    patch --forward --strip=1 --input="${srcdir}/0001-Build-GUI-application-on-windows.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}"

  ninja
}

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

  DESTDIR="${pkgdir}" ninja install

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