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

_realname=ghex
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.18.4
pkgrel=4
pkgdesc="A simple binary editor for the Gnome desktop (mingw-w64)"
url="https://wiki.gnome.org/Apps/Ghex"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=("GPL2")
options=(strip staticlibs)
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-gtk-update-icon-cache")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        001-nohelp.patch
        002-fread.patch
        003-gui-app.patch)
sha256sums=('c2d9c191ff5bce836618779865bee4059db81a3a0dff38bda3cc7a9e729637c0'
            '30a351ef0c0b0bc319edec222de5222879b8eecfb58237e5b25c3c1dccf02788'
            '670d0ac95803ea84e53d2d3ee27bd272599c4cab92501426644bfde9fef3d2ae'
            'e48c7c487bc6a4917c91e3bb08f378916e131ee446b0f2f7bd7666a3478a4141')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -Np1 -i ${srcdir}/001-nohelp.patch
  patch -Np1 -i ${srcdir}/002-fread.patch
  patch -Np1 -i ${srcdir}/003-gui-app.patch
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Ddefault_library=both \
    "../${_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"
}
