# -*- Mode: Tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem      1.0
PortGroup       github 1.0
PortGroup       muniversal  1.0

name            mpir
categories      devel math
license         LGPL-3
maintainers     {michaelld @michaelld} openmaintainer
description     Multiple Precision Integers and Rationals

long_description \
    MPIR: Multiple Precision Integers and Rationals, is a fork of \
    the GNU Multi Precision \(GMP\) library. MPIR is a library for \
    arbitrary precision arithmetic, operating on signed integers, \
    rational numbers, and floating point numbers. It has a rich set \
    of functions, and the functions have a regular interface. MPIR \
    is designed to be as fast as possible, both for small operands \
    and huge operands.  The speed is achieved by using fullwords as \
    the basic arithmetic type, by using fast algorithms, with \
    carefully optimized assembly code for the most common inner \
    loops for lots of CPUs, and by a general emphasis on speed \
    \(instead of simplicity or elegance\).

subport mpir-devel {}

if {${subport} eq ${name}} {

    # release
    conflicts       mpir-devel
    long_description {*}${long_description} \
        This port is kept up with the MPIR release, which is \
        typically updated a few times a year.

    github.setup    wbhart mpir 3.0.0 mpir-
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    revision        2
    checksums       rmd160 62467f99886ae947ed29466880fc885cf5843d63 \
                    sha256 b0a4088134fb25f25725a04243f83039897c51139a0b5f1dcac1395963483c38 \
                    size   3116197

    patchfiles-append patch-fix-configure.release.diff
    patch.pre_args-replace  -p0 -p1

} else {

    # devel
    long_description {*}${long_description} \
        This port is kept up with the MPIR GIT master branch, which \
        is typically updated daily to weekly.

    conflicts       mpir

    github.setup wbhart mpir b3367eb13eca95b3a204beaca5281a2c3b4c66a6
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    version   20201225-[string range ${github.version} 0 7]
    checksums rmd160 b82a0ca6ff5166286591d8094f2c9d7d452ddb88 \
              sha256 e5432756135ce336c6b15d339c1863aae24ddee0c339e055cd83f3775221949e \
              size   2546282
    revision  0

    patchfiles-append patch-fix-configure.devel.diff
    patch.pre_args-replace  -p0 -p1

}

homepage       https://www.mpir.org/

# universal_variant no

use_autoconf   yes
autoconf.cmd   ./autogen.sh

depends_build  port:autoconf \
               port:automake \
               port:libtool \
               port:yasm

if {${os.platform} eq "darwin" && ${os.major} >= 22} {
    depends_build-append port:texinfo
}

configure.cppflags
compiler.cpath
compiler.library_path

configure.args-append --disable-silent-rules \
                      --enable-cxx

configure.universal_args-delete --disable-dependency-tracking

platform darwin {
    if { ${build_arch} eq "arm64" } {
        configure.pre_args-append --build=aarch64-apple-darwin${os.major}
    } else {
        configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
    }
}

if {!${universal_possible} || ![variant_isset universal]} {
    if {${build_arch} eq "x86_64" || ${build_arch} eq "ppc64"} {
        configure.env-append ABI=64
    } elseif {${build_arch} eq "arm64" } {
        configure.env-append ABI=standard
    } else {
        configure.env-append ABI=32
    }
} else {
    array set merger_configure_env {
        ppc     ABI=mode32
        i386    ABI=32
        ppc64   ABI=mode64
        x86_64  ABI=64
        arm64   ABI=standard
    }
}

test.run       yes
test.target    check
