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

# Availability.h
legacysupport.newest_darwin_requires_legacy 8

name                hwloc
version             2.14.0
set branch          [join [lrange [split ${version} .] 0 [llength [split ${version} .] ]-2 ] .]
revision            0
epoch               1
categories          devel
maintainers         {i0ntempest @i0ntempest} openmaintainer
license             BSD
description         Portable Hardware Locality
long_description \
    The Portable Hardware Locality (hwloc) software package provides \
    a portable abstraction (across OS, versions, architectures...) of \
    the hierarchical topology of modern architectures, including NUMA \
    memory nodes, sockets, shared caches, cores and simultaneous \
    multithreading.

homepage            https://www.open-mpi.org/projects/hwloc
master_sites        https://download.open-mpi.org/release/${name}/v${branch}/
use_bzip2           yes
checksums           rmd160  35e235337aef80988b60e2e9d3134a3d2206c2b0 \
                    sha256  966b9bb3e9f29f8d65ce8d106779e457f40e246a645e584b100772a42f9ae94b \
                    size    5707694

depends_build       path:bin/pkg-config:pkgconfig

depends_lib-append  port:libxml2 \
                    port:ncurses

configure.args      --disable-cairo \
                    --disable-cuda \
                    --disable-opencl \
                    --without-x

configure.checks.implicit_function_declaration.whitelist-append strchr

build.args-append   V=1 VERBOSE=1

test.run            yes
test.target         check

livecheck.type      regex
livecheck.regex     "${name} (\[0-9.\]+)"

variant cuda description "Enable CUDA support" {
    configure.args-replace  --disable-cuda --enable-cuda
}

variant opencl description "Enable OpenCL support" {
    configure.args-replace  --disable-opencl --enable-opencl

    # Untested
    if {${os.platform} ne "darwin" || ${os.major} < 12} {
        depends_build-append \
                    port:opencl-headers
        depends_lib-append \
                    port:freeocl
    }
}

variant gui description "Add graphical output capability" {
    depends_lib-append      path:lib/pkgconfig/cairo.pc:cairo \
                            path:bin/openssl:openssl \
                            port:xorg-libice \
                            port:xorg-libsm \
                            port:xorg-libX11
    require_active_variants path:lib/pkgconfig/cairo.pc:cairo x11
    configure.args-replace  --without-x --with-x
    configure.args-replace  --disable-cairo --enable-cairo
    configure.args-append   --x-includes=${prefix}/include/X11 \
                            --x-libraries=${prefix}/lib
}

notes "
  * GUI support is now disabled by default. It can be enabled via variant gui.
  * OpenCL and CUDA support is now disabled by default. It can be enabled by variants\
  opencl and cuda, respectively.
"
