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

gitlab.instance             https://gitlab.inria.fr
gitlab.setup                scotch scotch 7.0.5 v

categories                  science math
maintainers                 {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
license                     CeCILL-C

description                 a software package for graph and mesh/hypergraph \
                            partitioning and sparse matrix ordering
long_description            Scotch is {*}${description}.

checksums                   rmd160  b7fe20f5cd39f936618fea9329cb26ae437bfe21 \
                            sha256  6f7ac6ebbf2e2b8524ff5f59eb9562a26ba6670b8b327ef0257dd37a6bca67be \
                            size    7044004

compilers.choose            cc fc
mpi.setup                   require

depends_build-append        port:bison \
                            port:flex
depends_skip_archcheck-append \
                            bison \
                            flex

depends_lib-append          port:bzip2 \
                            port:xz \
                            port:zlib

depends_test-append         port:mumps

# MPI implementation is not threadsafe, do not use DSCOTCH_PTHREAD
configure.args-append       -DMPI_THREAD_MULTIPLE=OFF

# libScotchMeTiS header stubs conflicts with original MeTiS headers
configure.args-append       -DINSTALL_METIS_HEADERS=OFF

# Build a shared library, not static!
configure.args-append       -DBUILD_SHARED_LIBS=ON

post-destroot {
    if {${muniversal.build_arch} ne ${configure.build_arch}} {
        xinstall -d -m 0755 ${destroot}${prefix}/include/${muniversal.build_arch}
        foreach hfile {scotchf.h ptscotchf.h} {
            if {[file exists ${destroot}${prefix}/include/${hfile}]} {
                move ${destroot}${prefix}/include/${hfile} ${destroot}${prefix}/include/${muniversal.build_arch}
            }
        }
    }
}

test.run                    yes

pre-configure {
    if {[mpi_variant_isset]} {
        configure.args-append \
                            -DMPIEXEC_EXECUTABLE=${prefix}/bin/${mpi.exec}
    }
}

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