# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=meson
pkgver=1.8.1
pkgrel=0
pkgdesc="Fast and user friendly build system"
url="https://mesonbuild.com"
arch="noarch"
license="Apache-2.0"
depends="samurai"
makedepends="py3-gpep517 py3-setuptools py3-wheel"
# glib-dev, gobject-introspection-dev, gtk+3.0-dev is a circular dep,
# but only during bootstrap-
# not installing checkdepends with !check should be fine
options="$options !check" # circular deps above with check on bootstrap
checkdepends="
	boost-dev
	boost-static
	cmake
	cups-dev
	doxygen
	gettext-static
	gfortran
	glib-dev
	gobject-introspection-dev
	gtest-dev
	gtk+3.0-dev
	libpcap-dev
	libxml2-dev
	linux-headers
	llvm-dev
	nasm
	ncurses-dev
	py3-pytest
	python3-dev
	vala
	zlib-dev
	zlib-static
	"
subpackages="
	$pkgname-doc
	$pkgname-pyc
	$pkgname-vim::noarch
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-polkit::noarch
	abuild-$pkgname:abuild:noarch
	"
source="https://github.com/mesonbuild/meson/releases/download/$pkgver/meson-$pkgver.tar.gz
	fix-ninja-output-test.patch
	skip-broken-tests.patch
	abuild-meson
	"

prepare() {
	default_prepare

	# https://github.com/mesonbuild/meson/issues/10104
	rm -r "$builddir/test cases/linuxlike/13 cmake dependency"
}

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	MESON_CI_JOBNAME=thirdparty \
		NINJA=samu \
		NINJA_1_9_OR_NEWER=1 \
		python3 run_tests.py
}

package() {
	python3 -m installer -d "$pkgdir" .dist/*.whl

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

vim() {
	pkgdesc="$pkgdesc (vim support)"
	depends=
	install_if="vim $pkgname=$pkgver-r$pkgrel"
	cd "$builddir"
	for kind in ftdetect ftplugin indent syntax
	do
		mkdir -p "$subpkgdir"/usr/share/vim/vimfiles/$kind
		install -Dm644 \
			"$builddir"/data/syntax-highlighting/vim/$kind/meson.vim \
			"$subpkgdir"/usr/share/vim/vimfiles/$kind/meson.vim
	done
}

polkit() {
	pkgdesc="$pkgdesc (polkit config)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel polkit"

	amove usr/share/polkit-*
}

abuild() {
	pkgdesc="$pkgdesc (abuild wrapper)"
	depends="$pkgname=$pkgver-r$pkgrel abuild"
	install_if="$pkgname=$pkgver-r$pkgrel abuild"

	install -Dm0755 "$srcdir"/abuild-meson -t "$subpkgdir"/usr/bin
}

sha512sums="
f5e7a6098f73e46b30a5e9b09f4da21c2e9cd8133a2ee6f2894fe1603356dbe29361ff95063ac364828676c56da1675c5d58238abda4329e935bcf216a9a80df  meson-1.8.1.tar.gz
ff267ae6c6fe9ae6c57506f52735151b08f89eac5733777694f1d949d66b246ec277b91ec578ae31be0ef03b31c87f51616e069ead2e21920155c77ad82de6bd  fix-ninja-output-test.patch
0bbbf65f56f4feab43b4ec3fbe7d4c64ef9abb563ea114d0b960048319b936dd577e538a762991661a1cb256f32c0da0fef2d3add07730e37a8bbd4ec27dc611  skip-broken-tests.patch
015030aa7fcc658b74a9e58a6bf67070450def0f58fb75c7bba3dbe5ba3556d7d16a4710710ed286e5bb4a7efa90c5e0abbc63b0a8be37f499c0e7862e26d150  abuild-meson
"
