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

_realname=desktop-file-utils
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.28
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
pkgdesc="Utilities for .desktop files (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-glib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-ninja")
license=("spdx:GPL-2.0-or-later")
url="https://www.freedesktop.org/wiki/Software/desktop-file-utils"
msys2_repository_url='https://gitlab.freedesktop.org/xdg/desktop-file-utils'
source=("https://www.freedesktop.org/software/${_realname}/releases/desktop-file-utils-${pkgver}.tar.xz"{,.asc}
        001-win.patch
        002-install.patch)
sha256sums=('4401d4e231d842c2de8242395a74a395ca468cd96f5f610d822df33594898a70'
            'SKIP'
            '3858a459a788b9de64bd5a3cf4505d6b935085f33160ad7931029f1d58732cd1'
            '63685214d41ee6ba567579e83a5c066cf490800b9f5a0b91f273b02ad00af8c8')
validpgpkeys=('C01EDE5BB0D91E26D003662EC76BB9FEEAD12EA7') # Hans Petter Jansson <hpj@suse.com>

prepare() {
  cd ${_realname}-${pkgver}

  patch -b -V simple -p1 -i "${srcdir}"/001-win.patch
  patch -b -V simple -p1 -i "${srcdir}"/002-install.patch
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      ../${_realname}-${pkgver}

  meson compile
}

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

  DESTDIR="${pkgdir}" meson install
  cp -v "${pkgdir}${MINGW_PREFIX}"/bin/{desktop-file-install.exe,desktop-file-edit.exe}

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