# -*- 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           linear_algebra 1.0

github.setup        igraph igraph 1.0.0
revision            1
github.tarball_from releases

categories          math science devel
license             GPL-2+
maintainers         {snc @nerdling} {gmail.com:szhorvat @szhorvat} openmaintainer
description         Network analysis and graph theory library for C.
long_description    igraph is a C library for network analysis and graph theory, \
                    with an emphasis on efficiency, portability and ease of use.
homepage            https://igraph.org

depends_lib         port:arpack \
                    port:glpk \
                    port:gmp \
                    port:libxml2 \
                    port:plfit

checksums           rmd160  9d0ab89bc1d05b5f896c2483f5774e1b9679b8ca \
                    sha256  91e23e080634393dec4dfb02c2ae53ac4e3837172bb9047d32e39380b16c0bb0 \
                    size    5387320

# Testing notes:
#
# There is a bug in macOS 13.x to 14.0 that will cause the safelocale test to fail.
# See https://stackoverflow.com/q/76133503/695132 and https://github.com/igraph/igraph/issues/2340
# This is fixed in macOS 14.1.
test.run            yes
test.target         check

compiler.c_standard 1999
compiler.cxx_standard \
                    2014

linalg.setup        noveclibfort

# Build options for igraph:
#  - Do not use ccache to build this port unless MacPorts tells it to.
#  - Build a shared library.
#  - Enable link-time optimization when available.
#  - Set features and the use of external libraries explicitly---do not leave this to auto-detection.
configure.args-append   -DUSE_CCACHE=OFF \
                        -DBUILD_SHARED_LIBS=ON \
                        -DIGRAPH_ENABLE_LTO=AUTO \
                        -DIGRAPH_GLPK_SUPPORT=ON \
                        -DIGRAPH_GRAPHML_SUPPORT=ON \
                        -DIGRAPH_USE_INTERNAL_ARPACK=OFF \
                        -DIGRAPH_USE_INTERNAL_BLAS=OFF \
                        -DIGRAPH_USE_INTERNAL_GLPK=OFF \
                        -DIGRAPH_USE_INTERNAL_GMP=OFF \
                        -DIGRAPH_USE_INTERNAL_LAPACK=OFF \
                        -DIGRAPH_USE_INTERNAL_PLFIT=OFF \
                        -DIGRAPH_OPENMP_SUPPORT=OFF \
                        -DIGRAPH_WARNINGS_AS_ERRORS=OFF

pre-configure {
    # Link to chosen BLAS/LAPACK
    configure.args-append   ${cmake_linalglib}
}

# Workaround for Lion and Mountain Lion. See https://trac.macports.org/ticket/60655
configure.cppflags-append   -D_DARWIN_C_SOURCE

variant tls description {Build thread-safe version} {
    compiler.thread_local_storage   yes
    configure.args-append           -DIGRAPH_ENABLE_TLS=ON
}

# The openmp variant is not enabled by default because in MacPorts,
# the compilers that support OpenMP won't support LTO (without workarounds).
# Overall, igraph performance benefits more from LTO than OpenMP.
variant openmp description {Enable OpenMP support} {
    # This compiler gives an invalid warning about uninitialized variables.
    # It is unclear if it also miscompiles the code.
    compiler.blacklist-append       {macports-clang-9.0}

    configure.args-replace          -DIGRAPH_OPENMP_SUPPORT=OFF -DIGRAPH_OPENMP_SUPPORT=ON
}

# Do not enable TLS on OS X 10.6, as it does not support it.
if {${os.platform} eq "darwin" && ${os.major} >= 11} {
    default_variants +tls
}

# See https://github.com/macports/macports-base/commit/7c91604891fa0d071b8d598490c4dc2edb8e0031
if {[variant_isset openmp]} {
    compiler.openmp_version 2.0
    if {[info exists compiler.log_verbose_output]} {
        compiler.log_verbose_output no
    } else {
        configure.cppflags-append -fopenmp
        configure.ldflags-append  -fopenmp
    }
}

post-destroot {
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 {*}[glob ${worksrcpath}/doc/html/*] ${destroot}${docdir}
}

# To prevent picking up 1.0.0-rc1
github.livecheck.regex  {([\d.]+)}
