# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem 1.0
PortGroup github 1.0

name            libsdl12
github.setup    libsdl-org SDL-1.2 18bc4d1a1d27b0cf5b06be9322c65ca88282b1ee
version         1.2.15-20250302
categories      devel multimedia
platforms       macosx freebsd
license         LGPL-2.1+
maintainers     {jmr @jmroot} openmaintainer
description     Cross-platform multi-media development API

long_description \
    Simple DirectMedia Layer is a cross-platform multimedia library designed \
    to provide fast access to the graphics framebuffer and audio device. It is \
    used by MPEG playback software, emulators, and many popular games, including \
    the award winning Linux port of \"Civilization: Call To Power.\" Simple \
    DirectMedia Layer supports Linux, Win32, BeOS, macOS, Solaris, IRIX, and FreeBSD. \
    This is the legacy 1.2 branch.

homepage        https://www.libsdl.org/

github.tarball_from archive
checksums       rmd160 499e7e95862dd0d029fdef2a98685fc4f0bc8637 \
                sha256 f5fa17102e77bffd9e644f6c4cf1c9a91dc586f57b1402f2c95c3f972687e92b

configure.args  --disable-esd \
                --disable-nasm \
                --disable-pulseaudio \
                --without-x

variant x11 {
    configure.args-delete --without-x
    configure.args-append --x-includes=${prefix}/include \
                          --x-libraries=${prefix}/lib \
                          --disable-x11-shared
    depends_lib-append \
        port:xorg-libXext \
        port:xorg-libXrandr \
        port:xrender
}
if {${os.subplatform} ne "macosx"} {
    default_variants +x11
}

post-configure {
    if {[variant_exists universal] && [variant_isset universal]} {
        system -W ${worksrcpath}/include "ed - ./SDL_config.h < ${filespath}/include_SDL_config.h.ed"
    }
}

set docdir  ${prefix}/share/doc/${name}

post-destroot {
    # Allow installing in parallel with sdl12-compat
    set my_prefix ${prefix}/libexec/${name}
    xinstall -d ${destroot}${my_prefix}/bin \
                ${destroot}${my_prefix}/include \
                ${destroot}${my_prefix}/lib \
                ${destroot}${my_prefix}/share
    move ${destroot}${prefix}/bin/sdl-config ${destroot}${my_prefix}/bin
    move ${destroot}${prefix}/include/SDL ${destroot}${my_prefix}/include
    move {*}[glob ${destroot}${prefix}/lib/*] ${destroot}${my_prefix}/lib
    move ${destroot}${prefix}/share/aclocal ${destroot}${my_prefix}/share

    xinstall -d ${destroot}${docdir}/html

    xinstall -m 0644 -W ${worksrcpath} BUGS COPYING CREDITS INSTALL README.md README-SDL.txt \
        README.MacOSX TODO ${destroot}${docdir}

    xinstall -m 0644 -W ${worksrcpath} docs.html docs/index.html ${destroot}${docdir}/html
    reinplace {s@docs/@@g} ${destroot}${docdir}/html/docs.html

    foreach {dir} {html images} {
        xinstall -d ${destroot}${docdir}/html/${dir}
        xinstall -m 0644 {*}[glob ${worksrcpath}/docs/${dir}/*] ${destroot}${docdir}/html/${dir}
    }
}

# Remove after 2023-08-28
pre-activate {
    if {[file exists ${prefix}/share/man/man3/SDLKey.3.gz]
            && ![catch {lindex [registry_active libsdl] 0} installed]} {
        set libsdl_vers [lindex $installed 1]
        if {[vercmp $libsdl_vers < 1.2.15-20220801]} {
            registry_deactivate_composite libsdl "" [list ports_nodepcheck 1]
        }
    }
}

livecheck.type  none
