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

name                grads
version             2.2.1
revision            22
set branch          [join [lrange [split ${version} .] 0 1] .]
maintainers         {takeshi @tenomoto}
license             GPL-2
categories          science
description         interactive visualization tool for earth science data
master_sites        ftp://cola.gmu.edu/grads/${branch}/:src \
                    ftp://cola.gmu.edu/grads/:data
set gradssrc        ${name}-${version}-src${extract.suffix}
set gradsdata       data2${extract.suffix}
distfiles           ${gradssrc}:src ${gradsdata}:data
checksums           ${gradssrc} \
                    rmd160  498232b716b1bbda674976f38b421dd284d68900 \
                    sha256  695e2066d7d131720d598bac0beb61ac3ae5578240a5437401dc0ffbbe516206 \
                    size    5976570 \
                    ${gradsdata} \
                    rmd160 98637dd79e49335e0d986429549fbce2b81afc7a \
                    sha256 55419fe15478d8213031bb1bfa7adec96984379373ec751cbe37d4bb22f6ce18 \
                    size    1779887
set url http://cola.gmu.edu/grads/
homepage            ${url}
long_description   \
    The Grid Analysis and Display System (GrADS) is an interactive     \
    desktop tool that is used for easy access, manipulation, and       \
    visualization of earth science data. The format of the data may    \
    be either binary, GRIB, NetCDF, or HDF-SDS (Scientific Data Sets). \
    GrADS has been implemented worldwide on a variety of commonly used \
    operating systems and is freely distributed over the Internet.

depends_build       port:gadap
depends_lib         port:readline   \
                    port:netcdf     \
                    port:udunits    \
                    port:hdf4       \
                    port:hdf5       \
                    port:gd2        \
                    port:libdap     \
                    port:wgrib2     \
                    port:curl       \
                    port:libgeotiff \
                    port:shapelib   \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:xorg-libXmu
depends_build       port:pkgconfig

patchfiles          patch-configure.diff \
                    patch-src-Makefile.in.diff

post-patch {
   reinplace "s|/usr/local/lib|${prefix}/share|g" ${worksrcpath}/src/gxsubs.c
}

configure.env-append    SUPPLIBS=${prefix}
configure.args          --without-gui   \
                        --with-readline \
                        --with-grib2    \
                        --with-sdf      \
                        --with-gadap    \
                        --with-shp      \
                        --with-cairo=${prefix}    \
                        --with-geotiff=${prefix}  \
                        --with-hdf4=${prefix} \
                        --with-hdf5=${prefix} \
                        --with-netcdf=${prefix} \
                        --libdir=${prefix}/lib/${name} \
                        --with-x

configure.cflags-append \
                    -DH5_USE_110_API

test.run            yes
test.target         check

post-destroot {
    xinstall -d -m 755 ${destroot}${prefix}/share/${name}
    xinstall -m 644 {*}[glob -directory ${worksrcpath}/data *.dat *res] \
        ${destroot}${prefix}/share/${name}
    xinstall -d -m 755 ${destroot}${prefix}/share/${name}/tables
    xinstall -m 644 {*}[glob -directory ${worksrcpath}/data/tables *] \
        ${destroot}${prefix}/share/${name}/tables
    xinstall -m 644 ${filespath}/udpt ${destroot}${prefix}/share/${name}
    reinplace "s|PREFIX|${prefix}|" ${destroot}${prefix}/share/${name}/udpt
}

platform darwin 8 {
    configure.args-delete   --with-dap
    configure.args-append   --without-dap
}

livecheck.type      regex
livecheck.url       ${url}/downloads.php
livecheck.regex     {GrADS version (\d+\.\d+\.\d+) is the latest}
