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

github.setup                DrTimothyAldenDavis SuiteSparse 7.10.1 v
github.tarball_from         archive
# subports have independent revisions
revision                    0
epoch                       20200517
categories                  math science
maintainers                 {mcalhoun @MarcusCalhoun-Lopez} openmaintainer

description                 Sparse matrix routines

long_description            SuiteSparse is a single archive that contains all packages \
                            authored by Tim Davis.

homepage                    https://people.engr.tamu.edu/davis/suitesparse.html

checksums                   rmd160  1bb5e26b6a007068f7aa1c8cdf39b70fef61d1b0 \
                            sha256  9e2974e22dba26a3cffe269731339ae8e01365cfe921b06be6359902bd05862c \
                            size    87776029

configure.optflags          -O3

compiler.c_standard         2011

# We keep SUITESPARSE_USE_STRICT at the default value of OFF and
# SUITESPARSE_USE_OPENMP at the default value of ON. This way OpenMP will be
# used only when the compiler supports it. OpenMP is enabled on a case-by-case
# basis for some subports by adding 'compiler.openmp_version 4.0' and setting
# PACKAGENAME_USE_OPENMP=ON for CMake.
#
# Additionally we set:
# -DBUILD_STATIC_LIBS=OFF: Disable building static libraries
# -DSUITESPARSE_INCLUDEDIR_POSTFIX="": Install headers into 'include' instead of
# 'include/suitesparse' for compatibility with older packages such as sundials5.
configure.args-append       -DBUILD_STATIC_LIBS=OFF -DSUITESPARSE_INCLUDEDIR_POSTFIX=""

# Necessary for CMake's FindOpenMP to function correctly
compiler.log_verbose_output no

subport SuiteSparse_config {
    PortGroup               linear_algebra 1.0

    version                 7.10.1
    revision                0
    # from the README.txt:
    #    "[n]o licensing restrictions apply"
    license                 Permissive
    linalg.setup            noveclibfort
    pre-configure {
        configure.args-append   ${cmake_linalglib}
    }
    # OpenMP is not essential for SuiteSparse_config, we turn it off
    configure.args-append   -DSUITESPARSE_CONFIG_USE_OPENMP=OFF
}

subport SuiteSparse_AMD {
    version                 3.3.3
    revision                0
    depends_lib-append      port:SuiteSparse_config
    license                 BSD
    long_description-append ${subport}: approximate minimum degree ordering.
}

subport SuiteSparse_BTF {
    version                 2.3.2
    revision                0
    depends_lib-append      port:SuiteSparse_config
    license                 LGPL-2.1+
    long_description-append ${subport}: permutation to block triangular form.
}

subport SuiteSparse_CAMD {
    version                 3.3.3
    revision                0
    depends_lib-append      port:SuiteSparse_config
    license                 BSD
    long_description-append ${subport}: constrained approximate minimum degree ordering.
}

subport SuiteSparse_CCOLAMD {
    version                 3.3.4
    revision                0
    depends_lib-append      port:SuiteSparse_config
    license                 BSD
    long_description-append ${subport}: constrained column approximate minimum degree ordering.
}

subport SuiteSparse_CHOLMOD {
    PortGroup               linear_algebra 1.0

    version                 5.3.1
    revision                0
    depends_lib-append      port:SuiteSparse_config port:SuiteSparse_AMD port:SuiteSparse_CAMD port:SuiteSparse_COLAMD port:SuiteSparse_CCOLAMD
    license                 LGPL-2.1+
    long_description-append ${subport}: sparse Cholesky factorization.
    linalg.setup            noveclibfort
    pre-configure {
        configure.args-append   ${cmake_linalglib}
    }
    # OpenMP is not essential for CHOLMOD, we turn it off
    configure.args-append   -DCHOLMOD_USE_OPENMP=OFF
}

subport SuiteSparse_COLAMD {
    version                 3.3.4
    revision                0
    depends_lib-append      port:SuiteSparse_config
    license                 BSD
    long_description-append ${subport}: column approximate minimum degree ordering.
}

subport SuiteSparse_CXSparse {
    version                 4.4.1
    revision                0
    depends_lib-append      port:SuiteSparse_config
    license                 LGPL-2.1+
    long_description-append ${subport}: a concise extended sparse matrix package.
}

subport SuiteSparse_GraphBLAS {
    version                 10.0.1
    revision                0
    license                 Apache-2
    long_description-append ${subport}: graph algorithms in the language of linear algebra.
    compiler.openmp_version 4.0
    compiler.cxx_standard   2011
    # OpenMP is essential for reasonable performance with GraphBLAS
    configure.args-append   -DGRAPHBLAS_USE_OPENMP=ON
    # Workaround on El Capitan and earlier
    # See https://github.com/DrTimothyAldenDavis/SuiteSparse/issues/735
    if {${os.platform} eq "darwin" && ${os.major} <= 15} {
        configure.args-append   -DGBNCPUFEAT=ON
    }
}

subport SuiteSparse_KLU {
    version                 2.3.5
    revision                0
    depends_lib-append      port:SuiteSparse_config port:SuiteSparse_AMD port:SuiteSparse_BTF port:SuiteSparse_COLAMD port:SuiteSparse_CHOLMOD
    license                 LGPL-2.1+
    long_description-append ${subport}: sparse LU factorization, primarily for circuit simulation.
}

subport SuiteSparse_LDL {
    version                 3.3.2
    revision                0
    depends_lib-append      port:SuiteSparse_config port:SuiteSparse_AMD
    license                 LGPL-2.1+
    long_description-append ${subport}: a very concise LDL' factorization package.
}

subport SuiteSparse_LAGraph {
    version                 1.1.5
    revision                0
    depends_lib-append      port:SuiteSparse_GraphBLAS
    license                 BSD
    long_description-append ${subport}: graph algorithms implemented using GraphBLAS.
    compiler.openmp_version 4.0
    # OpenMP is essential for reasonable performance with GraphBLAS and LAGraph
    configure.args-append   -DLAGRAPH_USE_OPENMP=ON
}

subport SuiteSparse_Mongoose {
    version                 3.3.4
    revision                0
    depends_lib-append      port:SuiteSparse_config
    license                 GPL-3
    long_description-append ${subport}: graph partitioning.
    compiler.cxx_standard   2011
}

subport SuiteSparse_ParU {
    PortGroup               linear_algebra 1.0

    version                 1.0.0
    revision                0
    depends_lib-append      port:SuiteSparse_config port:SuiteSparse_CHOLMOD port:SuiteSparse_UMFPACK port:SuiteSparse_AMD port:SuiteSparse_COLAMD port:SuiteSparse_CAMD port:SuiteSparse_CCOLAMD
    license                 GPL-3
    long_description-append ${subport}: solving sparse linear system via parallel multifrontal LU factorization algorithms.
    linalg.setup            noveclibfort
    pre-configure {
        configure.args-append   ${cmake_linalglib}
    }
    compiler.openmp_version 4.5
    configure.args-append   -DPARU_USE_OPENMP=ON
}

subport SuiteSparse_RBio {
    version                 4.3.4
    revision                0
    depends_lib-append      port:SuiteSparse_config
    license                 GPL-2+
    long_description-append ${subport}: read/write sparse matrices in Rutherford/Boeing format.
}

subport SuiteSparse_SPEX {
    version                 3.2.3
    revision                0
    depends_lib-append      port:SuiteSparse_config port:SuiteSparse_AMD port:SuiteSparse_COLAMD \
                            port:gmp \
                            port:mpfr
    license                 GPL-3+
    long_description-append ${subport}: a software package for SParse EXact algebra.
}

subport SuiteSparse_SPQR {
    PortGroup               linear_algebra 1.0

    version                 4.3.4
    revision                0
    depends_lib-append      port:SuiteSparse_config port:SuiteSparse_AMD port:SuiteSparse_COLAMD port:SuiteSparse_CHOLMOD
    license                 GPL-2+
    long_description-append ${subport}: sparse QR factorization.
    linalg.setup            noveclibfort
    pre-configure {
        configure.args-append   ${cmake_linalglib}
    }
    compiler.cxx_standard   2011
}

subport SuiteSparse_UMFPACK {
    PortGroup               linear_algebra 1.0

    version                 6.3.5
    revision                0
    depends_lib-append      port:SuiteSparse_config port:SuiteSparse_AMD port:SuiteSparse_CHOLMOD
    license                 GPL-2+
    long_description-append ${subport}: sparse LU factorization.
    linalg.setup            noveclibfort
    pre-configure {
        configure.args-append   ${cmake_linalglib}
    }
}


if {${subport} eq ${name}} {
    depends_lib-append      port:SuiteSparse_config \
                            port:SuiteSparse_GraphBLAS \
                            port:SuiteSparse_LAGraph \
                            port:SuiteSparse_Mongoose \
                            port:SuiteSparse_AMD \
                            port:SuiteSparse_BTF \
                            port:SuiteSparse_CAMD \
                            port:SuiteSparse_CCOLAMD \
                            port:SuiteSparse_COLAMD \
                            port:SuiteSparse_CHOLMOD \
                            port:SuiteSparse_CXSparse \
                            port:SuiteSparse_LDL \
                            port:SuiteSparse_KLU \
                            port:SuiteSparse_UMFPACK \
                            port:SuiteSparse_ParU \
                            port:SuiteSparse_RBio \
                            port:SuiteSparse_SPQR \
                            port:SuiteSparse_SPEX

    license                 BSD
    master_sites
    distfiles
    extract.rename          no
    patchfiles
    use_configure           no
    supported_archs         noarch
    platforms               any
    build {}
    # create a dummy file so the port can be successfully activated
    destroot {
        xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${subport}
        set    docfile      [open ${destroot}${prefix}/share/doc/${subport}/README.txt "w"]
        puts  ${docfile}    "Meta-port for ${name}"
        puts  ${docfile}    "${long_description}"
        close ${docfile}
    }
} else {
    PortGroup               compilers 1.0
    PortGroup               cmake 1.1

    compilers.choose        cc cpp cxx
    compilers.setup

    if {${subport} eq "SuiteSparse_config"} {
        set SuiteSparse_name    ${subport}
    } else {
        set SuiteSparse_name    [join [lrange [split ${subport} _] 1 end] _]
    }

    cmake.source_dir    ${worksrcpath}/${SuiteSparse_name}
}
