# -*- 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.36
revision            0
categories-append   graphics
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
license             GPL
description         3D visualization using OpenGL
long_description    {*}${description}
homepage            https://dmurdoch.github.io/rgl
checksums           rmd160  7962fece2d4e01cc50d0799a88b507719cf3fec9 \
                    sha256  15570af26b4c3c62cc66d05dced8e7d6b7c363ded97450ae4eba97c6d7491547 \
                    size    4143956

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

depends_lib-append  path:lib/pkgconfig/freetype2.pc: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 \
                    port:R-xdvir

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
