# -*- 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           python 1.0
PortGroup           github 1.0

github.setup        matplotlib matplotlib 2.2.2 v

name                py-matplotlib
categories-append   graphics math
platforms           darwin
license             {PSF BSD}

python.versions     27 34 35 36

maintainers         sean openmaintainer

description         Matplotlib is a python plotting library

long_description    Matplotlib strives to produce publication quality 2D \
                    graphics for interactive graphing, scientific publishing, \
                    user interface development and web application servers \
                    targeting multiple user interfaces and hardcopy output \
                    formats. There is a 'pylab' mode which emulates matlab \
                    graphics. The library uses numpy for handling large data \
                    sets and supports a variety of output backends. This port \
                    provides variants for the different GUIs (gtk2, tkinter, \
                    qt4, cairo, latex).

homepage            http://matplotlib.org/

checksums           rmd160  94ea2604a9473aba40a065027caf06d42e775e6e \
                    sha256  bf08dc0347ddcdce02dca22c20f89d760a459bcb6ba793fa002b6b8925f66c68 \
                    size    36595100

if {${name} ne ${subport}} {
    depends_build-append \
                        port:pkgconfig

    depends_lib-append  port:freetype \
                        port:libpng \
                        port:qhull \
                        port:py${python.version}-dateutil \
                        port:py${python.version}-numpy \
                        port:py${python.version}-parsing \
                        port:py${python.version}-pyobjc-cocoa \
                        port:py${python.version}-six \
                        port:py${python.version}-tornado \
                        port:py${python.version}-tz \
                        port:py${python.version}-cycler \
                        port:py${python.version}-kiwisolver

    if {${python.version} == 27} {
        depends_lib-append port:py27-functools32 \
                           port:py27-subprocess32 \
                           port:py27-backports-functools_lru_cache
    }

    patchfiles-append   patch-setup.cfg.diff \
                        patch-setupext.py.diff \
                        patch-src-macosx.m.diff

    build.env           PKG_CONFIG_PATH="${python.prefix}/lib/pkgconfig"

    post-patch {
        reinplace "s|@@PREFIX@@|${prefix}|" ${worksrcpath}/setup.cfg
    }

    # build fails with gcc-4.0 on Leopard, use gcc-4.2 (#37069)
    compiler.blacklist gcc-4.0

    post-destroot {
        if {${name} ne ${subport}} {
            xinstall -m 755 -d ${destroot}${prefix}/share/doc/${subport} \
                ${destroot}${prefix}/share/${subport}
            xinstall -m 644 -W ${worksrcpath} README.rst matplotlibrc.template \
                ${destroot}${prefix}/share/doc/${subport}
            file copy ${worksrcpath}/examples \
                ${destroot}${prefix}/share/${subport}
        }
    }

    variant webagg description "Enable WebAgg backend" {
        depends_run-append  port:py${python.version}-tornado
    }

    variant tkinter description "Enable tkAgg backend" {
        depends_lib-append  port:py${python.version}-tkinter
        post-patch {
            reinplace "s|^tkagg=False|tkagg=True|" ${worksrcpath}/setup.cfg
        }
    }

    if {${python.version} < 30} {
        variant gtk2 description "Enable GTKAgg backend" {
            depends_lib-append  port:py${python.version}-pygtk
            post-patch {
                reinplace "s|^gtk=False|gtk=True|" ${worksrcpath}/setup.cfg
                reinplace "s|^gtkagg=False|gtkagg=True|" ${worksrcpath}/setup.cfg
            }
        }
    }

    if {${python.version} == 27} {
        variant gtk3 description "Enable GTK3Agg backend" {
            depends_lib-append  port:py${python.version}-gobject3 port:gtk3
            post-patch {
                reinplace "s|^gtk3agg=False|gtk3agg=True|" ${worksrcpath}/setup.cfg
            }
        }
    }

    variant qt4 description "Enable QT4Agg backend" {
        depends_lib-append  port:py${python.version}-pyqt4
        post-patch {
            reinplace "s|^qt4agg=False|qt4agg=True|" ${worksrcpath}/setup.cfg
        }
    }

    if {${python.version} == 27 ||
        ${python.version} == 34 ||
        ${python.version} == 35 ||
        ${python.version} == 36} {
        variant pyside description "Enable PySide backend" {
            depends_lib-append  port:py${python.version}-pyside
            post-patch {
                reinplace "s|^pyside=False|pyside=True|" ${worksrcpath}/setup.cfg
            }
        }
    }

    variant cairo description "Enable Cairo backends" {
        depends_lib-append  port:py${python.version}-cairo
        post-patch {
            reinplace "s|^cairo=False|cairo=True|" ${worksrcpath}/setup.cfg
        }
    }

    variant dvipng description "Enable dvipng support" {
        depends_run-append  port:dvipng
    }

    variant ghostscript description "Enable GhostScript support" {
        depends_run-append  port:ghostscript
    }

    variant latex description "Enable LaTeX support" {
        depends_run-append  bin:latex:texlive
    }

    variant pdftops description "Enable pdftops support" {
        depends_run-append  bin:pdftops:poppler
    }

    if { ![variant_isset gtk2] && ![variant_isset tkinter] && ![variant_isset qt4] && ![variant_isset pyside] } {
        default_variants-append +cairo
    }

    post-patch {
        reinplace "s|^agg=False|agg=True|" ${worksrcpath}/setup.cfg
        if {[variant_isset gtk3] && [variant_isset cairo]} {
            reinplace "s|^gtk3cairo=False|gtk3cairo=True|" ${worksrcpath}/setup.cfg
        }
    }

    livecheck.type      none

    notes "
The default backend is the interactive Mac OS X backend. Different\
backends can be specified using the ~/.matplotlib/matplotlibrc file.\
More details regarding backends can be found in the matplotlib FAQ:

http://matplotlib.sourceforge.net/faq/installing_faq.html#what-is-a-backend
"
} else {
    github.livecheck.regex  {([\d+(?:.\d+)*"]+)}
}