# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=mtex2mml
_pkgname=mtex2MML
pkgver=1.3.1
pkgrel=1
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"
subpackages="$pkgname-dev $pkgname-libs $pkgname-fixtures::noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/gjtorikian/$pkgname/archive/v$pkgver.tar.gz
	cmake-fix-install.patch
	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() {
	mkdir -p "$builddir"/build
	cd "$builddir"/build

	cmake .. \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-DCMAKE_VERBOSE_MAKEFILE=TRUE
	make
}

check() {
	cd "$builddir"/build
	ctest -V
}

package() {
	cd "$builddir"/build
	make DESTDIR="$pkgdir" install
}

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

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

sha512sums="584a02d8312233a08d527973ddca7d5d26429cd4d97e0a5db671d90ac1e9f2587746b38fbdb69366ed6e1f38a706335309a3fc04c10aa93658a7b773cc752fed  mtex2mml-1.3.1.tar.gz
54c8da2a63d4b2e9f5bccdcbc8130399c0772badda41f62dfb8ef91c10681e477e291b71fce95dda80f0c5b57277d5a94c597fe515b94eeb1c9178a587bcc3ff  cmake-fix-install.patch
1754951f71e085fd8c2e6cebf6c5cd07604c671b9ac027fc2cbc16be891ffcf433ba48135e08e51479fac1cf3b129de85929cef8151e776e9b50ed4be8728b3c  fix-uthash-includes.patch"
