# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=mtex2mml
_pkgname=mtex2MML
pkgver=1.3.2
pkgrel=0
pkgdesc="A Bison grammar to convert TeX math into MathML"
url="https://github.com/gjtorikian/mtex2MML"
arch="all"
license="GPL-2.0 MPL-2.0 LGPL-2.1"
makedepends="cmake bison flex-dev python3 samurai"
subpackages="$pkgname-dev $pkgname-libs $pkgname-fixtures::noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/gjtorikian/mtex2MML/archive/v$pkgver.tar.gz
	fix-uthash-includes.patch
	"
builddir="$srcdir/$_pkgname-$pkgver"

prepare() {
	default_prepare

	# Note: This bundled uthash is modified, so we can't replace it with
	# system-provided. Thus we must move them to the other sources, where
	# they really belongs.
	# Upstream-Issue: https://github.com/gjtorikian/mtex2MML/issues/59
	cd deps/uthash
	mv utarray.h uthash.h utstring.h ../../src/
	rm ./*.h
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_VERBOSE_MAKEFILE=TRUE
	cmake --build build
}

check() {
	ctest -V --test-dir build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

fixtures() {
	pkgdesc="$pkgdesc (test fixtures)"
	local destdir="$subpkgdir/usr/share/$_pkgname"

	mkdir -p "$destdir"
	mv "$builddir"/tests/fixtures "$destdir"/
}

sha512sums="
eb45477335e3944a3e54f42cda86d98aca65974c2311799870813c2512bb99c8b9e38149d5c4d808a7a51a962e9d00e3b8ead44292ed3e82fd1c3d9529bd3da6  mtex2mml-1.3.2.tar.gz
1754951f71e085fd8c2e6cebf6c5cd07604c671b9ac027fc2cbc16be891ffcf433ba48135e08e51479fac1cf3b129de85929cef8151e776e9b50ed4be8728b3c  fix-uthash-includes.patch
"
