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

# Still using configure/make system because CMakeLists.txt does not install nf-config.

# netcdf-fortran does not require the fortran interface of hdf5.
# enforcing hdf5 variant does not allow installation of
# hdf5+cxx (w/o a fortran variant) and netcdf-fortran.
#mpi.enforce_variant         hdf5

# check to avoid the configure error:
#        The NetCDF C library is built with parallel I/O feature enabled, but
#        the Fortran compiler '/opt/local/bin/gfortran-mp-7' supplied in this configure command
#        does not support MPI-IO. Please use one that does. If parallel I/O
#        feature is not desired, please use a NetCDF C library with parallel
#        I/O feature disabled. Abort.
mpi.enforce_variant         netcdf

github.setup                Unidata netcdf-fortran 4.6.2 v
github.tarball_from         archive
revision                    0
maintainers                 {takeshi @tenomoto} \
                            {@Dave-Allured noaa.gov:dave.allured} \
                            openmaintainer
categories                  science
license                     Permissive

description                 NetCDF Fortran Library
long_description \
    The Unidata network Common Data Form (netCDF) is an interface \
    for scientific data access and a set of freely-distributed \
    software libraries that provide an implementation of the interface. \
    The netCDF library also defines a machine-independent format for \
    representing scientific data. Together, the interface, library, \
    and format support the creation, access, and sharing of scientific data. \
    This software package provides Fortran application interfaces \
    for accessing netCDF data.

checksums           rmd160  010ee748868ba6349d16d179b1edb607fe9c8ce6 \
                    sha256  44cc7b5626b0b054a8503b8fe7c1b0ac4e0a79a69dad792c212454906a9224ca \
                    size    8087390

patchfiles          patch-nf03_test4-Makefile.in.diff \
                    patch-nf-config.diff \
                    patch-docs-Makefile.in.diff

compilers.choose    f77 f90 fc
compilers.add_gcc_rpath_support no
mpi.setup           require_fortran

depends_lib         port:netcdf
depends_run-append  port:m4

# Fortran compilers can not cross-compile
if {${os.arch} eq "i386"} {
    set universal_archs_supported "i386 x86_64"
} else {
    set universal_archs_supported "ppc ppc64"
}

if {${universal_possible} && [variant_isset universal]} {
    patchfiles-append   patch-Makefile.in.diff
}

post-patch {
    if {[variant_isset g95]} {
        reinplace "s|lt_cv_ld_force_load=yes|lt_cv_ld_force_load=no|" ${worksrcpath}/configure
    }
}

# Fix for 10.7 and invalid instruction mnemonic 'cvttss2sil' copied from:
# https://github.com/william-dawson/NTPoly/issues/192
compiler.blacklist-append \
                    {clang < 500}

configure.args-append       HDF5_PLUGIN_PATH=${prefix}/hdf5/lib/plugin
configure.cppflags-append   -DNDEBUG \
                            -DpgiFortran
configure.cflags-append     -fno-common
if {[variant_isset g95]} {
    configure.fflags-append     -fno-second-underscore
    configure.fcflags-append    -fno-second-underscore
    configure.ldflags-append    -lf95
}

test.run                    yes
test.target                 check

if {[mpi_variant_isset]} {
    configure.args-append      --enable-parallel-tests
    pre-test {
        foreach script {nf_test4/run_f77_par_test.sh nf_test4/run_f77_par_test_03.sh nf03_test4/run_f90_par_test.sh examples/F90/run_f90_par_examples.sh} {
            reinplace -W ${worksrcpath} "s|mpiexec|${prefix}/bin/${mpi.exec}|" ${script}
        }
    }
}

github.livecheck.regex      {([^"rba]+)}
