# -*- 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           github 1.0
PortGroup           legacysupport 1.1
PortGroup           linear_algebra 1.0
PortGroup           makefile 1.0
PortGroup           mpi 1.0

github.setup        cfdemons LUMA 1.7.12 Release_
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
name                luma
revision            3
categories          science
license             Apache-2
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Open-source project Lattice-Boltzmann at the University of Manchester (LUMA)
long_description    {*}${description}
checksums           rmd160  2c220f3f833da786754a8e1c547b3e0fadddc1d1 \
                    sha256  d485c046d622fb2ea4159b4eaa657d06c23e6d458496676576c65ba57e468ea9 \
                    size    53192327

veclibfort          no

worksrcdir          ${worksrcpath}/LUMA

patchfiles-append   patch-makefile.diff \
                    patch-fix-includes.diff \
                    patch-tests.diff

post-patch {
    reinplace "s,@MPICXX@,${mpi.cxx}," ${worksrcdir}/makefile
    reinplace "s,@PREFIX@,${prefix},g" ${worksrcdir}/makefile
    reinplace "s,@LAPACK@,${linalglib}," ${worksrcdir}/makefile
    reinplace "s,@MPICXX@,${mpi.cxx}," ${worksrcdir}/cases/testsuite/scripts/runTestSuite.sh
    reinplace "s,@PREFIX@,${prefix}," ${worksrcdir}/cases/testsuite/scripts/runTestSuite.sh
}

compiler.openmp_version 2.5
compilers.choose    cxx

# Until mpich-defailt is enabled with gcc:
if {${os.platform} eq "darwin" && ${os.arch} eq "powerpc"} {
    mpi.setup       require \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 \
                    -clang -fortran
} else {
    mpi.setup       require \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48
}

depends_build-append \
                    port:pkgconfig
depends_lib-append  port:hdf5 \
                    port:zlib

configure.pre_args-append \
                    -DMPIRUN=${prefix}/bin/${mpi.exec}

if {[string match *clang* ${configure.compiler}]} {
    configure.ldflags-append \
                    -L${prefix}/lib/libomp \
                    -lomp
}

legacysupport.redirect_bins LUMA

build.target        LUMA

destroot {
    copy ${worksrcdir}/LUMA ${destroot}${prefix}/bin
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${workpath}/LUMA-${version} LICENSE NOTICE README.md ${destroot}${docdir}
    foreach dir {docs scripts tools} {
        copy ${worksrcdir}/${dir} ${destroot}${docdir}
    }
}

# These are settings to run test suite, however at the moment tests fail to compile.
# See: https://github.com/cfdemons/LUMA/issues/25
test.dir            ${worksrcdir}/cases/testsuite/scripts
test.cmd            ./runTestSuite.sh
test.target
test.run            yes
