# -*- 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.0

name                mathgl
version             8.0.3
revision            1
categories          math
license             GPL-3
maintainers         {mps @Schamschula} openmaintainer
description         MathGL is a library for making high-quality scientific graphics.
long_description    {*}${description} MathGL is also a library for the fast data \
                    plotting and data processing of large data arrays a library for \
                    working in window and console modes and for easy embedding into \
                    other programs and a library with large and growing set of graphics.
platforms           darwin
homepage            http://mathgl.sourceforge.net/
master_sites        sourceforge

checksums           rmd160  9efdd7655932d0f7f6c2cd0de7d197b7a2aaf857 \
                    sha256  9bba9ee6a0f86d1b8f3f3ba0374d3cb776f772dbb6f1a01684ca6c0bd56204d6 \
                    size    242167802

depends_build-append \
                    port:gettext

depends_lib-append  path:lib/libfltk.dylib:fltk \
                    port:gettext-runtime \
                    port:giflib \
                    port:libpng \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:zlib \
                    port:gsl \
                    port:hdf5

# find correct site-package location
#patchfiles-append   patch-python.diff

configure.args-append \
                    -Denable-arma=OFF \
                    -Denable-fltk=ON \
                    -Denable-gif=ON \
                    -Denable-png=ON \
                    -Denable-jpeg=ON \
                    -Denable-gsl=ON \
                    -Denable-hdf5=ON \
                    -Denable-openmp=OFF \
                    -Denable-zlib=ON \
                    -Denable-glut=OFF \
                    -Denable-wx=OFF \
                    -Denable-pdf=OFF \
                    -Denable-qt4=OFF \
                    -Denable-qt5=OFF \
                    -Denable-python=OFF \
                    -Denable-lua=OFF \
                    -Denable-octave=OFF

# install cmake files in the correct location
configure.args-append \
                    -DMGL_LIB_INSTALL_DIR=${prefix}/lib

configure.cflags-append \
                    -DH5_USE_18_API

# currently broken
# see https://sourceforge.net/p/mathgl/discussion/508393/thread/fb61ebd073/
# variant arma description {Enable armadillo support} {
#     compiler.cxx_standard           2011
#     compiler.thread_local_storage   yes
# 
#     depends_lib-append  port:armadillo
#     configure.args-replace -Denable-arma=OFF -Denable-arma=ON
# }

#currently broken
#variant pdf description {Enable pdf support} {
#    depends_lib-append port:libharu
#    configure.args-replace -Denable-pdf=OFF -Denable-pdf=ON
#}

variant mpich description {Use hdf5 with mpich} {
    PortGroup       active_variants 1.1
    PortGroup       mpi 1.0

    require_active_variants     hdf5   mpich
}

variant python39 conflicts python310 python311 python312 python313 description {Use Python 3.9} {}
variant python310 conflicts python39 python311 python312 python313 description {Use Python 3.10} {}
variant python311 conflicts python39 python310 python312 python313 description {Use Python 3.11} {}
variant python312 conflicts python39 python310 python311 python313 description {Use Python 3.12} {}
variant python313 conflicts python39 python310 python311 python312 description {Use Python 3.13} {}

if {![variant_isset python39] && ![variant_isset python310] && ![variant_isset python311] && ![variant_isset python312]} {
    default_variants +python313
}

foreach pv {313 312 311 310 39} {
    if {[variant_isset python${pv}]} {
        set python_branch "[string index ${pv} 0].[string range ${pv} 1 end]"
        depends_build-append port:swig-python

        depends_lib-append  \
                    port:python${pv}   \
                    port:py${pv}-numpy

        configure.args-replace -Denable-python=OFF -Denable-python=ON
        configure.args-append  -DPYTHON_EXECUTABLE=${prefix}/bin/python${python_branch}

        pre-destroot {
            reinplace "s|-38.pyc|-${pv}.pyc|" ${worksrcpath}/lang/cmake_install.cmake
        }

        break
    }
}

variant qt5 description {Enable Qt5 widget} {
    PortGroup qt5 1.0
    qt5.depends_component \
                    qtwebkit
    configure.args-replace \
                    -Denable-qt5=OFF -Denable-qt5=ON

    # avoid dependency on qt5-qtwebkit
    #configure.args-append  -Denable-json-sample=OFF
}

livecheck.type      regex
livecheck.url       ${homepage}/doc_en/Download.html
livecheck.regex     "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
