# -*- 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
# $Id: Portfile 67899 2010-05-21 09:19:17Z takeshi@macports.org $

PortSystem 1.0

name                grads
version             1.9b4
revision            7
platforms           darwin
maintainers         takeshi
categories          science
description         interactive visualization tool for earth science data
master_sites        ftp://grads.iges.org/grads/1.9/:src \
                    ftp://grads.iges.org/grads/:data
set gradssrc        ${name}-src-${version}${extract.suffix}
set gradsdata       data.tar.Z
distfiles           ${gradssrc}:src ${gradsdata}:data
checksums           ${gradssrc}  sha1 839e32693602e2695825d4d5a1a8ae7e1672c3a5 \
                    ${gradsdata} sha1 6a3e997868b358ecf71ea618c27ad10f28183f5e
homepage            http://www.iges.org/grads/grads.html
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_lib         port:libwww     port:readline   port:rx   \
                    port:netcdf     port:udunits    port:hdf4 \
                    port:libnc-dap  port:gd2

patchfiles          patch-configure.diff patch-grads.h.diff    \
                    patch-wgrib.c.diff   patch-bufrscan.c.diff \
                    patch-gacfg.c.diff   patch-gxhpng.c.diff

post-patch {
    reinplace "s|/usr/local|${prefix}|" ${worksrcpath}/src/gx.h
}

configure.env       SUPPLIBS=${prefix} LIBS=-lsz
configure.args      --with-readline --with-lats \
                    --with-nc --with-dods --with-hdf --with-x      \
                    --with-printim --without-gui
configure.cppflags-delete   -I${prefix}/include
configure.cppflags-append   -I${prefix}/lib/jpeg6b/include -I${prefix}/include
configure.ldflags-delete    -L${prefix}/lib 
configure.ldflags-append    -L${prefix}/lib/jpeg6b/lib -L${prefix}/lib 

post-configure {
    reinplace "s|libjpeg.a|jpeg6b/lib/libjpeg.a|" ${worksrcpath}/src/Makefile
    reinplace "s|libwww.a|libwwwcore.a|g" ${worksrcpath}/src/Makefile
    reinplace "s|\$(supp_lib_dir)/inst.o| |g" ${worksrcpath}/src/Makefile
}

post-destroot {
    xinstall -d -m 755 ${destroot}${prefix}/share/${name}/
    foreach file [glob -directory ${workpath} *.dat *res] {
        file rename ${file} ${destroot}${prefix}/share/${name}/
    }
    system "ln -s ${prefix}/bin/${name}dods ${destroot}${prefix}/bin/${name}"
}
