# -*- 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           active_variants 1.1
PortGroup           cmake 1.1
PortGroup           wxWidgets 1.0
PortGroup           github 1.0

github.setup        wxMaxima-developers wxmaxima 24.01.0 Version-
revision            0
checksums           rmd160  175c29dd96bca5ea5d5cf50b9fcc57b7ab99727c \
                    sha256  514e97b36a7dddbb9583d5b262f330330e0b5aa1379f7a6ae1f6ada1c50cc6b5 \
                    size    16501208

name                wxMaxima
maintainers         @MSoegtropIMC
license             GPL-2
# openssl is a dependency of curl in cmake, so build only
license_noconflict  openssl
categories          math aqua
description         Graphical user interface for Maxima based on wxWidgets
long_description    Maxima is a Computer Algebra System (CAS) and wxMaxima is a work book style \
                    graphical front end for it based on wxWidgets

github.tarball_from archive

universal_variant   no

compiler.cxx_standard \
                    2014
compiler.openmp_version 3.0

# https://github.com/wxMaxima-developers/wxmaxima/issues/1784
compiler.blacklist-append \
                    {clang < 1316} \
                    macports-clang-3.* \
                    {macports-clang-[4-9].0} \
                    {macports-clang-1[0-2]}

if {${os.platform} eq "darwin" && ${os.major} > 15} {
    wxWidgets.use   wxWidgets-3.2
} elseif {${os.platform} eq "darwin" && ${os.major} > 11} {
    wxWidgets.use   wxWidgets-3.0-cxx11
} else {
    PortGroup       legacysupport 1.1

    legacysupport.redirect_bins wxmaxima

    wxWidgets.use   wxGTK-3.0-cxx11

    # We really do not want to build a MacOS-style app with GTK here.
    # It will build, but the app can only run when its binary is called from CLI.
    # Also, we need a malloc fix here, which does not really work with bundles.
    patchfiles-append \
                    patch-no-bundle.diff

    configure.args-append \
                    -DWXM_DISABLE_WEBVIEW=YES
}

depends_lib-append  port:maxima \
                    port:${wxWidgets.port}

if {[string match *clang* ${configure.compiler}]} {
    depends_lib-append \
                    port:libomp

    configure.cppflags-append \
                    -I${prefix}/include/libomp
}

depends_run-append  port:gnuplot

post-patch {
    reinplace -W ${worksrcpath} "s|OSX_MACPORTS_PREFIX \"/opt/local\"|OSX_MACPORTS_PREFIX \"${prefix}\" // patched by MacPorts|" src/Dirstructure.h
    reinplace -W ${worksrcpath} "s|OSX_MACPORTS_PREFER 0|OSX_MACPORTS_PREFER 1 // patched by MacPorts|" src/Dirstructure.h
}

configure.args-append \
                    -DCMAKE_BUILD_TYPE=Release \
                    -DCCACHE_PROGRAM= \
                    -DUSE_CPPCHECK=YES \
                    -DwxWidgets_CONFIG_EXECUTABLE:FILEPATH=${wxWidgets.wxconfig}

destroot {
    if {${os.platform} eq "darwin" && ${os.major} > 11} {
        copy ${build.dir}/src/wxmaxima.app ${destroot}${applications_dir}/wxMaxima.app
    } else {
        copy ${build.dir}/src/wxmaxima ${destroot}${prefix}/bin/
    }
}

notes "
wxMaxima is installed under '${applications_dir}/wxMaxima.app'.\
You can start it from there via Finder.\
If you want to add wxMaxima to the Dock, start it via Finder,\
right-click the icon in Dock and select 'Options/Keep in Dock'.

wxMaxima should be able to find maxima and gnuplot at the MacPorts install\
folder '${prefix}/bin/' and also at a few non-MacPorts locations.\
In case you have issues with finding maxima, open wxMaxima Preferences and\
under the second tab (maxima) enter your path to the maxima executable and\
in the last tab (startup) add this command:
  gnuplot_command:\"<yourgnuplotpath>/gnuplot\"$
You might have to restart wxMaxima for this to take effect.

wxMaxima and Maxima startup files can typically be found in:
  ~/.maxima
"

github.livecheck.regex  {([a-z0-9.]+)}
