# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Anatol Pomozov <anatol dot pomozov at gmail>

pkgname=meson
pkgver=1.9.1
pkgrel=2
pkgdesc="High productivity build system"
url="https://mesonbuild.com/"
arch=(any)
license=(Apache-2.0)
depends=(
  bash
  ninja
  python
  python-tqdm
)
makedepends=(
  git
  python-aiohttp
  python-build
  python-installer
  python-setuptools
  python-strictyaml
  python-wheel
)
checkdepends=(
  boost
  clang
  cmake
  cuda
  cython
  doxygen
  gcc-fortran
  gcc-objc
  git
  glib2-devel
  glibc-locales
  gmock
  gnustep-base
  gobject-introspection
  graphviz
  gtest
  gtk-doc
  gtk-sharp-3
  gtk3
  gtkmm3
  hdf5
  hotdoc
  itstool
  java-environment=8
  libelf
  libpcap
  libwmf
  llvm
  mercurial
  mono
  nasm
  netcdf-fortran
  openmpi
  openssh
  protobuf
  pypy3
  python-gobject
  python-importlib-metadata
  python-lxml
  python-pip
  python-pytest-xdist
  qt5-base
  qt5-tools
  qt6-base
  qt6-declarative
  qt6-tools
  rust
  rust-bindgen
  sdl2
  vala
  valgrind
  vulkan-headers
  vulkan-icd-loader
  vulkan-validation-layers
  wayland
  wayland-protocols
  wxwidgets-gtk3
)
source=(
  "git+https://github.com/mesonbuild/meson?signed#tag=$pkgver"
  arch-meson
  cross-lib32
  native-clang
  0001-Skip-broken-tests.patch
  0002-Update-tests-to-work-with-CUDA-13.patch
)
b2sums=('0bccaa9793e9c4246cbeb66951465862e1addb410f77714160ecf7399b1f0b537f13231819ef7cf2e1a01eff8ac8e10e1e32679da0e0b0ea006856bf63ff9020'
        '70f042a7603d1139f6cef33aec028da087cacabe278fd47375e1b2315befbfde1c0501ad1ecc63d04d31b232a04f08c735d61ce59d7244521f3d270e417fb5af'
        '01de9b127552feaec612a0bc9551796e44f0800908bd759c6ede4dc22a65dd8ed4fc06dcbdeaef48c4aef926115d783ef019e429b01295526f23f8fa7d49e11b'
        '7d88929d5a3b49d91c5c9969f19d9b47f3151706526b889515acaeda0141257d5115875ac84832e9ea46f83a7700d673adcc5db84b331cd798c70ae6e90eac1e'
        '561dcdb5785c9ec7a679b78631eb982e3ee5a6ae39cdfa30ad23417ed0cc1dbc8d323f4a15c3fc793395d86cec261625dd7b45fbfbf8442ecbda31947d88422d'
        '598d001a3f2f790542dfde0360316d3de059eb13c5679d76931c67a034585d31ca24e75cf3834abc45adefd45a8d731a8755f1822e9c0446d8eff3949e23ac8b')
validpgpkeys=(
  19E2D6D9B46D8DAA6288F877C24E631BABB1FE70 # Jussi Pakkanen <jpakkane@gmail.com>
  BD27B07A5EF45C2ADAF70E0484818A6819AF4A9B # Eli Schwartz <eschwartz93@gmail.com>
)

prepare() {
  cd meson

  # Switch C# test to use gtk-sharp-3
  # https://github.com/mesonbuild/meson/pull/15167
  sed -i 's/glib-sharp-2/glib-sharp-3/' 'test cases/csharp/4 external dep/meson.build'

  # Pass tests
  patch -Np1 -i ../0001-Skip-broken-tests.patch
  patch -Np1 -i ../0002-Update-tests-to-work-with-CUDA-13.patch
}

build() {
  cd meson
  python -m build --wheel --no-isolation
  ./meson.py setup docs docs.build --prefix /usr -D html=false
  ./meson.py compile -C docs.build
}

check() (
  cd meson
  export LC_CTYPE=en_US.UTF-8 CPPFLAGS= CFLAGS= CXXFLAGS= LDFLAGS=
  ./run_tests.py --failfast
)

package() {
  cd meson
  python -m installer --destdir="$pkgdir" dist/*.whl

  ./meson.py install -C docs.build --destdir "$pkgdir"
  install -Dm644 docs.build/reference_manual.json -t "$pkgdir/usr/share/doc/$pkgname"

  install -d "$pkgdir/usr/share/vim/vimfiles"
  cp -rt "$pkgdir/usr/share/vim/vimfiles" data/syntax-highlighting/vim/*/

  install -Dm644 data/shell-completions/bash/* -t "$pkgdir/usr/share/bash-completion/completions"
  install -Dm644 data/shell-completions/zsh/*  -t "$pkgdir/usr/share/zsh/site-functions"

  install -D ../arch-meson -t "$pkgdir/usr/bin"

  install -Dm644 ../cross-lib32 "$pkgdir/usr/share/meson/cross/lib32"
  install -Dm644 ../native-clang "$pkgdir/usr/share/meson/native/clang"
}

# vim:set sw=2 sts=-1 et:
