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

# Revert to GitHub once updated there.
R.setup             cran dmurdoch rgl 1.3.14
revision            0
categories-append   graphics
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             GPL
description         3D visualization using OpenGL
long_description    {*}${description}
homepage            https://dmurdoch.github.io/rgl
checksums           rmd160  fa1b43118cf1ea44e067a865e2382e858207d11c \
                    sha256  9a44f7e0ba5c201a7df3168d2b493eb3344f84faaac807c704f52e6196d9c395 \
                    size    4067443

depends_build-append \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:freetype \
                    port:libpng \
                    port:R-base64enc \
                    port:R-htmltools \
                    port:R-htmlwidgets \
                    port:R-jsonlite \
                    port:R-knitr \
                    port:R-magrittr \
                    port:R-mime \
                    port:R-R6 \
                    port:zlib

# Enabling X11 breaks the build on Sonoma:
# https://trac.macports.org/ticket/68830
# https://github.com/dmurdoch/rgl/issues/397
if {(${os.platform} eq "darwin" && ${os.major} < 22) || ${os.platform} ne "darwin"} {
    depends_lib-append \
                    port:xorg-libX11

    build.args-append \
                    --configure-args="--with-x \
                        --x-includes=${prefix}/include/X11 \
                        --x-libraries=${prefix}/lib"
}

# https://github.com/dmurdoch/rgl/issues/317
if {${os.platform} eq "darwin" && ${os.major} < 11} {
    build.args-append \
                    --configure-args="--disable-opengl"
}

# Some deps are omitted.
depends_test-append port:R-alphashape3d \
                    port:R-crosstalk \
                    port:R-deldir \
                    port:R-downlit \
                    port:R-extrafont \
                    port:R-interp \
                    port:R-jpeg \
                    port:R-magick \
                    port:R-manipulateWidget \
                    port:R-markdown \
                    port:R-misc3d \
                    port:R-orientlib \
                    port:R-pkgdown \
                    port:R-plotrix \
                    port:R-png \
                    port:R-rmarkdown \
                    port:R-shiny \
                    port:R-testthat \
                    port:R-tripack \
                    port:R-waldo

if {${configure.build_arch} in [list arm64 x86_64]} {
    depends_test-append \
                    port:R-js \
                    port:R-V8
}

# Tests seem to pass fine even on old systems.
# On PowerPC I get two minor errors presently.
# One error in R-plot3d example:
# XIO:  fatal IO error 0 (Unknown error: 0) on X server "/tmp/launch-TJkOdD/org.macports:0"
# after 63713 requests (63713 known processed) with 0 events remaining.
# This is most likely a bug in xorg-server-legacy
# or rather specifically in its implementation for ppc.
# Another error is with parsing pre-release versions of Darwin:
# https://github.com/dmurdoch/rgl/issues/419
test.run            yes