# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup compilers 1.0

name                hdf4
version             4.2.15
revision            2
categories          science
license             NCSA
maintainers         {takeshi @tenomoto}

description         file format for storing scientific data and utilities
long_description    ${description}
homepage            http://www.hdfgroup.org/products/hdf4/index.html
master_sites        ftp://ftp.hdfgroup.org/HDF/releases/HDF${version}/src/ \
                    http://www.hdfgroup.org/ftp/HDF/releases/HDF${version}/src/
distname            hdf-${version}
use_bzip2           yes
checksums           rmd160  89721c9462f53d944f45ccf73d33668bebf1e01b \
                    sha256  bde035ef5a1cd5fdbd0a7f1fa5c17e98bbd599300189ac4d234f16e9bb7bcb12 \
                    size    3647900

compilers.choose    fc f77 f90
compilers.setup

depends_lib         port:zlib path:include/turbojpeg.h:libjpeg-turbo

patchfiles          patch-configure.diff \
                    patch-m4-libtool.m4.diff \
                    patch-hdf-examples-Makefile.in.diff \
                    patch-mfhdf-Makefile.in.diff \
                    patch-mfhdf-examples-Makefile.in.diff \
                    patch-mfhdf-hdiff-hdiff_main.c.diff \
                    patch-mfhdf-libsrc-file.c.diff \
                    patch-mfhdf-test-hdftest.c.diff \
                    patch-mfhdf-test-tdatainfo.c.diff \
                    patch-mfhdf-test-tfile.c.diff \
                    patch-mfhdf-test-tncvargetfill.c.diff \
                    patch-mfhdf-test-tsd.c.diff \
                    patch-mfhdf-test-tszip.c.diff \
                    patch-hdf-test-mgr.c.diff \
                    implicit-int.patch \
                    arm64.patch

configure.args      --disable-netcdf --disable-fortran \
                    --with-jpeg=${prefix} --enable-shared \
                    --without-szlib
configure.cppflags-delete   -I${prefix}/include
configure.ldflags-delete    -L${prefix}/lib


test.run            yes
test.target         check

post-destroot {
    file mkdir ${destroot}${prefix}/share/doc/${name}
    file copy ${worksrcpath}/hdf/util/testfiles ${destroot}${prefix}/share/doc/${name}/samples
    foreach f {COPYING release_notes/HISTORY.txt release_notes/RELEASE.txt} {
        file copy ${worksrcpath}/$f ${destroot}${prefix}/share/doc/${name}/
    }
    foreach f {lib/libudport.a include/netcdf.h include/netcdf.inc include/netcdf.f90 \
             share/man/man1/ncgen.1 share/man/man1/ncdump.1} {
        file delete ${destroot}${prefix}/$f
    }
}

if {[fortran_variant_isset]} {
    patchfiles-append   patch-hdf-fortran-examples-Makefile.in.diff \
                        patch-mfhdf-fortran-examples-Makefile.in.diff
    configure.args-delete   --disable-fortran --enable-shared
}

compilers.allow_arguments_mismatch  yes

if {[variant_isset g95]} {
    configure.fflags-append -fno-second-underscore
}

variant szip description {build with szip} {
    depends_lib-append      port:szip
    configure.args-delete   --without-szlib
    configure.args-append   --with-szlib=${prefix}
}

livecheck.type   regex
livecheck.url    ${homepage}
livecheck.regex  {Release of HDF is ([0-9]+\.[0-9]+\.[0-9]+)}
