# -*- 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  codeberg 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
codeberg.setup      mrirecon bart 1.0.00 v
revision            0
platforms           {darwin >= 17}
license             BSD
checksums \
    rmd160  75e74de6d8a531404a766543ae5b9df2877e1245 \
    sha256  b77676566ea202a2a825b68c5e515f9a3d5ecebdad329f78099f837ae77195fe \
    size    1481212

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
}

use_configure       no
build.cmd           ${prefix}/bin/gmake
test.run            yes

post-build {
    system -W ${worksrcpath} "${prefix}/bin/gmake doc/commands.txt"
}

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_build-append port:gmake

depends_lib-append  port:fftw-3 \
                    port:fftw-3-single \
                    port:libpng \
                    port:openblas \
                    port:flock \
                    port:python314
