# -*- 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           boost 1.0
PortGroup           cmake 1.1
PortGroup           conflicts_build 1.0
PortGroup           github 1.0
PortGroup           legacysupport 1.1

github.setup        kpeeters cadabra2 2.5.14
revision            1

# Drop on next update:
if {${os.platform} eq "darwin" && ${os.major} < 10} {
    incr revision
}

categories          math
license             GPL-3+
maintainers         nomaintainer

description         A field theory approach to symbolic computer algebra
long_description    Cadabra is a computer algebra system for \
                    the manipulation of what could loosely be called \
                    tensorial expressions. It is aimed at, though not \
                    necessarily restricted to, theoretical high energy \
                    physicists. Because of its target audience, \
                    the program's interface, storage system and underlying \
                    philosophy differ substantially from other computer \
                    algebra systems.

homepage            https://cadabra.science/index.html

checksums           rmd160  012bacf39726c315cb409e6090fb096a4e9bc9e5 \
                    sha256  9e85977f49dae20230f4865a4f879d819cbfaaf3797d22adef1407990eab66ff \
                    size    33370920
github.tarball_from archive

# cadabra2-gtk(12276) malloc: *** error for object 0x365c034: Non-aligned pointer being freed
# legacysupport is only used for wrappers with libstdc++ builds.
legacysupport.newest_darwin_requires_legacy 0
legacysupport.redirect_bins cadabra-server cadabra2-cli cadabra2-gtk \
                    cadabra2cadabra cadabra2html cadabra2ipynb \
                    cadabra2latex cadabra2python cdb-nbtool

compiler.cxx_standard 2017

set python.version  313

set python.branch   [string index ${python.version} 0].[string range ${python.version} 1 end]
set python.prefix   ${frameworks_dir}/Python.framework/Versions/${python.branch}

# error: could not find git for clone of microtex-populate
depends_build-append \
                    path:bin/git:git \
                    port:pcrexx \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:adwaita-icon-theme \
                    port:dvipng \
                    port:gmp \
                    port:gtkmm3 \
                    port:hicolor-icon-theme \
                    port:pcre \
                    port:py${python.version}-sympy \
                    port:sqlite3

# See: https://github.com/macports/macports-ports/commit/351cf2678d137a5caa70f3423b550838f1ff3fa0
if {${os.platform} eq "darwin" && ${os.major} < 23} {
    compiler.blacklist-append \
                    clang
}

# cadabra2 uses its own bundled version of nlohmann/json.hpp
conflicts_build     nlohmann-json

configure.args      -DENABLE_MATHEMATICA=OFF \
                    -DPYBIND11_PYTHON_VERSION=${python.branch} \
                    -DSQLITE3_INCLUDE_DIR=${prefix}/include

post-destroot {
    ln ${destroot}${python.prefix}/lib/python${python.branch}/site-packages/cadabra2.cpython-${python.version}-darwin.so \
            ${destroot}${prefix}/lib/cadabra2.cpython-${python.version}-darwin.so
}

post-activate {
    system "${prefix}/bin/texhash"
    system "gtk-update-icon-cache ${prefix}/share/icons/hicolor"
}

variant texmacs description {install TeXmacs front end} {
    depends_run-append      port:TeXmacs
}

github.livecheck.regex  {(\d\.\d+(\.\d+))}
