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

PortSystem 1.0
PortGroup xcodeversion 1.0

name            libsdl
set my_name     SDL
version         1.2.15
revision        3
categories      devel multimedia
platforms       macosx freebsd
license         LGPL-2.1+
maintainers     jmr 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, Mac OS, Solaris, IRIX, and FreeBSD.

homepage        http://www.libsdl.org/
master_sites    ${homepage}release/
distname        ${my_name}-${version}

checksums       rmd160 d4802a090cb4a24eeb0c8ce5690802f596d394c3 \
                sha256 d6d316a793e5e348155f0dd93b979798933fb98aa1edebcc108829d6474aad00

minimum_xcodeversions {8 2.4.1}

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

patchfiles \
    no-CGDirectPaletteRef.patch

platform darwin {
    configure.ldflags-append -framework Carbon

    post-destroot {
        reinplace "/Libs:/s/-lSDLmain/-lSDLmain -Wl,-framework,AppKit/" ${destroot}${prefix}/lib/pkgconfig/sdl.pc
        reinplace "s/SDLmain.a/SDLmain.a -Wl,-framework,AppKit/" ${destroot}${prefix}/bin/sdl-config
        reinplace "s/-lSDLmain/-lSDLmain -Wl,-framework,AppKit/" ${destroot}${prefix}/bin/sdl-config
    }
}

platform darwin 8 powerpc {
    if {![catch {sysctl hw.vectorunit} result] && $result > 0} {
        # Work around buggy header. https://trac.macports.org/ticket/50032
        configure.cflags-append -faltivec
    }
}

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
}
default_variants +x11

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

post-destroot {
    set docdir  ${prefix}/share/doc/${name}
    
    xinstall -d ${destroot}${docdir}/html

    xinstall -m 0644 -W ${worksrcpath} BUGS COPYING CREDITS INSTALL README 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}
    }
}

livecheck.type  regex
livecheck.url   ${homepage}download-1.2.php
livecheck.regex ${my_name}-(\\d+(?:\\.\\d+)*)