# -*- 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                    pnetcdf
version                 1.14.1
revision                0
maintainers             {@thiagoveloso gmail.com:thiagoveloso} openmaintainer
categories              science devel
license                 Permissive

description             A Parallel I/O Library for NetCDF File Access.

long_description        PnetCDF is a high-performance parallel I/O library \
                        for accessing files in format compatibility with Unidata's \
                        NetCDF, specifically the formats of CDF-1, 2, and 5. The \
                        CDF-5 file format, an extension of CDF-2, supports unsigned \
                        data types and uses 64-bit integers to allow users to define \
                        large dimensions, attributes, and variables (> 2B array elements).

homepage                https://parallel-netcdf.github.io

master_sites            ${homepage}/Release/

checksums               rmd160  5989469c35c6f8cda91adf809f7e9c936e645a1e \
                        sha256  6f0f7221006c211fce9ddd2c008796b8c69dd717b2ad1be0b4027fc328fd3220 \
                        size    2512984

if {${os.platform} eq "darwin" && ${os.arch} eq "powerpc"} {
    mpi.setup           require require_fortran \
                        -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5 \
                        -clang -fortran
} else {
    mpi.setup           require require_fortran \
                        -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5
}

# Xcode clang of 10.7 fails with error: invalid instruction mnemonic 'cvtsi2ssl'
# Copied from https://github.com/macports/macports-ports/pull/17269
# Also see https://github.com/william-dawson/NTPoly/issues/192
compiler.blacklist-append \
                        {clang < 500} {*gcc-[34].*} {macports-gcc-[56]}

depends_build-append    port:autoconf \
                        port:automake \
                        port:libtool \
                        port:m4 \
                        path:bin/perl:perl5

configure.args-append   --disable-silent-rules \
                        --with-mpi=${prefix}

# M4 was accidentally left out of Xcode 15.3.  Affects some Sonoma builds.
# Use MacPorts M4.  For background, see:
# https://github.com/macports/macports-ports/pull/22985
# and related tickets.
configure.env-append    M4=${prefix}/bin/gm4

configure.env-append    MPICC=${mpi.cc} \
                        MPICXX=${mpi.cxx} \
                        MPIF77=${mpi.f77} \
                        MPIF90=${mpi.f90}

use_parallel_build      yes

if {![variant_isset openmpi]} {
    default_variants-append \
                        +mpich
}

post-destroot {
    reinplace "s|${destroot}||g" ${destroot}${prefix}/lib/pkgconfig/pnetcdf.pc
    reinplace "s|${destroot}||g" ${destroot}${prefix}/bin/pnetcdf-config
}

livecheck.type          regex
livecheck.url           ${homepage}/wiki/Download.html
# Match either prefix, "parallel-netcdf" or "pnetcdf".
# Check with "port -d livecheck pnetcdf".
livecheck.regex         \[parallel\]*\[p-\]netcdf-\(\[0-9.\]+\).tar
