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

github.setup        Reference-ScaLAPACK scalapack 2.2.3 v
revision            0
categories          math
maintainers         nomaintainer
license             BSD
description         A package for solving linear equations
long_description    The ScaLAPACK (or Scalable LAPACK) library includes \
                    a subset of LAPACK routines redesigned for distributed \
                    memory MIMD parallel computers. Since version 2.0.0, \
                    ScaLAPACK includes BLACS.

homepage            https://www.netlib.org/scalapack

checksums           rmd160  ce637d21ede19c0e3038bb6b98f44b6871c93e18 \
                    sha256  5d93701eca663925e98010dd8d0f45fd79b2191d74e5afa5711d587370a8b9dd \
                    size    4805086

github.tarball_from archive

mpi.setup           require require_fortran

# fix wrong version, which results in wrong versioned name of
# libscalapack.${version}.dylib
# see https://github.com/Reference-ScaLAPACK/scalapack/issues/108
post-patch {
    reinplace "s|2.2.1|${version}|g" ${worksrcpath}/CMakeLists.txt
}

compiler.blacklist-append \
                    {clang < 500}

# remove when issue https://trac.macports.org/ticket/62567 is closed
configure.cflags-append \
                    -Wno-implicit-function-declaration

configure.args      -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib \
                    -DBUILD_SHARED_LIBS=ON \
                    -DBUILD_TESTING=ON

pre-configure {
    configure.args-append \
        -DMPI_C_COMPILER=${mpi.cc} \
        -DMPI_Fortran_COMPILER=${mpi.fc} \
        -DMPIEXEC_EXECUTABLE=${prefix}/bin/${mpi.exec} \
        -DLAPACK_LIBRARIES="-L${prefix}/lib ${linalglib}"
}

# see https://github.com/Reference-ScaLAPACK/scalapack/issues/21
compilers.allow_arguments_mismatch \
                    yes

# remove duplicate rpath ${prefix}/lib/libgcc
compilers.add_gcc_rpath_support \
                    no

# BUILD_TESTING only affects BLACS directory anyway

test.run            yes

pre-test {
    # test infrastructure uses /bin/ps (I think for checking on job
    # timeout), which is forbidden by sandboxing
    append portsandbox_profile \
        " (allow process-exec (literal \"/bin/ps\") (with no-profile))"
}
