# -*- 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 117247 2014-02-20 16:34:06Z eborisch@macports.org $

PortSystem          1.0
PortGroup           conflicts_build 1.0
PortGroup           muniversal 1.0
PortGroup           mpi 1.0

mpi.setup

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

description         HDF5 general purpose library and file format for storing\
                    scientific data
long_description    HDF5 is a data model, library, and file format for storing\
                    and managing data. It supports an unlimited variety of\
                    datatypes, and is designed for flexible and efficient I/O\
                    and for high volume and complex data. HDF5 is portable and\
                    is extensible, allowing applications to evolve in their use\
                    of HDF5. The HDF5 Technology suite includes tools and\
                    applications for managing, manipulating, viewing, and\
                    analyzing data in the HDF5 format.
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 \
    rmd160  b885803d35855007f2e66f1a376fff9d11d5c1ec \
    sha256  6d080f913a226a3ce390a11d9b571b2d5866581a2aa4434c398cd371c7063639
distname            ${realname}-${version}
use_bzip2           yes
depends_lib         port:zlib
use_parallel_build  yes

# nawk: bailing out at source line 273
conflicts_build     nawk

# llvm-gcc-4.2 produced code fails type conversion tests
# Upstream suggestion is use -O0. Clang-produced code passes all tests.
compiler.blacklist  llvm-gcc-4.2

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

# http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/2010-March/002682.html
license             NCSA

default_variants    +cxx

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
    }
}

post-destroot {
    xinstall -d ${destroot}${prefix}/share/hdf5/
    xinstall -m 444 ${worksrcpath}/COPYING\
      ${destroot}${prefix}/share/hdf5/
}

test.run            yes
test.target         check

variant szip description {Enable szip support. (Noncommercial license)} {
    depends_lib-append          port:szip
    configure.args-append       --with-szlib=yes
    license                     Noncommercial
}

variant cxx description {
    Enable c++ interfance.
  +cxx is EXPERIMENTAL with +threadsafe or any mpi variant
} {
    configure.args-delete       --disable-cxx
    configure.args-append       --enable-cxx
}

variant fortran description {
    Enable fortran bindings.
  +fortran is EXPERIMENTAL with +threadsafe
} {
    configure.args-delete       --disable-fortran
    configure.args-append       --enable-fortran

    if {![fortran_variant_isset]} {
        default_variants +gfortran
    }
}

if {[ variant_isset fortran ] && ![ fortran_variant_isset ] } {
    ui_error "+fortran requires a fortran compiler to be selected"
    return -code error
}

if {([ variant_isset gfortran ] || [ variant_isset g95 ]) && ![ variant_isset fortran ]} {
    default_variants +fortran
}

variant threadsafe description {
    Enable threadsafety.
  +threadsafe is EXPERIMENTAL with +cxx, +fortran, or any mpi variant
} {
    configure.args-delete       --disable-threadsafe
    configure.args-append       --enable-threadsafe --with-pthread
}

if {[ variant_isset threadsafe ] && ([ variant_isset cxx ] ||
                                     [ variant_isset fortran ]) ||
    ([ mpi_variant_isset ])  &&
    ([ variant_isset cxx ]   || [ variant_isset threadsafe ])  } {

    # Tell hdf5-18 to configure in this experimental configuration
    configure.args-append       --enable-unsupported

    notes {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
hdf5-18 has been installed in an unsupported "Experimental" mode due to\
selected variants. See "port variants hdf5-18 | grep EXPERIMENTAL" for more\
information.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    }

    pre-configure {
        ui_warn {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
hdf5-18 will been configured in an unsupported "Experimental" mode due to\
selected variants. See "port variants hdf5-18 | grep EXPERIMENTAL" for more\
information.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    }
    }
}

if {[ mpi_variant_isset ]} {
    configure.args-delete       --disable-parallel
    configure.args-append       --enable-parallel
}

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