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

epoch                   2
github.setup            hpddm hpddm 2.3.0 v
revision                0
checksums               rmd160  397e16eed477ed66919e5ba2830455595c5931dd \
                        sha256  db3d5251bb064a42a3c214137ef9b585934213e7dab7fb725de0b3d4fd2ffdf6 \
                        size    337163

categories              math science
license                 LGPL-3+
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer

description             a framework for high-performance domain decomposition methods
long_description        HPDDM is an efficient implementation of various domain decomposition methods.

github.tarball_from     archive

mpi.setup               require require_fortran

linalg.setup            blas_only

set python_branch       3.12
set python_version      [string map {. {}} ${python_branch}]

depends_lib-append      port:python${python_version} \
                        port:mumps \
                        port:arpack \
                        port:scalapack \
                        port:hypre

compiler.cxx_standard   2011

patchfiles-append       patch-install_name.diff

muniversal.arch_tools   MPICXX \
                        MPICC \
                        MPIF90

post-extract {
    copy ${worksrcpath}/Make.inc/Makefile.macOS ${worksrcpath}/Makefile.inc
}

pre-build {
    build.args-append   MPICXX=${mpi.cxx} \
                        MPICC=${mpi.cc} \
                        MPIF90=${mpi.f90} \
                        MPIRUN="${prefix}/bin/${mpi.exec} -np" \
                        MUMPS_INCS=-I${prefix}/include \
                        PYTHON_INCS=-I${frameworks_dir}/Python.framework/Versions/${python_branch}/include/python${python_branch} \
                        ARPACK_LIBS="-L${prefix}/lib -larpack" \
                        SCALAPACK_LIBS="-L${prefix}/lib -lscalapack" \
                        MUMPS_LIBS="-L${prefix}/lib -lmumps_common -lesmumps -lsmumps -ldmumps -lcmumps -lzmumps -lpord" \
                        HYPRE_LIBS="-L${prefix}/lib -lHYPRE" \
                        PYTHON_LIBS="-L${frameworks_dir}/Python.framework/Versions/${python_branch}/lib -lpython${python_branch}" \
                        VERSION=${version} \
                        CVERSION=[join [lrange [split ${version} .] 0 0] .]
    if {[variant_isset openblas]} {
        build.args-append \
                        OPENBLAS_LIBS="-L${prefix}/lib ${linalglib}"
    } else {
        build.args-append \
                        BLAS_LIBS="-L${prefix}/lib ${linalglib}"
    }
}

# Makefile searches for gfortran in $(MPIF90) name, which is not always true
#    even though $(MPIF90) uses gfortran
build.args-append       F90MOD=-J

destroot {
    xinstall -d  -m 0755 ${destroot}${prefix}/include/${name}
    xinstall     -m 0644 {*}[glob ${worksrcpath}/include/*]   ${destroot}${prefix}/include/${name}
    xinstall     -m 0755 {*}[glob ${worksrcpath}/lib/*.dylib] ${destroot}${prefix}/lib
    #xinstall    -m 0644 {*}[glob ${worksrcpath}/lib/*.a]     ${destroot}${prefix}/lib
    xinstall -W ${worksrcpath}/bin -m 0755 \
        custom_operator_fortran \
        schwarz_c \
        schwarz_cpp \
        ${destroot}${prefix}/bin
}

# Tests may randomly lead to infinity loop, let's disable it.
# See: https://github.com/hpddm/hpddm/issues/110
test.run                no

depends_test-append     port:py${python_version}-mpi4py \
                        port:py${python_version}-numpy \
                        port:py${python_version}-scipy

pre-test {
    test.args-append    PATH=${frameworks_dir}/Python.framework/Versions/${python_branch}/bin:$env(PATH) \
                        {*}${build.args}
}

github.livecheck.branch main
