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

R.setup             cran dmlc xgboost 1.7.8.1
revision            0
categories-append   math
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             Apache-2
description         Extreme Gradient Boosting
long_description    {*}${description}
checksums           rmd160  a686d5710e05e9a7205418f90357c9054e66f832 \
                    sha256  394d6fd00b2fe97549c7a7e6598df86448cdfbd7c0af45b0c17f7b9e81bc1be9 \
                    size    1086388

depends_build-append \
                    path:bin/cmake:cmake
depends_lib-append  port:R-data.table \
                    port:R-jsonlite

# See:
# https://github.com/dmlc/xgboost/issues/8946
# https://github.com/dmlc/xgboost/pull/8964
patchfiles          patch-unbreak-32-bit.diff \
                    patch-fix-OpenMP.diff

post-patch {
    reinplace "s,@OMP_PREFIX@,${prefix}," ${worksrcpath}/configure
    if {[string match macports-clang* ${configure.compiler}]} {
        reinplace "s,@OMP@,-lomp," ${worksrcpath}/configure
        reinplace "s,@INC@,include/libomp," ${worksrcpath}/configure
        reinplace "s,@LIB@,lib/libomp," ${worksrcpath}/configure
    } elseif {[string match macports-gcc* ${configure.compiler}]} {
        reinplace "s,@OMP@,-lgomp," ${worksrcpath}/configure
        reinplace "s,@INC@,," ${worksrcpath}/configure
        reinplace "s,@LIB@,lib/libgcc," ${worksrcpath}/configure
    }
}

depends_test-append port:R-Ckmeans.1d.dp \
                    port:R-crayon \
                    port:R-DiagrammeR \
                    port:R-float \
                    port:R-ggplot2 \
                    port:R-igraph \
                    port:R-knitr \
                    port:R-lintr \
                    port:R-rmarkdown \
                    port:R-testthat \
                    port:R-titanic \
                    port:R-vcd

test.run            yes
