# -*- 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 f86e4e1cd6f891a22676845f6f38a278b028919c
name                metis
version             20261116
revision            0

categories          math
maintainers         nomaintainer
license             Apache-2

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

checksums           rmd160  032c470f547c00bc930fe86b543bffceaf80f8a0 \
                    sha256  e32d857e1592a274d3a4c030617999503589cef83c17d0f4f83b984263f8805b \
                    size    4868258

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
    }
}
