# -*- 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.2.0
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  eda00bf5bdf8ebe55b4016ddb1c729c132e81554 \
                    sha256  1a1ab8209b35586fbc1aa279ba76d102130b95badcb20ca329587219112d8c16 \
                    size    42131403

patch.pre_args-replace  -p0 -p1

compiler.cxx_standard   2011
compiler.c_standard     1999

mpi.setup           -gcc44 -gcc45

depends_build-append \
                    path:bin/pkg-config:pkgconfig

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_EXAMPLES:BOOL=OFF \
                    -DHDF5_BUILD_FORTRAN:BOOL=OFF \
                    -DHDF5_BUILD_HL_LIB:BOOL=ON \
                    -DHDF5_BUILD_JAVA: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} \
                    -DHDF5_USE_LIBAEC_STATIC:BOOL=OFF \
                    -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 libaec_DIR=${prefix}/lib/libaec
configure.env-append ZLIB_ROOT=${prefix}/lib

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

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]} {
    # **** Parallel and C++ options are mutually exclusive, override with HDF5_ALLOW_UNSUPPORTED option ****
    configure.args-append       -DHDF5_ALLOW_UNSUPPORTED=ON \
                                -DHDF5_ENABLE_PARALLEL=ON

    # Enabling tools does not work: https://github.com/HDFGroup/hdf5/issues/2265
    # -DHDF5_BUILD_PARALLEL_TOOLS:BOOL=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.-\]+)
