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

name                hdfeos5
version             2.0
revision            3
categories          science
license             public-domain
maintainers         {takeshi @tenomoto}
description         HDF-EOS library built on HDF5
long_description \
    library designed built on HDF5 to support the same Grid/Point/Swath \
    functionality in HDF-EOS 2 and to the extent possible it will be    \
    built with the same calling sequences as the original HDF-EOS 2 library.
homepage            https://hdfeos.org/software/library.php
worksrcdir          hdf-eos5-${version}
distname            ${worksrcdir}-src
master_sites        https://git.earthdata.nasa.gov/projects/DAS/repos/hdfeos5/raw/${distfiles}?at=refs%2Fheads%2FHDFEOS5_${version}&dummy=

checksums           rmd160  fa9d2561736499349b39f153b8aedf7091f69e17 \
                    sha256  d7c34770f0fe09fe5d255d73fd61aadd38278f423b925d1a5800e86aff17c82f \
                    size    1198593

compilers.choose    cc cxx
mpi.setup           -clang
compilers.enforce_c hdf5

depends_build       port:libtool
depends_lib         port:hdf5
fetch.use_epsv      no

patchfiles          patch-configure.diff \
                    patch-src-Makefile.in.diff

if {[mpi_variant_isset]} {
    set h5cc h5pcc
} else {
    set h5cc h5cc
}
default_variants-append +szip

configure.cflags-append -DH5_USE_16_API
configure.cc_archflags ""
configure.ld_archflags ""
configure.ldflags-append \
                    -L${prefix}/lib/libaec
configure.args      --prefix=${prefix}/lib/${name} \
                    --enable-shared \
                    --with-zlib=${prefix} \
                    --disable-dependency-tracking

pre-configure {
    configure.cc    ${prefix}/bin/${h5cc}
}

post-configure {
    file copy -force ${prefix}/bin/glibtool ${worksrcpath}/libtool
    reinplace "s|\\\\\$CC|${prefix}/bin/${h5cc}|" ${worksrcpath}/libtool
}

variant szip description {enables szip support} {
    depends_lib-append          port:libaec
    configure.args-append       --with-szlib=${prefix}/lib/libaec
    # Configure script code relating to szip assumes CC begins with the
    # compiler path; configure fails when ccache is used.
    configure.ccache            no
}

post-destroot {
    set incdir ${destroot}${prefix}/lib/${name}/include
    xinstall -d -m 755 ${incdir}
    xinstall -m 644 ${worksrcpath}/include/HE5_GctpFunc.h ${incdir}
    xinstall -m 644 ${worksrcpath}/include/HE5_HdfEosDef.h ${incdir}
}

livecheck.type      regex
livecheck.url       https://wiki.earthdata.nasa.gov/display/DAS/Toolkit+Downloads
livecheck.regex     {hdf-eos5-([0-9.]+)-src\.tar\.gz}
