# -*- 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 55371 2009-08-09 23:20:41Z takeshi@macports.org $

PortSystem 1.0

name                wgrib2
version             1.7.8j
revision            1
platforms           darwin
maintainers         takeshi
categories          science
description         program to read atmospheric data files in GRIB2
master_sites        ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/
distname            ${name}.tgz.v${version}
extract.suffix     
set version_g2clib  1.1.8
worksrcdir          grib2/g2clib-${version_g2clib}
checksums           md5    f4625d0b3b6b276a7ee256bb31aa04d5         \
                    sha1   430b5cca611fba2ebc5bf14fc00142b26998bdbd \
                    rmd160 763e5108dc2e93e2a4079177c31b567910b7ab63
homepage            http://www.cpc.noaa.gov/products/wesley/wgrib2/
long_description   \
    wgrib2 is a swiss army knife for grib2 files. \
    GRIB-2 has arrived and has begun replacing the the older standard GRIB-1. \
    GRIB-2 can reduce the file size by up to 80% (NAM, JPEG2000 compression).

depends_lib         port:jasper port:libpng port:netcdf

use_configure       no
use_parallel_build  no

set cppflags ${configure.cppflags}
if {[variant_isset universal]} {
    set cflags "${configure.cflags} ${configure.universal_cflags}"
    set ldflags "${configure.ldflags} ${configure.universal_ldflags}"
} else {
    set cflags ${configure.cflags}
    set ldflags ${configure.ldflags}
}
build.args          "-f makefile CPPFLAGS=\"${cppflags}\" CFLAGS=\"${cflags}\""

post-build  { 
    system "ranlib ${worksrcpath}/libgrib2c.a" 
    if {[variant_isset netcdf4]} {
        system "cd ${worksrcpath}/../wgrib2; \
            make -f makefile ${name} \
            CFLAGS=\"-I../g2clib-${version_g2clib} ${cppflags} ${cflags} \
                           -DUSE_NETCDF4 -UUSE_NETCDF3\"  \
            LDFLAGS=\"-L../g2clib-${version_g2clib} ${ldflags} \
                           -lgrib2c -ljasper -lnetcdf -lhdf5_hl -lhdf5 -lpng -lz\" "
    } else {
        system "cd ${worksrcpath}/../wgrib2; \
            make -f makefile ${name} \
            CFLAGS=\"-I../g2clib-${version_g2clib} ${cppflags} ${cflags} \
                           -UUSE_NETCDF4\"  \
            LDFLAGS=\"-L../g2clib-${version_g2clib} ${ldflags} \
                           -lgrib2c -ljasper -lnetcdf -lpng -lz\" "
    }
}

destroot {
    xinstall -m 755 ${worksrcpath}/grib2.h ${destroot}${prefix}/include
    xinstall -m 755 ${worksrcpath}/libgrib2c.a ${destroot}${prefix}/lib
    xinstall -m 755 ${worksrcpath}/../${name}/${name} ${destroot}${prefix}/bin
}

variant netcdf4 description {use netcdf4} {
    depends_lib-append  port:hdf5-18
}
