# -*- 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           compiler_wrapper 1.0

name                py27-matplotlib
python.rootname     matplotlib
version             2.2.5
revision            4

categories-append   graphics math
license             {PSF BSD}
maintainers         {reneeotten @reneeotten} 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, gtk3, \
                    tkinter, qt4, qt5, cairo, latex).

homepage            https://matplotlib.org/

checksums           rmd160  4532a205e8f40d6f40346b2e461d3dca144b38b9 \
                    sha256  a3037a840cd9dfdc2df9fee8af8f76ca82bfab173c0f9468193ca7a89a2b60ea \
                    size    36678633

use_parallel_build  no

python.versions     27
python.pep517       no

compiler.cxx_standard 2011

depends_build-append \
                path:bin/pkg-config:pkgconfig \
                port:py${python.version}-setuptools

depends_lib-append \
                port:freetype \
                port:qhull \
                port:py${python.version}-cycler \
                port:py${python.version}-dateutil \
                port:py${python.version}-kiwisolver \
                port:py${python.version}-numpy \
                port:py${python.version}-parsing \
                port:libpng \
                port:py${python.version}-backports-functools_lru_cache \
                port:py${python.version}-six \
                port:py${python.version}-subprocess32 \
                port:py${python.version}-tz

if {${python.version} < 310} {
    depends_lib-append \
                port:py${python.version}-importlib-resources
}

set configfile setup.cfg

patchfiles  patch-setup.cfg.diff \
            patch-qhull.diff \
            patch-setupext.py.diff \
            patch-jquery-ui.diff \
            patch-src_ft2font.cpp.diff

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

post-patch {
    reinplace "s|@@PREFIX@@|${prefix}|" ${worksrcpath}/${configfile}
}

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

# jquery-ui is included in the PyPI files, patch added for setup.py that avoids trying
# to install if from the cache or download from URL. Just copy the directory in the post-
# build phase.
post-build {
    set libdir [glob -nocomplain ${worksrcpath}/build/lib*]
    if {![file exists ${libdir}/matplotlib/backends/web_backend/jquery-ui-1.12.1]} {
        file copy ${worksrcpath}/lib/matplotlib/backends/web_backend/jquery-ui-1.12.1 \
            ${libdir}/matplotlib/backends/web_backend/ \
    }
}

build.env-append \
                PKG_CONFIG_PATH=${python.prefix}/lib/pkgconfig \
                CFLAGS=${configure.cxxflags} \
                CXXFLAGS=${configure.cxxflags} \

destroot.env-append \
                PKG_CONFIG_PATH=${python.prefix}/lib/pkgconfig \
                CFLAGS=${configure.cxxflags} \
                CXXFLAGS=${configure.cxxflags} \

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

# additionally on Leopard the macosx backend cannot be compiled anymore, see Trac ticket:
# https://trac.macports.org/ticket/61757
# this is a compiler issue, not OS version issue; this backend should be disabled for gcc.
# cc1obj: error: '-Werror=unguarded-availability': no option '-Wunguarded-availability'
# src/_macosx.m: error: incompatible type for argument 1 of 'updateDevicePixelRatio'
# src/_macosx.m: error: incompatible types when initializing type 'CGFloat' {aka 'float'} using type 'id'
if {[string match *gcc* ${configure.compiler}]} {
    post-patch {
        reinplace "s|^macosx=True|macosx=False|" ${worksrcpath}/${configfile}
    }
}

post-destroot {
    xinstall -d ${destroot}${prefix}/share/doc/${subport} \
        ${destroot}${prefix}/share/${subport}
    xinstall -m 0644 {*}[glob ${worksrcpath}/README.*] \
        ${destroot}${prefix}/share/doc/${subport}
    xinstall -m 0644 -W ${worksrcpath} matplotlibrc.template \
        ${destroot}${prefix}/share/doc/${subport}
    file copy ${worksrcpath}/examples \
        ${destroot}${prefix}/share/${subport}
}

variant webagg description "Enable WebAgg backend" {
    depends_lib-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}/${configfile}
    }
}

variant gtk3 description "Enable GTK3Agg backend" {
    depends_lib-append  port:py${python.version}-gobject3 \
                        path:lib/pkgconfig/gtk+-3.0.pc:gtk3

    post-patch {
        reinplace "s|^gtk3agg=False|gtk3agg=True|" ${worksrcpath}/${configfile}
    }
}

variant qt5 description "Enable Qt5Agg backend" {
    depends_lib-append  port:py${python.version}-pyqt5

    post-patch {
        reinplace "s|^qt5agg=False|qt5agg=True|" ${worksrcpath}/${configfile}
    }
}

variant cairo description "Enable Cairo backends" {
    depends_lib-append  port:py${python.version}-cairo

    post-patch {
        reinplace "s|^cairo=False|cairo=True|" ${worksrcpath}/${configfile}
    }
}

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
}

default_variants +webagg

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

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

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:

    https://matplotlib.org/stable/users/explain/backends.html"

livecheck.type      none
