# Contributor: Marian Buschsieweke <marian.buschsieweke@posteo.net>
# Maintainer: Marian Buschsieweke <marian.buschsieweke@posteo.net>
pkgname=mpir
pkgver=3.0.0
pkgrel=2
pkgdesc="Multiple Precision Integers and Rationals"
url="https://github.com/wbhart/mpir"
arch="all"
license="LGPL-3.0-or-later"
makedepends="autoconf automake texinfo libtool yasm m4"
subpackages="$pkgname-dev $pkgname-doc"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/wbhart/mpir/archive/refs/tags/mpir-$pkgver.tar.gz
	configure-xcode12.patch
	gcc14.patch
	tests.patch
	mpir.pc
	mpirxx.pc
	"
builddir="$srcdir/mpir-mpir-$pkgver"

prepare() {
	default_prepare

	update_config_guess
	update_config_sub
	autoreconf -fvi

	sed -e "s/@PKGVER@/$pkgver/" -i "$srcdir"/mpir.pc
	sed -e "s/@PKGVER@/$pkgver/" -i "$srcdir"/mpirxx.pc
}

build() {
	local _configure_opts="--prefix=/usr --enable-cxx --disable-static"

	# Add host flag to omit ppc64 ABIv1 assembly code and resolve the error:
	# ABI version 1 is not compatible with ABI version 2 output
	if [ "$CARCH" = "ppc64le" ]; then
		_configure_opts="$_configure_opts --host=none-alpine-linux-musl"
	fi

	./configure $_configure_opts
	make
}

package() {
	DESTDIR="$pkgdir" make install
	install -Dm644 "$srcdir"/mpir.pc "$pkgdir"/usr/lib/pkgconfig/mpir.pc
	install -Dm644 "$srcdir"/mpirxx.pc "$pkgdir"/usr/lib/pkgconfig/mpirxx.pc
}

check() {
	make check-recursive
}

sha512sums="
7d37f60645c533a6638dde5d9c48f5535022fa0ea02bafd5b714649c70814e88c5e5e3b0bef4c5a749aaf8772531de89c331716ee00ba1c2f9521c2cc8f3c61b  mpir-3.0.0.tar.gz
c7b9a273156f745ba39966bfdc8d78be393bd8e72e37cf2a958f3c63894747bca23d4dd67cf8e7dfe5aa3099082644e62a86597610260e61c203cc5ec45538b8  configure-xcode12.patch
f5bc7cd4590aae8c2a0012cc57b5684bc940a00aec7a77a19dcaa67c66555e0eab72c1590eab2751416c8491d6444bf7d527006e53ddd1772efcabe151b70deb  gcc14.patch
34dada56268c9150c8bf8e2ea2a1401a9bde22d0a44913c546638fd8b09bbdeadca60eb01c4210bbac62af97ebe0f057a74c636e04d4301d39b01af45fdfe5e5  tests.patch
00f960b5f320a12ef8ce98d457591f963e30685c94ad7f79942268c64e428f564f16c6bade001e63610817f6c22279a1d3b2473b9ca88b29c36fe9589e58d400  mpir.pc
c6c264b12091ef6f962cfcc819a0cd74586189afbba4af878f47d9921745e6d3634cd62a3a107a865438644181a5c60286f907b1aa4c80eb0ec1c7df44ab0f56  mpirxx.pc
"
