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

name                py-ngl
version             1.3.0b1
revision            2
categories-append   science
platforms           darwin
license             PyNGL
maintainers         {petr @petrrr} openmaintainer

description         Python module to visualize scientific data
long_description \
    PyNGL is a Python language module used to visualize scientific data, \
    with an emphasis on high-quality 2D visualizations.

homepage            http://www.pyngl.ucar.edu/
distname            PyNGL-${version}

master_sites        https://www.earthsystemgrid.org/download/fileDownload.htm?logicalFileId=40003c7a-306d-11df-8e89-00c0f03d5b7c&dummy=

checksums           md5     231e0ad8ab7f295483f131367ab856cc \
                    rmd160  bd4357d46af0a723cd81c16bdb0ecc3df03fa6a2 \
                    sha256  0666f605033609680f3e7312ae412a5a5b8792bc8f423b3cae3ae3e4af235a25

python.versions     27

if {${name} ne ${subport}} {
    depends_lib-append  port:zlib \
                        port:libpng \
                        port:xorg-libX11 \
                        port:py${python.version}-nio

    # ncarg is not universal, thus py-ngl isn't either
    universal_variant   no

    patch {
        reinplace "s|/usr/X11R6/lib|${prefix}/lib|" ${worksrcpath}/setup.py
        reinplace "s|/usr/bin/env python|${python.bin}|" ${worksrcpath}/examples/pynglex
        reinplace "s|py_cmd = 'python'|py_cmd = '${python.bin}'|" ${worksrcpath}/examples/pynglex
    }

    build.env           PNG_PREFIX=${prefix} \
                        ZLIB_PREFIX=${prefix} \
                        NCARG_ROOT=${prefix} \
                        CC=${configure.cc}

    destroot.env        NCARG_ROOT=${prefix}

    compilers.choose    fc f77 f90
    compilers.setup     require_fortran

    if {[gcc_variant_isset]} {
        build.env-append    F2CLIBS=gfortran \
                            F2CLIBS_PREFIX=${prefix}/lib/[gcc_variant_name]
    } else {
        # g95
        configure.fflags-append -fno-second-underscore

        build.env-append    F2CLIBS=f95 \
                            F2CLIBS_PREFIX=${prefix}/lib/
    }

    test.run                yes
    python.test_framework
    test.cmd                ${python.bin} ./build/scripts-${python.branch}/pynglex
    test.args               -w x11 ngl01p
} else {
    livecheck.type   regex
    livecheck.url    http://www.pyngl.ucar.edu/Download/
    livecheck.regex  {of PyNGL is ([0-9]\.[0-9]\.[0-9]+)}
}
