# -*- 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           compilers 1.0
PortGroup           cmake 1.1
PortGroup           gitlab 1.0
PortGroup           muniversal 1.1

name                eigen3
gitlab.setup        libeigen eigen 3.4.1
revision            0

categories          math science
license             {MPL-2 LGPL-2.1+ Apache-2 BSD Minpack}
maintainers         {eborisch @eborisch} {@barracuda156 gmail.com:vital.had} \
                    openmaintainer

description         A C++ template library for linear algebra: vectors, \
                    matrices, and related algorithms.
long_description    {*}${description}

homepage            https://libeigen.gitlab.io

checksums           rmd160  d9e19bc11df8b106f0e93271785474d335df8052 \
                    sha256  8bb7280b7551bf06418d11a9671fdf998cb927830cf21589b394382d26779821 \
                    size    2157363

compiler.cxx_standard   2011

# Eigen's source code specifically checks the version of Apple Clang.
compiler.blacklist-append   {clang < 900}

depends_build-append \
                    path:bin/pkg-config:pkgconfig

configure.env-append    PKG_CONFIG_LIBDIR=${prefix}/lib/pkgconfig

configure.args-append \
                    -DEIGEN_BUILD_BLAS=OFF \
                    -DEIGEN_BUILD_LAPACK=OFF \
                    -DEIGEN_BUILD_DOC_DEFAULT=OFF

build.env-append    EIGEN_MAKE_ARGS=-j{build.jobs}

variant doc description {Place local documentation into <prefix>/share/doc/eigen3/html} {
    compilers.choose    cc cxx cpp
    compilers.setup

    depends_build-append    path:bin/doxygen:doxygen \
                            port:texlive-latex \
                            path:bin/dot:graphviz

    configure.args-replace  -DEIGEN_BUILD_DOC_DEFAULT=OFF \
                            -DEIGEN_BUILD_DOC_DEFAULT=ON
}

variant blas description {Build eigen's blas (libeigen_blas*)} {
    compilers.choose    cc cxx cpp fc f77 f90
    compilers.setup     require_fortran

    universal_variant       yes
    configure.universal_args ""

    configure.args-replace \
                    -DEIGEN_BUILD_BLAS=OFF -DEIGEN_BUILD_BLAS=ON \
                    -DEIGEN_BUILD_LAPACK=OFF -DEIGEN_BUILD_LAPACK=ON
}


if {![variant_isset blas] && ![variant_isset doc]} {
    supported_archs     noarch
    platforms           any
    compilers.setup
}

test.run            yes
test.target         check
test.env-append     EIGEN_MAKE_ARGS=-j{build.jobs} \
                    EIGEN_CTEST_ARGS=-j{build.jobs}

pre-destroot {
    set build_suffix {}
    if {![info exists universal_archs_to_use]} {
        lappend build_suffix ""
    } else {
        set dash "-"
        foreach arch ${universal_archs_to_use} {
            lappend build_suffix ${dash}${arch}
        }
    }

    foreach sfx ${build_suffix} {
        # Install documentation if requested
        if {[variant_isset doc] && [string equal ${sfx} [lindex ${build_suffix} 0]]} {
                set docdir ${destroot}${prefix}/share/doc/eigen3
                xinstall -d ${docdir}
                # The documentation created is slightly different for each arch
                # which makes muniversal hiccup. Just copy one set of docs
                # into destroot directories.
                file copy ${cmake.build_dir}${sfx}/doc/html ${docdir}
        }

        if {[variant_isset blas]} {
            set libdir ${destroot}${sfx}${prefix}/lib
            xinstall -d ${libdir}
            file copy \
                {*}[glob ${cmake.build_dir}${sfx}/blas/libeigen_blas*] ${libdir}
        }
    }
}

post-destroot {
    # Install license information
    set docdir ${destroot}${prefix}/share/doc/eigen3
    xinstall -d ${docdir}
    xinstall -m 0644 {*}[glob ${worksrcpath}/COPYING.*] ${docdir}

    # Grab extra items install doesn't out of unsupported
    foreach n {README.txt bench} {
        file copy ${worksrcpath}/unsupported/${n} \
            ${destroot}${prefix}/include/eigen3/unsupported
    }

    # Install FindEigen3.cmake file, if it is provided.
    xinstall -d ${destroot}${cmake_share_module_dir}
    if {[file exists ${worksrcpath}/cmake/FindEigen3.cmake]} {
        xinstall -m 0444 ${worksrcpath}/cmake/FindEigen3.cmake \
            ${destroot}${cmake_share_module_dir}
    }
}

gitlab.livecheck.regex {(3\.[0-9.]+)}

notes "
This product includes software developed by the University of Chicago, as\
Operator of Argonne National Laboratory.
"

# remove after February 18, 2027
subport eigen3-devel {
    PortGroup       obsolete 1.0

    version         3.4-tracking-20241122
    revision        0
    epoch           3
    replaced_by     eigen3
}
