# -*- 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 66387 2010-04-10 22:54:35Z takeshi@macports.org $

PortSystem 1.0

name                wgrib2
version             1.8.3
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     b7ccf7dbd9c9a43cb6da59c978432ed2 \
                    sha1    b2268a8a51675dabf12c20af98d6a9fdd2261138 \
                    rmd160  89eaad5c0f351d5842cce888b7da01487622c934
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-devel \
                    port:hdf5-18

use_configure       no
use_parallel_build  no

default_variants    netcdf4

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} ${configure.cc_archflags}"
    set ldflags "${configure.ldflags} ${configure.cc_archflags}"
}
build.args          "-f makefile CC=\"${configure.cc}\" CPPFLAGS=\"${cppflags}\" CFLAGS=\"${cflags}\""

post-build  { 
    system "ranlib ${worksrcpath}/libgrib2c.a" 
    system "cd ${worksrcpath}/../wgrib2; \
            make -f makefile ${name} \
            CC=\"${configure.cc}\" \
            CFLAGS=\"-I../g2clib-${version_g2clib} -I${prefix}/lib/netcdf-devel/include ${cppflags} ${cflags} \
                           -DUSE_NETCDF4 -UUSE_NETCDF3\"  \
            LDFLAGS=\"-L../g2clib-${version_g2clib} -L${prefix}/lib/netcdf-devel/lib ${ldflags} \
                           -lgrib2c -ljasper -lpng -lnetcdf -lhdf5_hl -lhdf5 -lz -lsz -lcurl -lidn -lssl -lcrypto\" "
}

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
}
