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

github.setup        ralna spral 2024.05.08 v
revision            1
categories          math science
license             BSD
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Sparse Parallel Robust Algorithms Library
long_description    An open-source (BSD) library for sparse linear algebra and associated algorithms. \
                    It is primarily developed by the Numerical Analysis group at STFC Rutherford Appleton Laboratory.
homepage            https://www.numerical.rl.ac.uk/spral
checksums           rmd160  5f1586be411f2a6027c97aaecc3a4c079ff17d74 \
                    sha256  0795c10c1c4dab1cf8c2de4024296d75d9d83b7525e82c77584c16060e29e4f5 \
                    size    7912673
github.tarball_from archive

use_autoreconf      yes
autoreconf.args     -fvi

compilers.setup     require_fortran
compiler.c_standard 2011

patchfiles          patch-configure.diff

# https://github.com/ralna/spral/issues/165
post-patch {
    if {${configure.cxx_stdlib} eq "libc++"} {
        reinplace "s|-lstdc++|-lc++|g" ${worksrcpath}/configure.ac
    }
}

depends_build-append \
                    path:bin/pkg-config:pkgconfig
depends_lib-append  port:hwloc \
                    port:metis \
                    path:lib/libopenblas.dylib:OpenBLAS

# This is required to avoid failures:
# Fatal Error: Cannot open module file 'spral_ssids_contrib.mod' for reading at (1): No such file or directory
use_parallel_build  no

configure.args-append \
                    --disable-gpu \
                    --disable-openmp \
                    --disable-silent-rules

variant openmp description "Enable OpenMP support" {
    compiler.openmp_version 2.5

    configure.args-delete \
                    --disable-openmp

    if {[string match *clang* ${configure.compiler}]} {
        configure.ldflags-append \
                    -L${prefix}/lib/libomp -lomp
    }
}

default_variants    +openmp

# Some tests may fail: https://github.com/ralna/spral/issues/167
test.run            yes
test.target         check
