# -*- 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: Portfile 53861 2009-07-15 23:24:32Z toby@macports.org $

PortSystem      1.0
PortGroup       muniversal 1.0

name            libsdl
set my_name     SDL
version         1.2.13
revision        6
categories      devel multimedia
platforms       macosx freebsd
maintainers     nox 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       md5 c6660feea2a6834de10bc71b2f8e4d88 \
                sha1 51fcaa3e1d5c01fd813ea08688780f86b19cf539 \
                rmd160 ed8825fc98f4b3759cf9e5cf8357d71c50df9925

depends_lib \
    port:xorg-libXext \
    port:xorg-libXrandr \
    port:xrender

patchfiles      patch-SDL_x11gl_c.h.diff

configure.args  --enable-shared \
                --mandir=${prefix}/share/man

variant no_x11 {
        configure.args-append --without-x
        depends_lib-delete \
            port:xorg-libXext \
            port:xorg-libXrandr \
            port:xrender
}

use_parallel_build  yes

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

pre-extract {
    if {"darwin" == ${os.platform} && 8 == ${os.major}} {
        set minimum_xcodeversion 2.4.1
        set current_xcodeversion [exec defaults read /Developer/Applications/Xcode.app/Contents/Info CFBundleShortVersionString]
        if {[rpm-vercomp ${current_xcodeversion} ${minimum_xcodeversion}] < 0} {
            ui_error "On Mac OS X ${macosx_version}, ${name} ${version} requires Xcode ${minimum_xcodeversion} or later but you have Xcode ${current_xcodeversion}."
            return -code error "incompatible Xcode version"
        }
    }
}

post-configure {
    set sdl_config_h "${worksrcpath}/include/SDL_config.h"

    if {![variant_isset no_x11]} {
        if {[file exists "${prefix}/lib/libX11.6.dylib"]} {
            reinplace "/libX11.6.dylib/s|\".*\"|\"${prefix}/lib/libX11.6.dylib\"|" ${sdl_config_h}
        }

        if {[file exists "${prefix}/lib/libXext.6.dylib"]} {
            reinplace "/libXext.6.dylib/s|\".*\"|\"${prefix}/lib/libXext.6.dylib\"|" ${sdl_config_h}
        }

        if {[file exists "${prefix}/lib/libXrandr.2.dylib"]} {
            reinplace "/libXrandr.2.dylib/s|\".*\"|\"${prefix}/lib/libXrandr.2.dylib\"|" ${sdl_config_h}
        }

        if {[file exists "${prefix}/lib/libXrender.1.dylib"]} {
            reinplace "/libXrender.1.dylib/s|\".*\"|\"${prefix}/lib/libXrender.1.dylib\"|" ${sdl_config_h}
        }
    }
}

post-destroot {
    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}
        eval xinstall -m 0644 [glob ${worksrcpath}/docs/${dir}/*] ${destroot}${docdir}/html/${dir}
    }
}

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