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

name                stimfit
version             0.16.6
revision            1
checksums           rmd160  72a0675c28b133a55ee98ea882434fe7f94d4088 \
                    sha256  8448e27fa48d7e04f788c8d636a07596ffeaddcfde15e8d6f41e6f356cb58d44 \
                    size    1918670

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}

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      --disable-dependency-tracking \
                    --disable-silent-rules \
                    --disable-python \
                    --with-biosiglite \
                    --with-wx-config=${wxWidgets.wxconfig}

set python_branches {3.9 3.10 3.11 3.12 3.13}

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.python \
            ${prefix}/bin/python${python_branch}

        configure.args-replace \
            --disable-python \
            --enable-python

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

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

    configure.args-append \
        --with-lapack-lib=${prefix}/lib/libatlas.a
}

configure.ldflags-append \
                    -headerpad_max_install_names

destroot.destdir    DESTDIR=${destroot}${applications_dir}

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