# -*- 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 jeroen V8 4.4.2
revision            1
categories-append   devel
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             MIT
description         Embedded javascript and webassembly engine for R
long_description    {*}${description}
checksums           rmd160  3d32a14922b7454ee49267f4cf6c55759b5210c3 \
                    sha256  e7bc35f3420f5f537121d681a90c16a74b36dc17210c9425e7f03842493a9670 \
                    size    672334

# TODO: update V8 to the latest 8.x version. Keep PowerPC on 8.3 though.
# FIXME: fix the build on PowerPC.
set v8_ver          8.3

depends_lib-append  port:R-curl \
                    port:R-jsonlite \
                    port:R-Rcpp \
                    port:v8-${v8_ver}

patchfiles          patch-fix-configure.diff

if {[string match *gcc* ${configure.compiler}]} {
    patchfiles-append \
                    patch-gcc-permissive.diff
}

post-patch {
    reinplace "s|@V8@|v8-${v8_ver}|" ${worksrcpath}/configure
    reinplace "s|@V8_HOME@|${prefix}/libexec/v8-${v8_ver}|g" ${worksrcpath}/configure
    if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list i386 ppc]} {
        reinplace "s|@V8_LIBS@|-lv8_base_without_compiler -lv8_compiler -lv8_initializers -lv8_inspector -lv8_libbase -lv8_libplatform -lv8_libsampler -lv8_snapshot -latomic|" ${worksrcpath}/configure
    } else {
        reinplace "s|@V8_LIBS@|-lv8_base_without_compiler -lv8_compiler -lv8_initializers -lv8_inspector -lv8_libbase -lv8_libplatform -lv8_libsampler -lv8_snapshot|" ${worksrcpath}/configure
    }
}

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

test.run            yes
