# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=polyml
pkgver=5.9.1
pkgrel=1
pkgdesc="ML97 compatible Standard ML implementation"
url="https://www.polyml.org/"
# x86: https://github.com/polyml/polyml/issues/193
arch="all !x86"
license="LGPL-2.1-only"
makedepends="gmp-dev libffi-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/polyml/polyml/archive/v$pkgver.tar.gz
	riscv64.patch
	add-support-to-loongarch64.patch
	remove-reference-asm-elf.patch"

prepare() {
	default_prepare
	update_config_sub
	update_config_guess
}

build() {
	# Compiling poly as a dynamically linked position independent
	# executable causes it to segfault. Since Alpine's GCC enables
	# PIE by default we need to explicitly disable it.
	#
	# See https://github.com/polyml/polyml/issues/111
	CFLAGS="$CFLAGS -no-pie" ./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--with-gmp
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
}

sha512sums="
e471abef01b7f2bfac6d847904c0fcef6ae5a1356b1246a2e8982d24fd590b49feb03752642efe09d34344b4faf89bc3edd4418e9993e72ea22e5482e6d37271  polyml-5.9.1.tar.gz
bf41a055b01ca9e5d1856e39f318079e23272eb034031cb97f7b7dbb94b981b6956baaba38d33c959e2175f052d4214dffd6f1fb18a69b8509013a19a93beb50  riscv64.patch
eb8b2b390a8c210b180f9fcb6742c4d2a9938c5e720b3925690f0fb78058c15e65ef18af677d48fcdd4896c814978d9030f09280799f7426798b601fd2161ea6  add-support-to-loongarch64.patch
9fc6ac71fb6d2e787fa60047ac6cb23e11b549348a6d10c234fa4f307301a164f2918c07260fd54aab060abe6c57148f8efbb9b8e7bca5d621c332b32ff90d3c  remove-reference-asm-elf.patch
"
