# -*- 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           R 1.0

# Do not use GitHub version, it is broken.
R.setup             cran chkiefer lavacreg 0.2-2
revision            0
categories-append   math
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             GPL-2+
description         Latent variable count regression models
long_description    {*}${description}
checksums           rmd160  599eb74c1ed4bc9e42a0c2f26ca3d0dfa6722c32 \
                    sha256  8cf95777a5e9fbb6eea1c3d2cf328a0572f3965264f0e4681a6ac72245717849 \
                    size    52472

depends_lib-append  port:R-fastGHQuad \
                    port:R-pracma \
                    port:R-Rcpp \
                    port:R-RcppArmadillo \
                    port:R-SparseGrid

# See: https://github.com/chkiefer/lavacreg/issues/2
patchfiles          patch-openmp.diff \
                    patch-unbreak-clang-build.diff

post-patch {
    if {[string match macports-gcc* ${configure.compiler}]} {
        reinplace "s,@OMP_INC@,-fopenmp," ${worksrcpath}/src/Makevars
        reinplace "s,@OMP_LIB@,-fopenmp," ${worksrcpath}/src/Makevars
    } elseif {[string match macports-clang* ${configure.compiler}]} {
        reinplace "s,@OMP_INC@,-I${prefix}/include/libomp -fopenmp," ${worksrcpath}/src/Makevars
        reinplace "s,@OMP_LIB@,-L${prefix}/lib/libomp -lomp," ${worksrcpath}/src/Makevars
    }
}

compilers.setup     require_fortran
compiler.openmp_version 3.0

depends_test-append port:R-knitr \
                    port:R-rmarkdown \
                    port:R-testthat

test.run            yes
