# -*- 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 106253 2013-05-20 15:51:45Z jeremyhu@macports.org $

PortSystem          1.0

name                grib_api
version             1.9.18
revision            1
platforms           darwin
maintainers         takeshi
license             LGPL
categories          science
description         GRIB decoder
homepage            https://software.ecmwf.int/wiki/display/GRIB/Home
master_sites        https://software.ecmwf.int/wiki/download/attachments/3473437
checksums           md5     94c03e18f4e1e166048057929feb0d1a \
                    sha1    87616917a6978a56ae4fe173a3e6e3828b0ebfba \
                    rmd160  f44eeb38ee1d9fc453f0078971f9b0aab8f4c0f5
long_description \
    The ECMWF GRIB API is an application program interface accessible \
    from C and FORTRAN programs developed for encoding and decoding   \
    WMO FM-92 GRIB edition 1 and edition 2 messages. A useful set of  \
    command line tools is also provided to give quick access to grib messages.

depends_lib         port:jasper \
                    port:openjpeg15 \
                    port:libpng

fetch.ignore_sslcert    yes

post-patch {
    if {${os.major} == 8} {
        reinplace "s| -Wl,-rpath \$fortranlibdir||" ${worksrcpath}/configure
    }
    reinplace "s|share\/samples|share/$name/samples|" ${worksrcpath}/configure
    reinplace "s|share\/samples|share/$name/samples|" ${worksrcpath}/configure
    reinplace "s|share\/definitions|share/$name/definitions|" ${worksrcpath}/configure
    reinplace "s|'none'|''|" ${worksrcpath}/configure
    reinplace "s|-fno-common||" ${worksrcpath}/configure
}

configure.args      --disable-dependency-tracking \
                    --disable-fortran \
                    --with-ifs-samples=${prefix}/share/${name}/ifs_samples \
                    --with-jasper=${prefix} \
                    --with-openjpeg=${prefix} \
                    --with-png-support=${prefix} \
                    --disable-python

test.run            yes
test.target         check

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    eval xinstall -m 644 [glob ${worksrcpath}/html/*.html] \
        ${destroot}${prefix}/share/doc/${name}
    foreach b {parser points} {
        file rename ${destroot}${prefix}/bin/${b} ${destroot}${prefix}/bin/grib_${b}
    }
}

variant emos description {deprecated to remove dependency to emos} {
}

variant gcc43 conflicts g95 gcc44 gcc45 gcc46 gcc47 description {builds fortran interface with gfortran 4.3} {
    depends_build-append    port:gcc43
    configure.args-delete   --disable-fortran
    configure.compiler      macports-gcc-4.3
    configure.args-append   --with-fortranlibdir=${prefix}/lib/gcc43 \
                            --with-fortranlibs=-lgfortran
}

variant gcc44 conflicts g95 gcc43 gcc45 gcc46 gcc47 description {builds fortran interface with gfortran 4.4} {
    depends_build-append    port:gcc44
    configure.args-delete   --disable-fortran
    configure.compiler      macports-gcc-4.4
    configure.args-append   --with-fortranlibdir=${prefix}/lib/gcc44 \
                            --with-fortranlibs=-lgfortran
}

variant gcc45 conflicts g95 gcc43 gcc44 gcc46 gcc47 description {builds fortran interface with gfortran 4.5} {
    depends_build-append    port:gcc45
    configure.args-delete   --disable-fortran
    configure.compiler      macports-gcc-4.5
    configure.args-append   --with-fortranlibdir=${prefix}/lib/gcc45 \
                            --with-fortranlibs=-lgfortran
}

variant gcc46 conflicts g95 gcc43 gcc44 gcc45 gcc47 description {builds fortran interface with gfortran 4.6} {
    depends_build-append    port:gcc46
    configure.args-delete   --disable-fortran
    configure.compiler      macports-gcc-4.6
    configure.args-append   --with-fortranlibdir=${prefix}/lib/gcc46 \
                            --with-fortranlibs=-lgfortran
}

variant gcc47 conflicts g95 gcc43 gcc44 gcc45 gcc46 description {builds fortran interface with gfortran 4.7} {
    depends_build-append    port:gcc47
    configure.args-delete   --disable-fortran
    configure.compiler      macports-gcc-4.7
    configure.args-append   --with-fortranlibdir=${prefix}/lib/gcc47 \
                            --with-fortranlibs=-lgfortran
}

variant g95 conflicts gcc43 gcc44 gcc45 gcc46 gcc47 emos universal description {builds fortran interface with g95} {
    depends_build-append    port:g95
    configure.args-delete   --disable-fortran
    configure.fc            ${prefix}/bin/g95
    configure.f77           ${configure.fc}
    configure.args-append   --with-fortranlibdir=${prefix}/lib \
                            --with-fortranlibs=-lf95
}

variant python25 conflicts python26 python27 description {Add support for python25} {
    depends_lib-append      port:py25-numpy
    configure.args-delete   --disable-python
    configure.args-append   --enable-python
    configure.env-append    PYTHON=${prefix}/bin/python2.5 \
                            PYTHON_CONFIG=${prefix}/bin/python2.5-config
}

variant python26 conflicts python25 python27 description {Add support for python26} {
    depends_lib-append      port:py26-numpy
    configure.args-delete   --disable-python
    configure.args-append   --enable-python
    configure.env-append    PYTHON=${prefix}/bin/python2.6 \
                            PYTHON_CONFIG=${prefix}/bin/python2.6-config
}

variant python27 conflicts python25 python26 description {Add support for python27} {
    depends_lib-append      port:py27-numpy
    configure.args-delete   --disable-python
    configure.args-append   --enable-python
    configure.env-append    PYTHON=${prefix}/bin/python2.7 \
                            PYTHON_CONFIG=${prefix}/bin/python2.7-config
}
