PortSystem 1.0
PortGroup  github 1.0
PortGroup  compilers 1.0

compilers.setup     -clang -fortran

categories          science
maintainers         {eborisch @eborisch} openmaintainer
description         Toolbox for Computational Magnetic Resonance Imaging
long_description    {*}$description
github.setup        mrirecon bart 0.9.00 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            0
platforms           {darwin >= 17}
license             BSD
checksums \
    rmd160  25e0cd84ec7cc61caacf0d9ec9f9fa0992d0ba69 \
    sha256  bc64963bb64c2060a79ae856d9466b902edb680f81741a8b7734ed9587ef4b63 \
    size    1150755

if { ![c_variant_isset] } {
    default_variants-append +${compilers.gcc_default}
}

variant cuda description { Enable CUDA support } {
    build.env-append    CUDA=1
}

post-patch {
    reinplace -E "s^gcc-mp-\[0-9\]+^${configure.cc}^" Makefile
    reinplace "s^usr/local^${prefix}^" Makefile
}

patchfiles          Makefile.patch

use_configure       no
test.run            yes

post-build {
    system -W ${worksrcpath} "make doc/commands.txt"
}

destroot.keepdirs   ${destroot}${prefix}/lib/bart/commands

post-destroot {
    system -W ${worksrcpath} "mkdir -p ${destroot}${prefix}/share/bart"
    move ${destroot}${prefix}/share/doc/bart ${destroot}${prefix}/share/bart/doc
    copy ${worksrcpath}/LICENSE ${destroot}${prefix}/share/bart/doc
    copy ${worksrcpath}/python ${destroot}${prefix}/share/bart/
    copy ${worksrcpath}/matlab ${destroot}${prefix}/share/bart/
    copy ${worksrcpath}/scripts ${destroot}${prefix}/share/bart/
    foreach lib [glob ${worksrcpath}/lib/*.a ] {
        copy ${lib} ${destroot}${prefix}/lib/bart/
    }
}

depends_lib         port:fftw-3 \
                    port:fftw-3-single \
                    port:libpng \
                    port:openblas \
                    port:flock \
                    port:python311
