# $Id: Portfile 67323 2010-05-05 15:51:10Z vinc17@macports.org $

PortSystem 1.0
PortGroup  muniversal 1.0

name                pari
version             2.3.5
revision            1
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     6077c6db56fdd32e39a06a9bf320e1f7 \
                    sha1    f211ccfe42a4b18dbcde832dfd1ece6f477f4966 \
                    rmd160  488adf3af5398d0ab5390eb86b65cd79bd1044c5
depends_lib         port:xorg-libX11 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

configure.args      --mandir=${prefix}/share/man --with-readline
configure.universal_args-delete --disable-dependency-tracking

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
}

variant gmp description {GNU MP support} {
    depends_lib-append port:gmp
    configure.args-append --with-gmp
}

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+)
