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

# Must be revbumped when default MPICH compiler changes, since it installs version-specific headers:
# /opt/local/include/OpenCoarrays-2.10.3_GNU-14.2.0

github.setup        sourceryinstitute OpenCoarrays 2.10.3
revision            0
categories          science parallel devel fortran
license             BSD
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer

description         Library for multi-image coarray Fortran suppport
long_description    OpenCoarrays is an open-source software project \
                    that produces an application binary interface (ABI) \
                    to support coarrays and other Fortran 2018 parallel \
                    programming features for gfortran in the GNU Compiler \
                    Collection (GCC). Gfortran has used OpenCoarrays \
                    since the GCC 5.1.0 release.
homepage            http://www.opencoarrays.org

mpi.setup           require require_fortran \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5 \
                    -clang

universal_variant   no

checksums           rmd160  2423a9241aa796c4b2deaf6be19aa774c793e6f6 \
                    sha256  50c8c2a99fecbd33e6be126d33bb43543d5aa035df9d6e31e323e5398a1029e3 \
                    size    351188
github.tarball_from archive

post-patch {
    reinplace "s|mpicc|${prefix}/bin/${mpi.cc}|g" \
        src/tests/unit/simple/CMakeLists.txt
}

# Required to run the test phase.
pre-configure {
    configure.args-append \
        -DMPIEXEC_EXECUTABLE=${prefix}/bin/${mpi.exec} \
        -DMPI_C_COMPILER=${prefix}/bin/${mpi.cc} \
        -DMPI_Fortran_COMPILER=${prefix}/bin/${mpi.f90}
}

configure.args-append \
        -DMPI_C_COMPILE_OPTIONS="-lpthread" \
        -DMPI_Fortran_COMPILE_OPTIONS="-lpthread"

if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list arm i386 ppc]} {
    configure.ldflags-append \
        -latomic
}

# This can be used generally, since no universal variant, but Rosetta needs it:
platform darwin 10 powerpc {
    patchfiles-append patch-rosetta.diff
}

variant events description "Enable support for the Fortran 2015 events feature" {
    configure.args-append \
        -DCOMPILER_SUPPORTS_ATOMICS:BOOL=ON
}

# Do not make this default: known to trigger some bugs on Intel, broken on PPC.
variant ULFM description "Enable experimental ULFM support" {
    configure.args-append \
        -DCAF_ENABLE_FAILED_IMAGES:BOOL=ON
}

test.run            yes
test.target         check
