# -*- 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           active_variants 1.1

github.setup        KarypisLab METIS 272d4a91c5f66c92327493339a476c553ebf1f5d
name                metis
version             20260610
revision            0

categories          math
maintainers         nomaintainer
license             Apache-2

description         Serial Graph Partitioning and Fill-reducing Matrix Ordering
long_description    {*}${description}

checksums           rmd160  f8cc4008aba2c7f7a63c42ac480534fe393d08c4 \
                    sha256  0a7118a7c219b0fcf4d282163ed4344c8d91358c3d6ff22f917b08d95061607f \
                    size    4867727

patchfiles          patch-shared-gklib.diff

depends_lib-append  port:gklib

# /opt/local/include/gk_externs.h:19: error: thread-local storage not supported for this target
compiler.thread_local_storage yes

pre-configure {
    reinplace       {s|build/xinclude|${CMAKE_SOURCE_DIR}/include|g} \
                    ${worksrcpath}/CMakeLists.txt
}

configure.args-append \
                    -DGKLIB_PATH=${prefix} \
                    -DGKRAND=ON \
                    -DGKREGEX=ON \
                    -DSHARED=ON

post-destroot {
    # Install documentation
    xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 ${worksrcpath}/manual/manual.pdf \
        ${destroot}${prefix}/share/doc/${name}
}

variant openmp description {Enable openmp support} {
    require_active_variants gklib openmp
    compiler.openmp_version 4.5
    configure.args-append \
                    -DOPENMP=ON
}

variant longindex description {Build with index type being long} { }

variant single description {Build with single precision} { }

post-patch {
    if {[variant_isset longindex]} {
        reinplace   {s|//#define IDXTYPEWIDTH 32|#define IDXTYPEWIDTH 64|g} \
                    ${worksrcpath}/include/metis.h
    } else {
        reinplace   {s|//#define IDXTYPEWIDTH 32|#define IDXTYPEWIDTH 32|g} \
                    ${worksrcpath}/include/metis.h
    }

    if {[variant_isset single]} {
        reinplace   {s|//#define REALTYPEWIDTH 32|#define REALTYPEWIDTH 64|g} \
                    ${worksrcpath}/include/metis.h
    } else {
        reinplace   {s|//#define REALTYPEWIDTH 32|#define REALTYPEWIDTH 32|g} \
                    ${worksrcpath}/include/metis.h
    }
}
