# $Id$

PortSystem         1.0
PortGroup          python 1.0

categories-append  graphics math
name               py-matplotlib
version            1.1.0
maintainers        ram openmaintainer
platforms          darwin

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, wxpython).

homepage           http://matplotlib.sourceforge.net
master_sites       sourceforge:matplotlib
distname           matplotlib-${version}

checksums          md5 57a627f30b3b27821f808659889514c2 \
                   sha1 435b4f04a7e099b79f66451d69ad0b5ce66030ae \
                   rmd160 9313fc6407271c46f3ac5af4c53df5ea57982711

python.versions    24 25 26 27

if {${subport} == "py24-matplotlib"} {
  depends_lib-append port:py-dateutil \
                     port:py-tz \
                     port:py-numpy \
                     port:py-configobj \
                     port:py-pyobjc2 \
                     port:py-pyobjc2-cocoa
} elseif {${subport} != ${name}} {
  depends_lib-append port:py${python.version}-dateutil \
                     port:py${python.version}-tz \
                     port:py${python.version}-numpy \
                     port:py${python.version}-configobj \
                     port:py${python.version}-pyobjc-cocoa
}

if {$subport != $name} {

depends_lib-append port:freetype \
                   port:libpng

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

if {${configure.compiler} == "clang"} {
    configure.compiler llvm-gcc-4.2
}

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
}

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

post-activate {
  ui_msg "\nThe default backend is now the non-interactive Agg backend, different
backends can be specified using the ~/.matplotlib/matplotlibrc file.
More details, regarding backends, can be found in the matplotlib FAQ:
\nhttp://matplotlib.sourceforge.net/faq/installing_faq.html#what-is-a-backend\n"
}

variant cairo description "Enable Cairo backends" {
  if {${subport} == "py24-matplotlib"} {
    depends_lib-append port:py-cario
  } elseif {${subport} != ${name}} {
    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" {
  if {${subport} == "py24-matplotlib"} {
    depends_lib-append port:py-gtk
  } elseif {${subport} != ${name}} {
    depends_lib-append port:py${python.version}-gtk
  }
  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" {
  if {${subport} == "py24-matplotlib"} {
    depends_lib-append port:py-tkinter
  } elseif {${subport} != ${name}} {
    depends_lib-append port:py${python.version}-tkinter
  }
  post-patch {
    reinplace "s|^tkagg=False|tkagg=True|" ${worksrcpath}/setup.cfg
  }
}

variant wxpython description "Enable wxAgg backend" {
  if {${subport} == "py24-matplotlib"} {
    depends_lib-append port:py-wxpython
  } elseif {${subport} != ${name}} {
    depends_lib-append port:py${python.version}-wxpython
  }
  post-patch {
    reinplace "s|^wxagg=False|wxagg=True|" ${worksrcpath}/setup.cfg
  }
}

variant qt4 description "Enable QT4Agg backend" {
  if {${subport} == "py24-matplotlib"} {
    depends_lib-append port:py-pyqt4
  } elseif {${subport} != ${name}} {
    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
}

}

livecheck.type     regex
livecheck.url      ${homepage}
livecheck.regex    {Matplotlib (\d+(\.\d+)*) is available}