# -*- 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                py-matplotlib
version             3.11.0
revision            1

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, qt5, cairo, latex).

homepage            https://matplotlib.org/

checksums           rmd160  8180addad5c559115b58995e21e28b81f3ebe3fb \
                    sha256  68c0c7be01b30dcca3638934f7f591df73401235cbdbf0d1ab1c71e7db7f8b57 \
                    size    33251176

python.versions     310 311 312 313 314
python.pep517_backend meson

if {${name} ne ${subport}} {
    if {${python.version} == 310} {
        version     3.10.9
        revision    0
        checksums   rmd160  6aac38c10194c0dc192350275956c7767c2dba61 \
                    sha256  fd66508e8c6877d98e586654b608a0456db8d7e8a546eb1e2600efd957302358 \
                    size    34811233
        patchfiles  patch-PY310-python-binary-meson.build.diff \
                    patch-PY310-meson-version-pyproject.toml.diff
    } else {
        patchfiles  patch-python-binary-meson.build.diff

        depends_lib-append \
                    port:libraqm

        build.args-append \
                    -Csetup-args=-Dsystem-libraqm=True
    }

    post-patch {
        reinplace "s|@@PYTHONBIN@@|${python.bin}|g" \
            ${worksrcpath}/meson.build
    }

    compiler.cxx_standard 2017

    depends_build-append \
                    port:py${python.version}-setuptools_scm \
                    path:bin/pkg-config:pkgconfig \
                    port:py${python.version}-certifi \
                    port:py${python.version}-pybind11 \
                    port:ninja

    depends_lib-append \
                    port:freetype \
                    port:qhull \
                    port:py${python.version}-contourpy \
                    port:py${python.version}-cycler \
                    port:py${python.version}-dateutil \
                    port:py${python.version}-fonttools \
                    port:py${python.version}-kiwisolver \
                    port:py${python.version}-numpy \
                    port:py${python.version}-parsing \
                    port:py${python.version}-packaging \
                    port:py${python.version}-Pillow

    build.args-append \
                    -Csetup-args=-Dsystem-freetype=True \
                    -Csetup-args=-Dsystem-qhull=True

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

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

    # do not build the 'macosx' backend when GCC is used as a compiler and/or on OSes before 10.12
    # see: https://trac.macports.org/ticket/61757
    if {[string match *gcc* ${configure.compiler}] || ${os.platform} eq "darwin" && ${os.major} < 16} {
        build.args-append \
                    -Csetup-args=-Dmacosx=False
    }

    # fix for missing symbols on 10.13 and below; see: https://trac.macports.org/ticket/71255
    if {${os.platform} eq "darwin" && ${os.major} < 18} {
        build.args-append \
                    -Csetup-args=-Db_lto=false
    }

    post-destroot {
        xinstall -d ${destroot}${prefix}/share/doc/${subport} \
            ${destroot}${prefix}/share/${subport}
        xinstall -m 0644 {*}[glob ${worksrcpath}/README.*] \
            ${destroot}${prefix}/share/doc/${subport}

        file copy ${worksrcpath}/galleries \
            ${destroot}${prefix}/share/${subport}
    }

    variant tkinter description "Enable TkAgg backend" {
        depends_lib-append  port:py${python.version}-tkinter
    }

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

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

    variant qt6 description "Enable Qt6Agg backend" {
        depends_lib-append  port:py${python.version}-pyqt6
    }

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

    if {${python.version} < 312} {
        variant pyside2 description "Enable PySide2 backend" {
            depends_lib-append  port:py${python.version}-pyside2
        }
    }

    variant pyside6 description "Enable PySide6 backend" {
        depends_lib-append  port:py${python.version}-pyside6
    }

    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 tkinter] && ![variant_isset qt5] && ![variant_isset pyside2]} {
            default_variants-append +cairo
    }

    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"
}
