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

name                stimfit
version             0.17.1
checksums           rmd160  9843ffbd4ac35da4237057fc1bb543fb12f2798b \
                    sha256  9e2aba63d1b8da0a55cf0b36a2751e1752b38f4e88795a3482a210141d029a94 \
                    size    20174565

categories          science
license             GPL-2
maintainers         {gmx.de:christsc @neurodroid}
description         Electrophysiology analysis suite
long_description    A program for viewing and analyzing electrophysiological data
homepage            http://www.stimfit.org
master_sites        ${homepage}
worksrcdir          Stimfit-${version}-Source

wxWidgets.use       wxWidgets-3.2

depends_build       port:gawk

depends_lib         port:fftw-3 \
                    port:hdf5 \
                    port:${wxWidgets.port}

compiler.cxx_standard \
                    2017

configure.args      -DSTF_ENABLE_PYTHON=OFF \
                    -DSTF_WITH_BIOSIG=ON \
                    -DSTF_BIOSIG_PROVIDER=SUBMODULE \
                    -DSTF_BUILD_MODULE=OFF \
                    -DSTF_BUILD_TESTS=OFF \
                    -DSTF_MACOS_APP_BUNDLE=ON \
                    -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig}

configure.pre_args  -S ${worksrcpath} -B ${workpath}/build
build.cmd           ${configure.cmd}
build.target        --build ${workpath}/build
destroot.cmd        ${configure.cmd}
destroot.target     --install ${workpath}/build
destroot.destdir    DESTDIR=${destroot}

set python_branches {3.10 3.11 3.12 3.13 3.14}

set none_selected 1
foreach python_branch ${python_branches} {
    set python_version [join [lrange [split ${python_branch} .] 0 1] ""]
    if {[variant_isset python${python_version}]} {
        set none_selected 0
        break
    }
}

if {$none_selected} {
    default_variants +python313
}

foreach python_branch ${python_branches} {
    set python_version [join [lrange [split ${python_branch} .] 0 1] ""]

    set variant_line {variant python${python_version} description "Enable Python ${python_branch} shell"}

    foreach over ${python_branches} {
        if {${python_branch} == ${over}} {
            continue
        }

        set over_no_dot [join [lrange [split ${over} .] 0 1] ""]
        append variant_line " conflicts python${over_no_dot}"
    }
    append variant_line { {}}

    eval $variant_line
}

foreach python_branch ${python_branches} {
    set python_version [join [lrange [split ${python_branch} .] 0 1] ""]
    if {[variant_isset python${python_version}]} {
        depends_build-append \
            port:swig-python \
            port:py${python_version}-setuptools

        depends_lib-replace \
            port:${wxWidgets.port} \
            port:py${python_version}-wxpython-4.0

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

        configure.args-replace \
            -DSTF_ENABLE_PYTHON=OFF \
            -DSTF_ENABLE_PYTHON=ON

        configure.args-replace \
            -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig} \
            -DwxWidgets_CONFIG_EXECUTABLE=${frameworks_dir}/Python.framework/Versions/${python_branch}/bin/wx-config

        configure.args-append \
            -DPython3_EXECUTABLE=${prefix}/bin/python${python_branch}
    }
}

variant atlas description {Use MacPorts ATLAS libraries} {
    depends_lib-append \
        port:atlas

    configure.args-append \
        -DBLA_VENDOR=ATLAS
}

configure.ldflags-append \
                    -headerpad_max_install_names

post-destroot {
    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    xinstall -m 644 ${worksrcpath}/dist/macosx/copyright \
        ${worksrcpath}/COPYING ${docdir}
}
