# -*- 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

PortSystem          1.0
PortGroup           cmake 1.1
PortGroup           github 1.0
PortGroup           legacysupport 1.1
PortGroup           mpi 1.0

github.setup        HDFGroup hdf5 2.1.1
revision            0
categories          science
maintainers         {eborisch @eborisch} openmaintainer
license             BSD
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            https://www.hdfgroup.org/solutions/${name}
github.tarball_from releases

checksums \
    rmd160  e1fc58cd2d17ad1d269ef7d2fa4f9e4a8b84e499 \
    sha256  efff93b5a904d66e8f626d7da60b5eedc9faf544be27dbabbaa87967b8ad798b \
    size    42049698

# https://github.com/HDFGroup/hdf5/issues/6419
patchfiles-append   a6f1ecb70970a48de50ab4f2cd51de41a9818213.patch

compiler.cxx_standard   2011
compiler.c_standard     1999

mpi.setup           -gcc44 -gcc45

depends_lib-append  port:libaec \
                    port:zlib

# <stdin>:2115:2: error: invalid instruction mnemonic 'cvtsi2ssl'
compiler.blacklist-append \
                    {clang < 500}

# Avoid duplicate LC_RPATH's in dylibs, satisfy Xcode 15 linker.
compilers.add_gcc_rpath_support no

# Use lib/hdf5 rather than hdf5/lib plugin directory
configure.args      -DCMAKE_BUILD_TYPE:STRING=Release \
                    -DCMAKE_FIND_DEBUG_MODE:BOOL=OFF \
                    -DH5_DEFAULT_PLUGINDIR:STRING=${prefix}/lib/hdf5 \
                    -DHDF5_BUILD_CPP_LIB:BOOL=ON \
                    -DHDF5_BUILD_FORTRAN:BOOL=OFF \
                    -DHDF5_ENABLE_OPTIMIZATION:BOOL=ON \
                    -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON \
                    -DHDF5_ENABLE_ZLIB_SUPPORT:BOOL=ON \
                    -DHDF5_INSTALL_CMAKE_DIR:STRING=${cmake_share_module_dir} \
                    -Dlibaec_INCLUDE_DIR:PATH=${prefix}/lib/libaec/include \
                    -Dlibaec_LIBRARY:FILEPATH=${prefix}/lib/libaec/lib/libaec.dylib \
                    -DSZIP_INCLUDE_DIR:PATH=${prefix}/lib/libaec/include \
                    -DSZIP_LIBRARY:FILEPATH=${prefix}/lib/libaec/lib/libsz.dylib \
                    -DSZIP_USE_EXTERNAL:BOOL=OFF

configure.env-append ZLIB_ROOT=${prefix}/lib
configure.env-append libaec_DIR=${prefix}/lib/libaec
configure.cflags-append -fno-common

# Actively checks how to get clang to warn on implicit functions with this.
configure.checks.implicit_function_declaration.whitelist-append strchr

default_variants +fortran

variant fortran description "Build fortran libs" {
    configure.args-replace  -DHDF5_BUILD_FORTRAN:BOOL=OFF -DHDF5_BUILD_FORTRAN:BOOL=ON
    configure.args-append   -DHDF5_INSTALL_MOD_FORTRAN:BOOL=ON
}

post-destroot {
    # Move LICENSE, etc.
    xinstall -d ${destroot}${prefix}/share/hdf5/
    foreach f [ glob -type f ${destroot}${prefix}/share/* ] {
        move $f ${destroot}${prefix}/share/hdf5/
    }

    foreach f [ glob ${destroot}${prefix}/mod/static/* ] {
        move $f ${destroot}${prefix}/include/
    }

    delete ${destroot}${prefix}/mod
}

test.run            yes

variant threadsafe description "Enable threadsafety. +threadsafe is EXPERIMENTAL" } {
    # Tell hdf5 to configure in this experimental configuration
    configure.args-append       -DHDF5_ALLOW_UNSUPPORTED=ON \
                                -DHDF5_ENABLE_THREADSAFE=ON

    pre-configure {
        ui_warn {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
hdf5 will been configured in an unsupported "Experimental" mode due to\
+threadsafe.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    }
    }

    notes-append {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
hdf5 has been installed in an unsupported "Experimental" mode due to\
+threadsafe.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    }
}

if {[mpi_variant_isset]} {
    configure.args-append       -DHDF5_ENABLE_PARALLEL=ON
}

if {[variant_isset fortran] && ![fortran_variant_isset]} {
    default_variants +gfortran
    if {![fortran_variant_isset]} {
        error "+fortran requires a fortran compiler to be selected"
    }
}

notes-append {
Mac users may need to set the environment variable "HDF5_USE_FILE_LOCKING"\
to the five-character string "FALSE" when accessing network mounted files.\
This is an application run-time setting, not a configure or build setting.\
Otherwise errors such as "unable to open file" or "HDF5 error" may be\
encountered.
}

# Livecheck on GitHub release tags only.  Exclude non-release tags.
# Accept matches both with and without "hdf5_" or "hdf5-" prefix.
livecheck.regex     releases/tag/\[hdf5_-\]*(\[0-9.-\]+)
