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

# Using commit since release is broken: https://github.com/cdslaborg/paramonte/issues/20
github.setup        cdslaborg paramonte 08b5ee74e1dc9045fca8fd7d94e3bbc979a3c425
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             1.5.1
revision            2
categories          math science fortran
license             MIT
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         ParaMonte: plain powerful parallel Monte Carlo and MCMC library
long_description    {*}${description}
homepage            https://www.cdslab.org/paramonte
checksums           rmd160  276593de1dd00faa48768f388372ec5d0df0b51f \
                    sha256  16d8756315f528725f02dd9d79b6099952deb7e6d8af1837619f971c0219ee44 \
                    size    4389174

cmake.build_type    Release

depends_build-append \
                    port:bash

# Needs Fortran 2008.
# Notice that it also needs Fortran to support ieee_arithmetic, which is not yet supported for PPC in Macports.
# Do not exclude PPC though, since experimental implementation for ieee_arithmetic exists for it.
if {${os.platform} eq "darwin" && ${os.arch} eq "powerpc"} {
    mpi.setup       require require_fortran \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5 -gcc6 \
                    -clang -fortran
} else {
    mpi.setup       require require_fortran \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5 -gcc6
}

compiler.openmp_version 3.0

# Fix install location:
patchfiles-append   patch-install.diff

configure.args-append \
                    -DBASIC_TEST_ENABLED:BOOL=ON \
                    -DCAF_ENABLED:BOOL=OFF \
                    -DCFI_ENABLED:BOOL=ON \
                    -DCODECOV_ENABLED:BOOL=OFF \
                    -DLTYPE:STRING=shared \
                    -DMPI_ENABLED:BOOL=ON \
                    -DMPIEXEC_EXECUTABLE=${prefix}/bin/${mpi.exec} \
                    -DOMP_ENABLED:BOOL=ON \
                    -DPERFPROF_ENABLED:BOOL=OFF \
                    -DPMCS:STRING=GNU \
                    -DPMLIB_INSTALL_NAME_DIR:STRING=${prefix}/lib \
                    -DPMLIB_NAME:STRING=paramonte \
                    -DSAMPLER_TEST_ENABLED:BOOL=ON \
                    -DTEST_RUN_ENABLED:BOOL=ON

universal_variant   no

# One test fails on ppc: https://github.com/cdslaborg/paramonte/issues/21
test.run            yes
test.cmd            ${cmake.build_dir}/test/obj/testParaMonte
# Fix malloc disaster:
test.cmd-prepend    DYLD_LIBRARY_PATH=${prefix}/lib/libgcc:${cmake.build_dir}/obj
# Yeah, it is a mess: data files are placed into bin, while a binary is sitting in obj. Eh.
test.dir            ${cmake.build_dir}/test/bin
test.target

# Given how oddly everything is placed, rather not move things around and get new errors
# but trash a test binary here, otherwise it gets installed.
post-destroot {
    delete ${destroot}${prefix}/var/macports/build
}
