# -*- 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           active_variants 1.1
PortGroup           openssl 1.0

openssl.branch      1.1

name                racket
version             8.17
revision            1
categories          lang scheme
license             Apache-2 MIT
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
description         Scheme programming environment
long_description    Interactive, integrated, graphical {*}${description}.

homepage            https://racket-lang.org

master_sites        https://download.racket-lang.org/releases/${version}/installers/ \
                    https://mirror.racket-lang.org/installers/${version}/ \
                    https://www.cs.utah.edu/plt/installers/${version}/ \
                    https://www.eecs.northwestern.edu/racket/${version}/ \
                    https://mirror.csclub.uwaterloo.ca/racket/racket-installers/${version}/ \
                    https://mirror.informatik.uni-tuebingen.de/mirror/racket/${version}/ \
                    https://racket.infogroep.be/${version}/
distname            ${name}-${version}-src
extract.suffix      .tgz

checksums           rmd160  088fc40b0e8480f267b9ebda083590b89cb22fb7 \
                    sha256  44431395138f7b8c5e67d416ff063b8fb6ce056f4c4f0fda27b7b1ec58bfa33b \
                    size    34341785

extract.rename      yes

patch.dir           ${workpath}/${distname}

# https://github.com/racket/racket/issues/5025
# diff -NaurdwB -I '^;;[[:space:]]*' ./racket-orig/ ./racket-new | sed -E -e 's/\.\/racket-(orig|new)/\./g' > ~/Downloads/paths-to-openssl.diff
patchfiles-append   paths-to-openssl.diff

post-patch {
    foreach rkt {libcrypto.rkt libssl.rkt} {
        reinplace "s|@@PREFIX@@|${prefix}|g" \
                    ${worksrcpath}/../collects/openssl/${rkt}
    }

    # https://github.com/racket/racket/issues/5055#issuecomment-2321445579
    reinplace -E \
        "s|^#hash\\((.+)\\)$|#hash(\\1 (lib-search-dirs . (\"${prefix}/lib\" #f)))|" \
                    ${worksrcpath}/../etc/config.rktd
}

worksrcdir          ${worksrcpath}/src

depends_build-append \
                    port:libtool

depends_lib-append  port:fontconfig \
                    port:gdk-pixbuf2 \
                    port:gtk2 \
                    port:libffi \
                    port:libiconv \
                    port:lz4 \
                    port:ncurses \
                    port:zlib

require_active_variants gtk2 x11

configure.args-append \
                    --enable-curses \
                    --enable-liblz4 \
                    --enable-libz \
                    --enable-pthread \
                    --enable-xonx

if {${configure.build_arch} in [list ppc ppc64]} {
    # Stripping may fail on PowerPC:
    # https://github.com/racket/racket/issues/5021
    configure.args-append \
                    --disable-strip \
                    --enable-bigendian
}

livecheck.type      regex
livecheck.url       https://racket-lang.org
livecheck.regex     {>Racket version ((?:\d+\.?)+)<}
