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

PortSystem          1.0
PortGroup           muniversal 1.0

name                pari
version             2.17.0
revision            0
categories          math
license             GPL-2+
maintainers         {gmail.com:watsonbladd @wbl} openmaintainer

description         PARI/GP computer algebra system

long_description    PARI/GP is a widely used computer algebra system designed \
                    for fast  computations in number theory (factorizations, \
                    algebraic number theory,  elliptic curves...)

homepage            https://pari.math.u-bordeaux.fr/
master_sites        ${homepage}pub/pari/unix/

checksums           rmd160  78d1611172282144f8de308e01bfee97839c4eae \
                    sha256  e723e7cef18d08c6ece2283af9a9b4d56077c22b4fce998faaa588d389b1aea8 \
                    size    5317997

depends_lib         port:gmp \
                    port:ncurses \
                    port:readline

platform darwin 8 {
    build.args-append EXTRADLLDFLAGS="-Wl,-single_module"
    destroot.args-append EXTRADLLDFLAGS="-Wl,-single_module"
}

# llvm-gcc produces incorrect code, ticket #33024
compiler.blacklist-append llvm-gcc-4.2

# See: https://trac.macports.org/ticket/59295
compiler.blacklist-append {clang}

configure.cmd       ./Configure

# PARI/GP doesn't use autoconf, and if only *FLAGS environment variables are
# used, libreadline is not found. One needs *PATH environment variables.
configure.env       C_INCLUDE_PATH=${prefix}/include

# Always use GMP (forced by --with-gmp), as advised by the PARI developers:
#   http://www.math.u-bordeaux.fr/~belabas/pari/doc/faq.html#gnump
# There are no reasons not to use it. If a no_gmp variant is needed,
# one would need --without-gmp, as by default, PARI's Configure will
# choose GMP if it can find it.
configure.args      --mandir=${prefix}/share/man \
                    --with-gmp \
                    --with-readline \
                    --graphic=none
configure.universal_args-delete --disable-dependency-tracking

set merger_must_run_binaries yes

# pari does not build for ppc on intel
if {${build_arch} eq "i386" || ${build_arch} eq "x86_64"} {
    supported_archs i386 x86_64
} elseif {${build_arch} eq "ppc" || ${build_arch} eq "ppc64"} {
    supported_archs ppc ppc64
}
set universal_archs_supported ${supported_archs}

post-patch {
    if {![variant_isset doc]} {
        reinplace "s/\\(doc all:\\).*/\\1/" \
            ${worksrcpath}/config/DOC_Make.SH
    }
}

build.args-append   CPLUSPLUS=${configure.cxx}

build.target        gp

post-destroot {
    set docdir ${destroot}${prefix}/share/doc/${name}
    file mkdir ${docdir}
    xinstall -m 644 -v -W ${worksrcpath} \
        AUTHORS CHANGES COPYING ${docdir}
    ln -s ../../${name}/doc ${docdir}/doc
}

variant doc description {Build DVI/PDF/PS documentation} {
    depends_build-append path:bin/tex:texlive
    build.target-append docpdf
    post-destroot {
        if {[variant_exists universal] && [variant_isset universal]} {
            set dir ${worksrcpath}-[lindex ${universal_archs_to_use} 0]
        } else {
            set dir ${worksrcpath}
        }
        xinstall -m 644 -W ${dir}/doc \
            develop.pdf libpari.pdf refcard.pdf tutorial.pdf users.pdf \
            ${destroot}${prefix}/share/${name}/doc
    }
}

# Qt support doesn't work with:
#   depends_lib-append port:qt4-mac
#   configure.args-delete --graphic=none
#   configure.args-append --graphic=Qt --with-qt=${prefix}
# Configure succeeds, but the build of src/graph/plotQt.c fails because
# ${prefix}/include/Qt is not in the include search path.

# Plotting works with X11, but the redraw after a window resize is
# sometimes incorrect.
variant x11 conflicts fltk description {Build with X11 support for the high-resolution plotting functions} {
    depends_lib-append port:xorg-libX11
    configure.args-delete --graphic=none
    configure.args-append --graphic=X11
}

# Plotting works with fltk @1.1.10_3, but the GUI part freezes
# (a Force Quit is needed).
variant fltk conflicts x11 description {Build with FLTK support for the high-resolution plotting functions} {
    depends_lib-append path:lib/libfltk.dylib:fltk
    configure.args-delete --graphic=none
    configure.args-append --graphic=fltk
}

variant mt description {Build multithreaded} {
    configure.args-append --mt=pthread
}

platform darwin 10 powerpc {
    # Without this settings get wrong in Rosetta:
    # Building for: i386 running darwin (ix86/GMP kernel) 32-bit version
    patchfiles-append patch-rosetta.diff
}

livecheck.type      regex
livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     ${name}-(\\d+\\.\\d+\\.\\d+)
