# $Id: Portfile 106539 2013-05-30 09:50:16Z robitaille@macports.org $

PortSystem         1.0
PortGroup          python 1.0
PortGroup          github 1.0

categories-append  graphics math
github.setup       matplotlib matplotlib 1.2.1 v
name               py-matplotlib
homepage           http://matplotlib.org/
master_sites       https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.2.1/
maintainers        sean openmaintainer
platforms          darwin
license            {PSF BSD}

description        matlab-like syntax for creating plots in python
long_description   Matplotlib is a pure python plotting library with the \
                   goal of making publication quality plots using a syntax \
                   familiar to matlab users. 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).

checksums          rmd160 c27142f1d6665bc6a748f601558045e7d801dbef \
                   sha256 52e18972aed85f30b05cef41778ec77685df6012f0598cd216e996de9b9ea29b

python.versions    26 27 31 32 33

if {$subport != $name} {

depends_build-append \
                   port:pkgconfig

depends_lib-append port:freetype \
                   port:libpng \
                   port:py${python.version}-dateutil \
                   port:py${python.version}-tz \
                   port:py${python.version}-numpy \
                   port:py${python.version}-pyobjc-cocoa

patchfiles         patch-setupext.py.diff \
                   patch-setup.cfg.diff

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

post-patch {
  reinplace "s|@@MPORTS_PREFIX@@|${prefix}|" ${worksrcpath}/setupext.py
  reinplace "s|@@PYTHON_BRANCH@@|${prefix}|" ${worksrcpath}/setupext.py
}

# build fails with gcc-4.0 on Leopard, use gcc-4.2 (#37069)
if {${configure.compiler} == "gcc-4.0"} {
   configure.compiler gcc-4.2
}

post-destroot {
  if {${name} != ${subport}} {
  xinstall -m 755 -d ${destroot}${prefix}/share/doc/${subport} \
    ${destroot}${prefix}/share/${subport}
  xinstall -m 644 -W ${worksrcpath} CHANGELOG README.txt TODO \
    ${destroot}${prefix}/share/doc/${subport}
  file copy ${worksrcpath}/examples \
    ${destroot}${prefix}/share/${subport}
  }
}

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

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

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

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

variant latex description "Enable LaTeX support" {
  depends_lib-append bin:latex:texlive
  post-patch {
    reinplace "s|MP_LaTeX=False|MP_LaTeX=True|" ${worksrcpath}/setupext.py
  }
}

variant ghostscript description "Enable GhostScript support" {
  depends_lib-append port:ghostscript
  post-patch {
    reinplace "s|MP_GhostScript=False|MP_GhostScript=True|" ${worksrcpath}/setupext.py
  }
}

if { ![variant_isset gtk2] && ![variant_isset tkinter] && ![variant_isset qt4] } {
  default_variants   +tkinter
}

}

if {${name} == ${subport}} {
  livecheck.regex    archive/[join ${github.tag_prefix} ""](\[\\d+(?:\\.\\d+)*"\]+)${extract.suffix}"
} else {
  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
"
}
