# -*- 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
# $Id: Portfile 87614 2011-11-28 21:11:56Z takeshi@macports.org $

PortSystem          1.0

name                hdf4
version             4.2.6
revision            2
platforms           darwin
categories          science
maintainers         takeshi

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/HDF_Current/src/ \
                    http://www.hdfgroup.org/ftp/HDF/HDF_Current/src/
distname            hdf-${version}
use_bzip2           yes
checksums           md5     eed281ded7f81f6ba1a3b1b1d5109bfe \
                    sha1    914eedbd8d4714f8bc0cc10bbbad5ad7fe1e375c \
                    rmd160  9b8b9ccba7f84085cff2c64090d5f7c0abf7acad

depends_lib         port:zlib port:szip port:jpeg

post-patch {
    reinplace "s|CFLAGS_TO_ADD\$CFLAGS|CFLAGS|" ${worksrcpath}/configure
    reinplace "s|FFLAGS_TO_ADD\$FFLAGS|FFLAGS|" ${worksrcpath}/configure
}

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

post-configure {
# remove -arch from h4cc to fix failure of h4cc -E with +universal
    reinplace -E {s|-arch [a-z0-9_]+||g} ${worksrcpath}/hdf/util/h4cc
}

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 {bin/ncdump bin/ncgen 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
    }
}

variant g95 conflicts gcc43 gcc44 gcc45 universal description {build with g95} {
    configure.args-delete   --disable-fortran --enable-shared
    depends_build-append    port:g95
    configure.f77           ${prefix}/bin/g95
}

variant gcc43 conflicts g95 gcc44 gcc45 universal description {build with gfortran 4.3} {
    configure.args-delete   --disable-fortran --enable-shared
    depends_build-append    port:gcc43
    configure.f77           ${prefix}/bin/gfortran-mp-4.3
}

variant gcc44 conflicts g95 gcc43 gcc45 universal description {build with gfortran 4.4} {
    configure.args-delete   --disable-fortran --enable-shared
    depends_build-append    port:gcc44
    configure.f77           ${prefix}/bin/gfortran-mp-4.4
}

variant gcc45 conflicts g95 gcc43 gcc44 universal description {build with gfortran 4.5} {
    configure.args-delete   --disable-fortran --enable-shared
    depends_build-append    port:gcc45
    configure.f77           ${prefix}/bin/gfortran-mp-4.5
}

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