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

name                libsdl2-powerpc
conflicts           libsdl2-snowleopard
github.setup        libsdl-org SDL 2.30.10 release-
revision            0
categories          devel multimedia
platforms           {darwin < 11}
supported_archs     ppc ppc64
license             zlib
maintainers         {@barracuda156 gmail.com:vital.had}
description         Cross-platform multi-media development API
long_description    Simple DirectMedia Layer is a cross-platform development library \
                    designed to provide low-level access to audio, keyboard, mouse, \
                    joystick and graphics hardware via OpenGL and Direct3D. This port \
                    is aimed at supporting macOS PowerPC and uses X11 backend.

homepage            https://www.libsdl.org

github.tarball_from releases
distname            SDL2-${version}
checksums           rmd160  af0c5cc2fca394c7a0fd3aaf155a215d6d706a1b \
                    sha256  f59adf36a0fcf4c94198e7d3d776c1b3824211ab7aeebeb31fe19836661196aa \
                    size    7586495

depends_lib-append  port:xorg-libX11 \
                    port:xorg-libXcursor \
                    port:xorg-libXfixes \
                    port:xorg-libXi \
                    port:xorg-libXinerama \
                    port:xorg-libXrandr \
                    port:xorg-libXScrnSaver \
                    port:xorg-libXxf86vm \
                    port:xrender

# xorg-server does not build presently on any PowerPC macOS.
depends_run-append  port:xorg-server-legacy

configure.args-append \
                    --disable-dbus \
                    --disable-esd \
                    --disable-libsamplerate \
                    --disable-pulseaudio \
                    --disable-video-cocoa \
                    --disable-video-opengl \
                    --disable-video-wayland \
                    --disable-x11-shared \
                    --enable-video-x11 \
                    --x-includes=${prefix}/include \
                    --x-libraries=${prefix}/lib

# Disable Jack until this is fixed:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61759
configure.args-append \
                    --disable-jack

# Should be fixable once this is backported:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105522
# Until then, disable it.
configure.args-append \
                    --disable-joystick

# FIXME: look into fixing CoreAudio module for Tiger.
if {${os.platform} eq "darwin" && ${os.major} < 9} {
    configure.args-append \
                    --disable-audio \
                    --disable-haptic \
                    --disable-hidapi \
                    --disable-hidapi-joystick \
                    --disable-locale
}

build.args          V=1

# Disable broken compilers:
compiler.blacklist  *clang* *gcc-4.*

# Fix-ups for PowerPC systems:
patchfiles-append   0001-Fixes-for-PowerPC.patch

# Fix building against Macports X11.
patchfiles-append   0002-fix-x11.diff

# To be dropped once this is backported:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105522
patchfiles-append   0003-hidapi-revert-a-commit-that-triggers-ICE-with-GCC.patch

# Config header hardcodes wrong paths.
post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" \
                    ${worksrcpath}/include/SDL_config_macosx.h \
                    ${worksrcpath}/src/video/x11/SDL_x11opengl.c \
                    ${worksrcpath}/configure
}

variant dbus description "Enable DBus support" {
    depends_lib-append \
                    port:dbus
    configure.args-replace \
                    --disable-dbus --enable-dbus
}

# OpenGL via Mesa may lead to system freezes.
# For now, do not enable by default.
variant opengl description "Enable OpenGL support" {
    # Mesa dependency due to: https://trac.macports.org/ticket/61943
    # We cannot depend on XQuartz.
    depends_lib-append \
                    port:mesa
    configure.args-replace \
                    --disable-video-opengl --enable-video-opengl
}

variant pulseaudio description "Build with PulseAudio support" {
    depends_lib-append \
                    port:pulseaudio
    configure.args-replace \
                    --disable-pulseaudio --enable-pulseaudio
}

variant samplerate description "Build with libsamplerate support" {
    depends_lib-append \
                    port:libsamplerate
    configure.args-replace \
                    --disable-libsamplerate --enable-libsamplerate
}

post-destroot {
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} BUGS.txt CREDITS.txt LICENSE.txt \
        README-SDL.txt TODO.txt WhatsNew.txt \
        {*}[glob ${worksrcpath}/docs/*.md] ${destroot}${docdir}
}
