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

_realname=meson
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.3
pkgrel=1
pkgdesc="High-productivity build system (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://mesonbuild.com/"
license=("spdx:Apache-2.0")
options=('!strip')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-ninja")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-wheel"
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
)
source=("https://github.com/mesonbuild/${_realname}/releases/download/${pkgver}/${_realname}-${pkgver}.tar.gz"
        'color-term.patch'
        '0002-Default-to-sys.prefix-as-the-default-prefix.patch'
        '0004-fix-gtk-doc.patch'
        'install-man.patch')
sha256sums=('4533a43c34548edd1f63a276a42690fce15bde9409bcf20c4b8fa3d7e4d7cac1'
            '5805aed0a117536eb16dd8eef978c6be57c2471b655ede63e25517c28b4f4cf0'
            '032b38f0b2765dc88e1fcb34e27b69b611e07c869c13c6e703bcf182e586fccb'
            '0f9177102976bbcbdf50c1da49842783a0c77be939e839f1bf91dcaba6a5cdee'
            '0682a36cb75e545a78b81293303835a16171f25baf949905dc08029436efff84')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

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

  apply_patch_with_msg \
    color-term.patch \
    0002-Default-to-sys.prefix-as-the-default-prefix.patch \
    0004-fix-gtk-doc.patch \
    install-man.patch
}

build() {
  cd "${_realname}-${pkgver}"

  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

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