# -*- coding: utf-8; mode: tcl; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; truncate-lines: t -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 78622 2011-05-14 18:56:57Z mmoll@macports.org $

PortSystem          1.0
PortGroup           muniversal 1.0

set realname        hdf5
name                ${realname}-18
version             1.8.7
revision            1
categories          science
maintainers         mmoll openmaintainer

description         HDF5 general purpose library and file format for storing scientific data
long_description    ${description}
homepage            http://www.hdfgroup.org/HDF5/
platforms           darwin
conflicts           hdf5
master_sites        http://www.hdfgroup.org/ftp/HDF5/current/src \
                    ftp://ftp.hdfgroup.org/HDF5/current/src/ \
                    ftp://ftp.hdfgroup.org/HDF5/prev-releases/hdf5-${version}/src/
checksums           md5     8859e2abc5258596302c7618722a48ad \
                    sha1    be1daff26f066aca0b5be52d86dada6757fc4b95 \
                    rmd160  34641bf8e664c3b3382d1346a65e2f5c3eb485ee
distname            ${realname}-${version}
use_bzip2           yes
depends_lib         port:zlib port:szip
use_parallel_build  yes

configure.args      --with-zlib=yes --with-szlib=yes --enable-filters=all \
                    --enable-production --disable-fortran \
                    --enable-cxx --enable-shared --enable-static \
                    --disable-parallel

post-configure {
    if {[variant_isset universal]} {
        set dirs {}
        foreach arch ${universal_archs_to_use} {
            lappend dirs ${worksrcpath}-${arch}
        }
    } else {
        set dirs ${worksrcpath}
    }
    foreach dir ${dirs} {
        reinplace -E {s|-arch [a-z0-9_]+||g} \
            ${dir}/tools/misc/h5cc \
            ${dir}/c++/src/h5c++ \
            ${dir}/src/libhdf5.settings \
            ${dir}/fortran/src/h5fc
    }
}

test.run            yes
test.target         check

variant threadsafe description {Enable threadsafety (experimental and un-supported, disables cxx support)} conflicts openmpi {
    configure.args-delete       --disable-threadsafe --enable-cxx
    configure.args-append       --enable-threadsafe --disable-cxx
}

# openmpi conflicts with universal because there is no universal variant for
# the openmpi port at the moment
variant openmpi description {Enable Parallel HDF5} conflicts threadsafe universal {
    depends_lib-append          port:openmpi
    configure.cc                ${prefix}/bin/openmpicc
    configure.args-delete       --disable-parallel --enable-cxx
    configure.args-append       --enable-parallel --disable-cxx
}


variant gcc44 description {Enable Fortran bindings (gfortran 4.4)} conflicts threadsafe universal gcc45 {
    depends_lib-append          port:gcc44 
    configure.fc                ${prefix}/bin/gfortran-mp-4.4 
    if { [variant_isset openmpi] } {
        configure.fcflags-append    -I${prefix}/include/openmpi -L${prefix}/lib -lmpi_f90 -lmpi_f77 -lmpi
    }
    configure.args-delete       --disable-fortran
    configure.args-append       --enable-fortran 
    configure.post_args LDFLAGS="-L${prefix}/lib"
}

variant gcc45 description {Enable Fortran bindings (gfortran 4.5)} conflicts threadsafe universal gcc44 {
    depends_lib-append          port:gcc45 
    configure.fc                ${prefix}/bin/gfortran-mp-4.5 
    if { [variant_isset openmpi] } {
        configure.fcflags-append    -I${prefix}/include/openmpi -L${prefix}/lib -lmpi_f90 -lmpi_f77 -lmpi
    }
    configure.args-delete       --disable-fortran
    configure.args-append       --enable-fortran 
    configure.post_args LDFLAGS="-L${prefix}/lib"
}


livecheck.type      regex
livecheck.url       http://www.hdfgroup.org/HDF5/release/obtain5.html
livecheck.regex     5-(\[0-9.\]+)
