# $Id: Portfile 79965 2011-07-01 01:10:42Z vinc17@macports.org $

PortSystem 1.0
PortGroup  muniversal 1.0

name                pari
version             2.5.0
categories          math
platforms           darwin
maintainers         vinc17 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            http://pari.math.u-bordeaux.fr/
master_sites        ${homepage}/pub/pari/unix/
checksums           md5     0b595a1345679ff482785a686c863e9f \
                    sha1    d96250cd8b3e426f548a832f2f44fdfd30fd32b6 \
                    rmd160  f9b5375da10bfc5672fbe8b4ab4ac1eb0772b572
depends_lib         port:gmp port:ncurses port:readline

build.target        gp

# 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 \
                    LIBRARY_PATH=${prefix}/lib

# 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

patchfiles patch-Makefile.SH.diff

post-patch {
    reinplace "s|-dylib_|-|g" \
      ${worksrcpath}/config/Makefile.SH \
      ${worksrcpath}/config/get_dlld
}

pre-configure {
    file rename -force ${worksrcpath}/Configure ${worksrcpath}/configure
    if {![variant_isset doc]} {
      reinplace "s/\\(doc all:\\).*/\\1/" \
        ${worksrcpath}/config/DOC_Make.SH
      reinplace "/INSTALL_DATA.*\\.\\(dvi\\|ps\\)/d" \
        ${worksrcpath}/config/Makefile.SH
    }
}

variant doc description {Build DVI/PDF/PS documentation} {
    depends_build-append path:${prefix}/bin/tex:texlive
    build.target-append docpdf
}

# 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 port:fltk
    configure.args-delete --graphic=none
    configure.args-append --graphic=fltk
}

post-destroot {
    global os.arch
    set docdir ${destroot}${prefix}/share/doc/${name}
    file mkdir ${docdir}
    xinstall -m 644 -v -W ${worksrcpath} \
      AUTHORS CHANGES COPYING ${docdir}
    system "ln -s ../../${name}/doc ${docdir}/doc"
    if {[variant_isset doc]} {
        if {[variant_isset universal]} {
            xinstall -m 644 -v -W ${worksrcpath}-${os.arch}/doc \
              develop.pdf libpari.pdf refcard.pdf tutorial.pdf users.pdf \
              ${destroot}${prefix}/share/${name}/doc
        } else {
            xinstall -m 644 -v -W ${worksrcpath}/doc \
              develop.pdf libpari.pdf refcard.pdf tutorial.pdf users.pdf \
              ${destroot}${prefix}/share/${name}/doc
        }
    }
}

livecheck.type      regex
livecheck.url       ${master_sites}?M=D
livecheck.regex     ${name}-(\\d+\\.\\d+\\.\\d+)
