# -*- 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           compilers 1.0
PortGroup           github 1.0
PortGroup           makefile 1.0

github.setup        mjlaine mcmcf90 67d6078137b7bdd6ed8ba84440ca99237301fe86
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             2023.04.06
revision            0
categories          math science fortran
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             MIT
description         Fortran library for MCMC calculations
long_description    This Fortran 90 library can be used to do Markov chain Monte Carlo simulation \
                    from a posterior distribution of unknown model parameters defined \
                    by a likelihood function and prior. The likelihood is given \
                    as “sum-of-squares” difference of observed values from modelled values.
homepage            https://mjlaine.github.io/mcmcf90
checksums           rmd160  2ef9feb1e1b30a07863c000cf8c2de11fe2e0bb8 \
                    sha256  112b9e1c07ca04e36adc4d0be01a8a919729edead1762218f0065cd206f9a3b2 \
                    size    56129

compilers.choose    fc f90
compilers.setup     require_fortran

compiler.blacklist-append \
                    *gcc-4.* {clang < 500}

depends_lib-append  path:lib/libopenblas.dylib:OpenBLAS

patchfiles-append   patch-dynlib.diff

post-patch {
    reinplace "s|F90=gfortran|F90=${configure.fc}|g" ${worksrcpath}/mac.mk
    reinplace "s|F77=gfortran|F77=${configure.fc}|g" ${worksrcpath}/mac.mk
    reinplace "s|F90=gfortran|F90=${configure.fc}|g" ${worksrcpath}/maci.mk
    reinplace "s|F77=gfortran|F77=${configure.fc}|g" ${worksrcpath}/maci.mk
    reinplace "s|@PREFIX@|${prefix}|" ${worksrcpath}/Makefile

    platform darwin 10 powerpc {
        # Rosetta hack:
        reinplace "s|maci.mk|mac.mk|g" ${worksrcpath}/Makefile
    }
}

use_parallel_build  no

destroot {
    copy ${worksrcpath}/libmcmcrun.a ${destroot}/${prefix}/lib/
    copy ${worksrcpath}/libmcmcrun.dylib ${destroot}/${prefix}/lib/
    xinstall -d ${destroot}${prefix}/include/${name}
    fs-traverse f ${worksrcpath} {
        if {[file isfile ${f}] && [file extension ${f}] == ".mod"} {
            copy ${f} ${destroot}${prefix}/include/${name}/
        }
    }
}
