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

github.setup        Reference-ScaLAPACK scalapack 2.2.2 v
revision            1
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  91015da6f02b4185c644c4567b2679852966e824 \
                    sha256  a2f0c9180a210bf7ffe126c9cb81099cf337da1a7120ddb4cbe4894eb7b7d022 \
                    size    4769347

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

# remove duplicate rpath ${prefix}/lib
if {${os.platform} eq "darwin" && ${os.major} >= 10} { # 10.6, Snow Leopard
    post-build {
        system -W ${workpath}/build/lib/ "install_name_tool -delete_rpath \
            ${prefix}/lib libscalapack.${version}.dylib"
    }
}

# 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))"
}
